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

Side by Side Diff: chrome/browser/offline_pages/prefetch/prefetch_service_factory.cc

Issue 2864293003: [Offline Pages] Add a GCMAppHandler for offline page prefetch. (Closed)
Patch Set: Refactor to remove GCM dependency. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/offline_pages/content/prefetch_service_factory.h" 5 #include "chrome/browser/offline_pages/prefetch/prefetch_service_factory.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "chrome/browser/gcm/gcm_profile_service_factory.h"
10 #include "chrome/browser/offline_pages/prefetch/prefetch_gcm_app_handler.h"
11 #include "components/gcm_driver/gcm_driver.h"
12 #include "components/gcm_driver/gcm_profile_service.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" 13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/offline_pages/core/offline_page_feature.h"
9 #include "components/offline_pages/core/prefetch/prefetch_service_impl.h" 15 #include "components/offline_pages/core/prefetch/prefetch_service_impl.h"
10 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
11 17
12 namespace offline_pages { 18 namespace offline_pages {
13 19
14 PrefetchServiceFactory::PrefetchServiceFactory() 20 PrefetchServiceFactory::PrefetchServiceFactory()
15 : BrowserContextKeyedServiceFactory( 21 : BrowserContextKeyedServiceFactory(
16 "OfflinePagePrefetchService", 22 "OfflinePagePrefetchService",
17 BrowserContextDependencyManager::GetInstance()) {} 23 BrowserContextDependencyManager::GetInstance()) {
24 DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
25 }
18 26
19 // static 27 // static
20 PrefetchServiceFactory* PrefetchServiceFactory::GetInstance() { 28 PrefetchServiceFactory* PrefetchServiceFactory::GetInstance() {
21 return base::Singleton<PrefetchServiceFactory>::get(); 29 return base::Singleton<PrefetchServiceFactory>::get();
22 } 30 }
23 31
24 // static 32 // static
25 PrefetchService* PrefetchServiceFactory::GetForBrowserContext( 33 PrefetchService* PrefetchServiceFactory::GetForBrowserContext(
26 content::BrowserContext* context) { 34 content::BrowserContext* context) {
27 return static_cast<PrefetchService*>( 35 return static_cast<PrefetchService*>(
28 GetInstance()->GetServiceForBrowserContext(context, true)); 36 GetInstance()->GetServiceForBrowserContext(context, true));
29 } 37 }
30 38
31 KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor( 39 KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor(
32 content::BrowserContext* context) const { 40 content::BrowserContext* context) const {
33 return new PrefetchServiceImpl(); 41 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.
42 return nullptr;
43
44 PrefetchGCMAppHandler* app_handler = new PrefetchGCMAppHandler();
45 auto service =
46 base::MakeUnique<PrefetchServiceImpl>(base::WrapUnique(app_handler));
47 gcm::GCMProfileServiceFactory::GetForProfile(context)
48 ->driver()
49 ->AddAppHandler(app_handler->app_id(), app_handler);
50 return service.release();
51 }
52
53 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.
54 return true;
34 } 55 }
35 56
36 } // namespace offline_pages 57 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698