Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2968)

Unified Diff: chrome/browser/favicon/fallback_icon_service_factory.cc

Issue 996253002: [Fallback Icons] Refactor FallbackIconService to be a BrowserContext-level singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and reverting small unneeded change. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/favicon/fallback_icon_service_factory.cc
diff --git a/chrome/browser/favicon/fallback_icon_service_factory.cc b/chrome/browser/favicon/fallback_icon_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..48f3e1047ef11c3e899808e4d95fe7cd4e73ebc2
--- /dev/null
+++ b/chrome/browser/favicon/fallback_icon_service_factory.cc
@@ -0,0 +1,59 @@
+// Copyright 2015 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/fallback_icon_service_factory.h"
+
+#include "base/memory/singleton.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/favicon/chrome_fallback_icon_client_factory.h"
+#include "chrome/browser/history/history_service.h"
+#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/favicon_base/fallback_icon_service.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+
+// static
+favicon_base::FallbackIconService* FallbackIconServiceFactory::GetForProfile(
+ Profile* profile, ServiceAccessType sat) {
+ if (!profile->IsOffTheRecord()) {
+ return static_cast<favicon_base::FallbackIconService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, true));
+ } else if (sat == ServiceAccessType::EXPLICIT_ACCESS) {
+ // Profile must be OffTheRecord in this case.
+ return static_cast<favicon_base::FallbackIconService*>(
+ GetInstance()->GetServiceForBrowserContext(
+ profile->GetOriginalProfile(), true));
+ }
+
+ // Profile is OffTheRecord without access.
+ NOTREACHED() << "This profile is OffTheRecord";
+ return NULL;
sdefresne 2015/03/16 09:11:29 nit: s/NULL/nullptr/ everywhere (except in comment
huangs 2015/03/16 22:06:11 Done. Doing this for new code (rather than global
+}
+
+// static
+FallbackIconServiceFactory* FallbackIconServiceFactory::GetInstance() {
+ return Singleton<FallbackIconServiceFactory>::get();
+}
+
+FallbackIconServiceFactory::FallbackIconServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "FallbackIconService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(HistoryServiceFactory::GetInstance());
+ DependsOn(ChromeFallbackIconClientFactory::GetInstance());
+}
+
+FallbackIconServiceFactory::~FallbackIconServiceFactory() {}
+
+KeyedService* FallbackIconServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* profile) const {
+ FallbackIconClient* fallback_icon_client =
+ ChromeFallbackIconClientFactory::GetForProfile(
+ static_cast<Profile*>(profile));
+ return new favicon_base::FallbackIconService(fallback_icon_client);
+}
+
+bool FallbackIconServiceFactory::ServiceIsNULLWhileTesting() const {
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698