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

Unified Diff: chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc

Issue 2864293003: [Offline Pages] Add a GCMAppHandler for offline page prefetch. (Closed)
Patch Set: Move Content Suggestions Observer to //components/offline_pages/core and modify lifetime management Created 3 years, 7 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/offline_pages/prefetch/prefetch_service_factory.cc
diff --git a/chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc b/chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..82b8e5d201a7ca25c3718901ec6aa39881392c90
--- /dev/null
+++ b/chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc
@@ -0,0 +1,58 @@
+// 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/offline_pages/prefetch/prefetch_service_factory.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/gcm/gcm_profile_service_factory.h"
+#include "components/gcm_driver/gcm_driver.h"
+#include "components/gcm_driver/gcm_profile_service.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "components/offline_pages/core/prefetch/prefetch_gcm_app_handler.h"
+#include "components/offline_pages/core/prefetch/prefetch_service_impl.h"
+#include "content/public/browser/browser_context.h"
+
+namespace offline_pages {
+
+PrefetchServiceFactory::PrefetchServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "OfflinePagePrefetchService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
+}
+
+// static
+PrefetchServiceFactory* PrefetchServiceFactory::GetInstance() {
+ return base::Singleton<PrefetchServiceFactory>::get();
+}
+
+// static
+PrefetchService* PrefetchServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<PrefetchService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ PrefetchGCMAppHandler* app_handler = new PrefetchGCMAppHandler();
+ auto service =
+ base::MakeUnique<PrefetchServiceImpl>(base::WrapUnique(app_handler));
+
+ gcm::GCMProfileServiceFactory::GetForProfile(context)
+ ->driver()
+ ->AddAppHandler(app_handler->app_id(), app_handler);
+ return service.release();
+}
+
+bool PrefetchServiceFactory::ServiceIsCreatedWithBrowserContext() const {
+ // PrefetchService is designed to be very lightweight to create, this way it
+ // can manage the lifetime of long-lived objects such as the GCMAppHandler and
+ // the daily-usage stats collector without burdening Chrome too much at
+ // startup time.
+ return true;
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698