Commit aa4ad85b authored by Chris Pickel's avatar Chris Pickel Committed by Commit Bot

Split LogoService{,Factory}

The factory will remain in the Android tree (it has to, to test against
the ChromeHome feature), while the service itself will move to a place
where it can be shared with Desktop.

I'm not expecting this code to be shared with iOS, which has its own
logo service for some extra caching behavior, so the Profile deps can
stay.

BUG=583290

Change-Id: I5f2840277a787f51cf4523b89bc23a6a0d8dae34
Reviewed-on: https://chromium-review.googlesource.com/597947
Commit-Queue: Chris Pickel <sfiera@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491481}
parent 91f7231b
......@@ -2825,6 +2825,8 @@ split_static_library("browser") {
"android/logo_bridge.h",
"android/logo_service.cc",
"android/logo_service.h",
"android/logo_service_factory.cc",
"android/logo_service_factory.h",
"android/metrics/launch_metrics.cc",
"android/metrics/uma_session_stats.cc",
"android/metrics/uma_session_stats.h",
......
......@@ -12,6 +12,7 @@
#include "base/android/jni_string.h"
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/android/logo_service.h"
#include "chrome/browser/android/logo_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "components/search_provider_logos/logo_tracker.h"
......
......@@ -8,7 +8,6 @@
#include "base/feature_list.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/image_decoder.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
......@@ -18,11 +17,10 @@
#include "components/search_engines/template_url_service.h"
#include "components/search_provider_logos/fixed_logo_api.h"
#include "components/search_provider_logos/google_logo_api.h"
#include "components/search_provider_logos/logo_tracker.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request_context_getter.h"
using content::BrowserThread;
using search_provider_logos::Logo;
using search_provider_logos::LogoDelegate;
using search_provider_logos::LogoTracker;
......@@ -88,13 +86,10 @@ class ChromeLogoDelegate : public search_provider_logos::LogoDelegate {
} // namespace
// LogoService ----------------------------------------------------------------
LogoService::LogoService(Profile* profile, bool use_gray_background)
: profile_(profile), use_gray_background_(use_gray_background) {}
LogoService::LogoService(Profile* profile) : profile_(profile) {
}
LogoService::~LogoService() {
}
LogoService::~LogoService() = default;
void LogoService::GetLogo(search_provider_logos::LogoObserver* observer) {
TemplateURLService* template_url_service =
......@@ -137,44 +132,13 @@ void LogoService::GetLogo(search_provider_logos::LogoObserver* observer) {
GURL google_base_url =
GURL(UIThreadSearchTermsData(profile_).GoogleBaseURLValue());
bool use_gray_background =
!base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature);
logo_tracker_->SetServerAPI(
search_provider_logos::GetGoogleDoodleURL(google_base_url),
search_provider_logos::GetGoogleParseLogoResponseCallback(
google_base_url),
search_provider_logos::GetGoogleAppendQueryparamsCallback(
use_gray_background));
use_gray_background_));
}
logo_tracker_->GetLogo(observer);
}
// LogoServiceFactory ---------------------------------------------------------
// static
LogoService* LogoServiceFactory::GetForProfile(Profile* profile) {
return static_cast<LogoService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
LogoServiceFactory* LogoServiceFactory::GetInstance() {
return base::Singleton<LogoServiceFactory>::get();
}
LogoServiceFactory::LogoServiceFactory()
: BrowserContextKeyedServiceFactory(
"LogoService",
BrowserContextDependencyManager::GetInstance()) {
}
LogoServiceFactory::~LogoServiceFactory() {}
KeyedService* LogoServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
DCHECK(!profile->IsOffTheRecord());
return new LogoService(profile);
}
......@@ -5,14 +5,18 @@
#ifndef CHROME_BROWSER_ANDROID_LOGO_SERVICE_H_
#define CHROME_BROWSER_ANDROID_LOGO_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/search_provider_logos/logo_tracker.h"
class Profile;
namespace search_provider_logos {
class LogoTracker;
class LogoObserver;
} // namespace search_provider_logos
// Provides the logo for a profile's default search provider.
//
// Example usage:
......@@ -21,7 +25,7 @@ class Profile;
//
class LogoService : public KeyedService {
public:
explicit LogoService(Profile* profile);
LogoService(Profile* profile, bool use_gray_background);
~LogoService() override;
// Gets the logo for the default search provider and notifies |observer|
......@@ -30,27 +34,10 @@ class LogoService : public KeyedService {
private:
Profile* profile_;
const bool use_gray_background_;
std::unique_ptr<search_provider_logos::LogoTracker> logo_tracker_;
DISALLOW_COPY_AND_ASSIGN(LogoService);
};
// Singleton that owns all LogoServices and associates them with Profiles.
class LogoServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static LogoService* GetForProfile(Profile* profile);
static LogoServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<LogoServiceFactory>;
LogoServiceFactory();
~LogoServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};
#endif // CHROME_BROWSER_ANDROID_LOGO_SERVICE_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/logo_service_factory.h"
#include "base/feature_list.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/logo_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
LogoService* LogoServiceFactory::GetForProfile(Profile* profile) {
return static_cast<LogoService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
LogoServiceFactory* LogoServiceFactory::GetInstance() {
return base::Singleton<LogoServiceFactory>::get();
}
LogoServiceFactory::LogoServiceFactory()
: BrowserContextKeyedServiceFactory(
"LogoService",
BrowserContextDependencyManager::GetInstance()) {}
LogoServiceFactory::~LogoServiceFactory() = default;
KeyedService* LogoServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
DCHECK(!profile->IsOffTheRecord());
bool use_gray_background =
!base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature);
return new LogoService(profile, use_gray_background);
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_LOGO_SERVICE_FACTORY_H_
#define CHROME_BROWSER_ANDROID_LOGO_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class LogoService;
class Profile;
// Singleton that owns all LogoServices and associates them with Profiles.
class LogoServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static LogoService* GetForProfile(Profile* profile);
static LogoServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<LogoServiceFactory>;
LogoServiceFactory();
~LogoServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(LogoServiceFactory);
};
#endif // CHROME_BROWSER_ANDROID_LOGO_SERVICE_FACTORY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment