| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/offline_pages/prefetch/prefetch_service_factory.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/singleton.h" |
| 9 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
| 10 #include "components/gcm_driver/gcm_driver.h" |
| 11 #include "components/gcm_driver/gcm_profile_service.h" |
| 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 13 #include "components/offline_pages/core/prefetch/prefetch_gcm_app_handler.h" |
| 14 #include "components/offline_pages/core/prefetch/prefetch_service_impl.h" |
| 15 #include "content/public/browser/browser_context.h" |
| 16 |
| 17 namespace offline_pages { |
| 18 |
| 19 PrefetchServiceFactory::PrefetchServiceFactory() |
| 20 : BrowserContextKeyedServiceFactory( |
| 21 "OfflinePagePrefetchService", |
| 22 BrowserContextDependencyManager::GetInstance()) { |
| 23 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); |
| 24 } |
| 25 |
| 26 // static |
| 27 PrefetchServiceFactory* PrefetchServiceFactory::GetInstance() { |
| 28 return base::Singleton<PrefetchServiceFactory>::get(); |
| 29 } |
| 30 |
| 31 // static |
| 32 PrefetchService* PrefetchServiceFactory::GetForBrowserContext( |
| 33 content::BrowserContext* context) { |
| 34 return static_cast<PrefetchService*>( |
| 35 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 36 } |
| 37 |
| 38 KeyedService* PrefetchServiceFactory::BuildServiceInstanceFor( |
| 39 content::BrowserContext* context) const { |
| 40 PrefetchGCMAppHandler* app_handler = new PrefetchGCMAppHandler(); |
| 41 auto service = |
| 42 base::MakeUnique<PrefetchServiceImpl>(base::WrapUnique(app_handler)); |
| 43 |
| 44 gcm::GCMProfileServiceFactory::GetForProfile(context) |
| 45 ->driver() |
| 46 ->AddAppHandler(app_handler->app_id(), app_handler); |
| 47 return service.release(); |
| 48 } |
| 49 |
| 50 bool PrefetchServiceFactory::ServiceIsCreatedWithBrowserContext() const { |
| 51 // PrefetchService is designed to be very lightweight to create, this way it |
| 52 // can manage the lifetime of long-lived objects such as the GCMAppHandler and |
| 53 // the daily-usage stats collector without burdening Chrome too much at |
| 54 // startup time. |
| 55 return true; |
| 56 } |
| 57 |
| 58 } // namespace offline_pages |
| OLD | NEW |