-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[journeys] Make
EntityImageService
chrome-free for componentization
This CL prepares `EntityImageService` for componentization by making it no longer directly depend on /chrome code. Followup CL will rename it to `ImageService` and move the implementation into /components. Larger plan is to hook it up into `QueryClustersState` and make it suitable for carrying URL-keyed image requests too. Bug: b/244507194, 1367485, b/248367751 Change-Id: Iee1db7b4fb865a7952e59ae6b0f5a262b76b7646 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4045243 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tommy Li <tommycli@chromium.org> Reviewed-by: Sophie Chang <sophiechang@chromium.org> Cr-Commit-Position: refs/heads/main@{#1076447}
- Loading branch information
Tommy C. Li
authored and
Chromium LUCI CQ
committed
Nov 28, 2022
1 parent
245b874
commit bbd6d79
Showing
8 changed files
with
129 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sophiechang@chromium.org | ||
tommycli@chromium.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# //chrome/browser/image_service | ||
|
||
Service implementation for Chrome Images feature, to provide relevant images | ||
for Chrome UI usage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/image_service/image_service_factory.h" | ||
|
||
#include "base/no_destructor.h" | ||
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | ||
#include "chrome/browser/history_clusters/entity_image_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/sync/sync_service_factory.h" | ||
|
||
namespace image_service { | ||
|
||
// static | ||
history_clusters::EntityImageService* ImageServiceFactory::GetForBrowserContext( | ||
content::BrowserContext* browser_context) { | ||
return static_cast<history_clusters::EntityImageService*>( | ||
GetInstance().GetServiceForBrowserContext(browser_context, true)); | ||
} | ||
|
||
// static | ||
ImageServiceFactory& ImageServiceFactory::GetInstance() { | ||
static base::NoDestructor<ImageServiceFactory> instance; | ||
return *instance; | ||
} | ||
|
||
ImageServiceFactory::ImageServiceFactory() | ||
: ProfileKeyedServiceFactory("ImageService") { | ||
DependsOn(SyncServiceFactory::GetInstance()); | ||
} | ||
|
||
ImageServiceFactory::~ImageServiceFactory() = default; | ||
|
||
KeyedService* ImageServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
auto* profile = Profile::FromBrowserContext(context); | ||
// TODO(tommycli): Move EntityImageService to the image_service component. | ||
return new history_clusters::EntityImageService( | ||
std::make_unique<ChromeAutocompleteProviderClient>(profile), | ||
SyncServiceFactory::GetForProfile(profile)); | ||
} | ||
|
||
} // namespace image_service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_IMAGE_SERVICE_IMAGE_SERVICE_FACTORY_H_ | ||
#define CHROME_BROWSER_IMAGE_SERVICE_IMAGE_SERVICE_FACTORY_H_ | ||
|
||
#include "base/no_destructor.h" | ||
#include "chrome/browser/profiles/profile_keyed_service_factory.h" | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
namespace history_clusters { | ||
class EntityImageService; | ||
} | ||
|
||
namespace image_service { | ||
|
||
// Factory for BrowserContext keyed ImageService, which provides images for | ||
// Journeys related features. | ||
class ImageServiceFactory : public ProfileKeyedServiceFactory { | ||
public: | ||
// This can return nullptr in tests. | ||
static history_clusters::EntityImageService* GetForBrowserContext( | ||
content::BrowserContext* browser_context); | ||
|
||
private: | ||
friend base::NoDestructor<ImageServiceFactory>; | ||
static ImageServiceFactory& GetInstance(); | ||
|
||
ImageServiceFactory(); | ||
~ImageServiceFactory() override; | ||
|
||
// BrowserContextKeyedServiceFactory: | ||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
} // namespace image_service | ||
|
||
#endif // CHROME_BROWSER_IMAGE_SERVICE_IMAGE_SERVICE_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters