Commit 8958da07 authored by zhaoqin@google.com's avatar zhaoqin@google.com

Revert 276642 "Turn FaviconClient into a Keyed service."

> Turn FaviconClient into a Keyed service.
> 
> This is an intermediary CL.
> The end goal is having the FaviconServiceFactory be able to obtain a FaviconClient to pass it to the FaviconService's constructor.
> 
> BUG=377505
> 
> Review URL: https://codereview.chromium.org/301613004

TBR=jif@chromium.org
BUG=383952

Review URL: https://codereview.chromium.org/334613004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276743 0039d316-1c4b-4281-b951-d872f2087c98
parent f841c4a7
// Copyright 2014 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/favicon/chrome_favicon_client_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
ChromeFaviconClientFactory::ChromeFaviconClientFactory()
: BrowserContextKeyedServiceFactory(
"ChromeFaviconClient",
BrowserContextDependencyManager::GetInstance()) {
}
ChromeFaviconClientFactory::~ChromeFaviconClientFactory() {
}
// static
FaviconClient* ChromeFaviconClientFactory::GetForProfile(Profile* profile) {
if (!profile->IsOffTheRecord()) {
return static_cast<FaviconClient*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// Profile must be OffTheRecord in this case.
return static_cast<FaviconClient*>(GetInstance()->GetServiceForBrowserContext(
profile->GetOriginalProfile(), true));
}
// static
ChromeFaviconClientFactory* ChromeFaviconClientFactory::GetInstance() {
return Singleton<ChromeFaviconClientFactory>::get();
}
KeyedService* ChromeFaviconClientFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
ChromeFaviconClient* client =
new ChromeFaviconClient(Profile::FromBrowserContext(context));
return client;
}
bool ChromeFaviconClientFactory::ServiceIsNULLWhileTesting() const {
return true;
}
// Copyright 2014 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_FAVICON_CHROME_FAVICON_CLIENT_FACTORY_H_
#define CHROME_BROWSER_FAVICON_CHROME_FAVICON_CLIENT_FACTORY_H_
#include "base/memory/singleton.h"
#include "chrome/browser/favicon/chrome_favicon_client.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
// Singleton that owns all ChromeFaviconClients and associates them with
// Profiles.
class ChromeFaviconClientFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns the instance of FaviconClient associated with this profile
// (creating one if none exists).
static FaviconClient* GetForProfile(Profile* profile);
// Returns an instance of the factory singleton.
static ChromeFaviconClientFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<ChromeFaviconClientFactory>;
ChromeFaviconClientFactory();
virtual ~ChromeFaviconClientFactory();
// BrowserContextKeyedServiceFactory:
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const OVERRIDE;
virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
};
#endif // CHROME_BROWSER_FAVICON_CHROME_FAVICON_CLIENT_FACTORY_H_
......@@ -6,7 +6,6 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/favicon/chrome_favicon_client.h"
#include "chrome/browser/favicon/chrome_favicon_client_factory.h"
#include "chrome/browser/favicon/favicon_handler.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
......@@ -43,17 +42,21 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper);
FaviconTabHelper::FaviconTabHelper(WebContents* web_contents)
: content::WebContentsObserver(web_contents),
profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
client_ = ChromeFaviconClientFactory::GetForProfile(profile_);
client_.reset(new ChromeFaviconClient(profile_));
#if defined(OS_ANDROID)
bool download_largest_icon = true;
#else
bool download_largest_icon = false;
#endif
favicon_handler_.reset(new FaviconHandler(
client_, this, FaviconHandler::FAVICON, download_largest_icon));
favicon_handler_.reset(new FaviconHandler(client_.get(),
this,
FaviconHandler::FAVICON,
download_largest_icon));
if (chrome::kEnableTouchIcon)
touch_icon_handler_.reset(new FaviconHandler(
client_, this, FaviconHandler::TOUCH, download_largest_icon));
touch_icon_handler_.reset(new FaviconHandler(client_.get(),
this,
FaviconHandler::TOUCH,
download_largest_icon));
}
FaviconTabHelper::~FaviconTabHelper() {
......
......@@ -107,7 +107,7 @@ class FaviconTabHelper : public content::WebContentsObserver,
Profile* profile_;
FaviconClient* client_;
scoped_ptr<FaviconClient> client_;
std::vector<content::FaviconURL> favicon_urls_;
......
......@@ -23,7 +23,6 @@
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/favicon/chrome_favicon_client_factory.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
......@@ -1992,11 +1991,6 @@ TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) {
}
#if defined(OS_CHROMEOS)
static KeyedService* BuildChromeFaviconClient(
content::BrowserContext* profile) {
return new ChromeFaviconClient(static_cast<Profile*>(profile));
}
// Check the multi profile case where only user related browsers should show
// up.
TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
......@@ -2026,8 +2020,6 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
// users running browser list.
std::string user2 = "user2";
TestingProfile* profile2 = CreateMultiUserProfile(user2);
ChromeFaviconClientFactory::GetInstance()->SetTestingFactory(
profile2, BuildChromeFaviconClient);
scoped_ptr<Browser> browser2(
CreateBrowserAndTabWithProfile(profile2, user2, "http://test2"));
base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) };
......
......@@ -644,8 +644,6 @@
'browser/external_protocol/external_protocol_handler.h',
'browser/favicon/chrome_favicon_client.cc',
'browser/favicon/chrome_favicon_client.h',
'browser/favicon/chrome_favicon_client_factory.cc',
'browser/favicon/chrome_favicon_client_factory.h',
'browser/favicon/favicon_changed_details.cc',
'browser/favicon/favicon_changed_details.h',
'browser/favicon/favicon_handler.cc',
......
......@@ -10,7 +10,6 @@
'dependencies': [
'../ui/gfx/gfx.gyp:gfx_geometry',
'favicon_base',
'keyed_service_core',
],
'sources': [
'favicon/core/browser/favicon_client.h',
......
include_rules = [
"+components/favicon_base",
"+components/keyed_service/core",
"+ui/gfx/geometry",
]
......@@ -5,14 +5,12 @@
#ifndef COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_CLIENT_H_
#define COMPONENTS_FAVICON_CORE_BROWSER_FAVICON_CLIENT_H_
#include "components/keyed_service/core/keyed_service.h"
class FaviconService;
class GURL;
// This class abstracts operations that depend on the embedder's environment,
// e.g. Chrome.
class FaviconClient : public KeyedService {
class FaviconClient {
public:
virtual ~FaviconClient() {};
......
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