Index: chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc |
diff --git a/components/offline_pages/content/prefetch_service_factory.cc b/chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc |
similarity index 51% |
rename from components/offline_pages/content/prefetch_service_factory.cc |
rename to chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc |
index ffe46b2630825585089479fcd31dfa4165481b54..0eac3cc0498e031cd46246d8611e02c1d6b9c10e 100644 |
--- a/components/offline_pages/content/prefetch_service_factory.cc |
+++ b/chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc |
@@ -2,10 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/offline_pages/content/prefetch_service_factory.h" |
+#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 "chrome/browser/offline_pages/prefetch/prefetch_gcm_app_handler.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/offline_page_feature.h" |
#include "components/offline_pages/core/prefetch/prefetch_service_impl.h" |
#include "content/public/browser/browser_context.h" |
@@ -14,7 +20,9 @@ namespace offline_pages { |
PrefetchServiceFactory::PrefetchServiceFactory() |
: BrowserContextKeyedServiceFactory( |
"OfflinePagePrefetchService", |
- BrowserContextDependencyManager::GetInstance()) {} |
+ BrowserContextDependencyManager::GetInstance()) { |
+ DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); |
+} |
// static |
PrefetchServiceFactory* PrefetchServiceFactory::GetInstance() { |
@@ -30,7 +38,20 @@ PrefetchService* PrefetchServiceFactory::GetForBrowserContext( |
KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor( |
content::BrowserContext* context) const { |
- return new PrefetchServiceImpl(); |
+ if (!offline_pages::IsPrefetchingOfflinePagesEnabled()) |
Dmitry Titov
2017/05/16 19:33:23
It feels this check belongs to delayed initializat
dewittj
2017/05/16 22:58:22
Done.
|
+ return nullptr; |
+ |
+ 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 { |
Dmitry Titov
2017/05/16 19:33:23
Could you add a comment as to lightweight creation
dewittj
2017/05/16 22:58:22
Done.
|
+ return true; |
} |
} // namespace offline_pages |