OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/android/ntp/offline_page_suggestions_provider_factory.h " | |
6 | |
7 #include "base/feature_list.h" | |
8 #include "base/memory/singleton.h" | |
9 #include "chrome/browser/android/chrome_feature_list.h" | |
10 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | |
11 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/pref_names.h" | |
14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | |
15 #include "components/ntp_snippets/content_suggestions_service.h" | |
16 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide r.h" | |
17 #include "components/offline_pages/offline_page_model.h" | |
18 #include "components/prefs/pref_service.h" | |
19 #include "content/public/browser/browser_context.h" | |
20 | |
21 using ntp_snippets::ContentSuggestionsService; | |
22 using ntp_snippets::OfflinePageSuggestionsProvider; | |
23 using offline_pages::OfflinePageModel; | |
24 using offline_pages::OfflinePageModelFactory; | |
25 | |
26 // static | |
27 OfflinePageSuggestionsProviderFactory* | |
28 OfflinePageSuggestionsProviderFactory::GetInstance() { | |
29 return base::Singleton<OfflinePageSuggestionsProviderFactory>::get(); | |
30 } | |
31 | |
32 // static | |
33 ntp_snippets::OfflinePageSuggestionsProvider* | |
34 OfflinePageSuggestionsProviderFactory::GetForProfile(Profile* profile) { | |
35 DCHECK(!profile->IsOffTheRecord()); | |
36 return static_cast<ntp_snippets::OfflinePageSuggestionsProvider*>( | |
37 GetInstance()->GetServiceForBrowserContext(profile, true)); | |
38 } | |
39 | |
40 OfflinePageSuggestionsProviderFactory::OfflinePageSuggestionsProviderFactory() | |
41 : BrowserContextKeyedServiceFactory( | |
42 "OfflinePageSuggestionsProvider", | |
43 BrowserContextDependencyManager::GetInstance()) { | |
44 DependsOn(ContentSuggestionsServiceFactory::GetInstance()); | |
45 DependsOn(OfflinePageModelFactory::GetInstance()); | |
46 } | |
47 | |
48 OfflinePageSuggestionsProviderFactory:: | |
49 ~OfflinePageSuggestionsProviderFactory() {} | |
50 | |
51 KeyedService* OfflinePageSuggestionsProviderFactory::BuildServiceInstanceFor( | |
52 content::BrowserContext* context) const { | |
53 Profile* profile = Profile::FromBrowserContext(context); | |
54 | |
55 ContentSuggestionsService* content_suggestions_service = | |
56 ContentSuggestionsServiceFactory::GetForProfile(profile); | |
57 if (content_suggestions_service->state() == | |
58 ContentSuggestionsService::State::DISABLED) { | |
59 return nullptr; | |
60 } | |
61 | |
62 OfflinePageModel* offline_page_model = nullptr; | |
Marc Treib
2016/07/14 14:17:24
This can move down to where it's assigned.
Philipp Keck
2016/07/14 15:30:06
Done.
| |
63 if (!base::FeatureList::IsEnabled( | |
64 chrome::android::kNTPOfflinePageSuggestionsFeature)) { | |
65 return nullptr; | |
66 } | |
67 | |
68 offline_page_model = OfflinePageModelFactory::GetForBrowserContext(profile); | |
69 | |
70 OfflinePageSuggestionsProvider* offline_page_suggestions_provider = | |
71 new OfflinePageSuggestionsProvider(offline_page_model); | |
72 content_suggestions_service->RegisterProvider( | |
73 offline_page_suggestions_provider); | |
74 return offline_page_suggestions_provider; | |
75 } | |
OLD | NEW |