1 // Copyright (c) 2012 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/download/download_core_service_factory.h"
6 
7 #include "chrome/browser/download/download_core_service_impl.h"
8 #include "chrome/browser/history/history_service_factory.h"
9 #include "chrome/browser/notifications/notification_display_service_factory.h"
10 #include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
11 #include "chrome/browser/profiles/incognito_helpers.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 
15 // static
GetForBrowserContext(content::BrowserContext * context)16 DownloadCoreService* DownloadCoreServiceFactory::GetForBrowserContext(
17     content::BrowserContext* context) {
18   return static_cast<DownloadCoreService*>(
19       GetInstance()->GetServiceForBrowserContext(context, true));
20 }
21 
22 // static
GetInstance()23 DownloadCoreServiceFactory* DownloadCoreServiceFactory::GetInstance() {
24   return base::Singleton<DownloadCoreServiceFactory>::get();
25 }
26 
DownloadCoreServiceFactory()27 DownloadCoreServiceFactory::DownloadCoreServiceFactory()
28     : BrowserContextKeyedServiceFactory(
29           "DownloadCoreService",
30           BrowserContextDependencyManager::GetInstance()) {
31   DependsOn(HistoryServiceFactory::GetInstance());
32   DependsOn(NotificationDisplayServiceFactory::GetInstance());
33   DependsOn(OfflineContentAggregatorFactory::GetInstance());
34 }
35 
~DownloadCoreServiceFactory()36 DownloadCoreServiceFactory::~DownloadCoreServiceFactory() {}
37 
BuildServiceInstanceFor(content::BrowserContext * profile) const38 KeyedService* DownloadCoreServiceFactory::BuildServiceInstanceFor(
39     content::BrowserContext* profile) const {
40   DownloadCoreService* service =
41       new DownloadCoreServiceImpl(static_cast<Profile*>(profile));
42 
43   // No need for initialization; initialization can be done on first
44   // use of service.
45 
46   return service;
47 }
48 
GetBrowserContextToUse(content::BrowserContext * context) const49 content::BrowserContext* DownloadCoreServiceFactory::GetBrowserContextToUse(
50     content::BrowserContext* context) const {
51   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
52 }
53