| 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 if (!base::FeatureList::IsEnabled( | |
| 63 chrome::android::kNTPOfflinePageSuggestionsFeature)) { | |
| 64 return nullptr; | |
| 65 } | |
| 66 | |
| 67 OfflinePageModel* offline_page_model = | |
| 68 OfflinePageModelFactory::GetForBrowserContext(profile); | |
| 69 | |
| 70 OfflinePageSuggestionsProvider* offline_page_suggestions_provider = | |
| 71 new OfflinePageSuggestionsProvider( | |
| 72 content_suggestions_service->category_factory(), offline_page_model); | |
| 73 content_suggestions_service->RegisterProvider( | |
| 74 offline_page_suggestions_provider); | |
| 75 return offline_page_suggestions_provider; | |
| 76 } | |
| OLD | NEW |