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

Side by Side Diff: chrome/browser/ntp_snippets/ntp_snippets_service_factory.cc

Issue 2191343002: 📰 Remove SnippetService's dependency on Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update some doc, show NO_SNIPPETS instead of SIGNIN when during INITIALIZING state Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" 5 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" 12 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 14 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
15 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 15 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/common/channel_info.h" 18 #include "chrome/common/channel_info.h"
20 #include "components/browser_sync/browser/profile_sync_service.h"
21 #include "components/image_fetcher/image_decoder.h" 19 #include "components/image_fetcher/image_decoder.h"
22 #include "components/image_fetcher/image_fetcher.h" 20 #include "components/image_fetcher/image_fetcher.h"
23 #include "components/image_fetcher/image_fetcher_impl.h" 21 #include "components/image_fetcher/image_fetcher_impl.h"
24 #include "components/keyed_service/content/browser_context_dependency_manager.h" 22 #include "components/keyed_service/content/browser_context_dependency_manager.h"
25 #include "components/ntp_snippets/content_suggestions_service.h" 23 #include "components/ntp_snippets/content_suggestions_service.h"
26 #include "components/ntp_snippets/ntp_snippets_constants.h" 24 #include "components/ntp_snippets/ntp_snippets_constants.h"
27 #include "components/ntp_snippets/ntp_snippets_database.h" 25 #include "components/ntp_snippets/ntp_snippets_database.h"
28 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 26 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
29 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 27 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
30 #include "components/ntp_snippets/ntp_snippets_service.h" 28 #include "components/ntp_snippets/ntp_snippets_service.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DCHECK(!profile->IsOffTheRecord()); 60 DCHECK(!profile->IsOffTheRecord());
63 return static_cast<ntp_snippets::NTPSnippetsService*>( 61 return static_cast<ntp_snippets::NTPSnippetsService*>(
64 GetInstance()->GetServiceForBrowserContext(profile, true)); 62 GetInstance()->GetServiceForBrowserContext(profile, true));
65 } 63 }
66 64
67 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() 65 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory()
68 : BrowserContextKeyedServiceFactory( 66 : BrowserContextKeyedServiceFactory(
69 "NTPSnippetsService", 67 "NTPSnippetsService",
70 BrowserContextDependencyManager::GetInstance()) { 68 BrowserContextDependencyManager::GetInstance()) {
71 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 69 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
72 DependsOn(ProfileSyncServiceFactory::GetInstance());
73 DependsOn(SigninManagerFactory::GetInstance()); 70 DependsOn(SigninManagerFactory::GetInstance());
74 DependsOn(SuggestionsServiceFactory::GetInstance()); 71 DependsOn(SuggestionsServiceFactory::GetInstance());
75 DependsOn(ContentSuggestionsServiceFactory::GetInstance()); 72 DependsOn(ContentSuggestionsServiceFactory::GetInstance());
76 } 73 }
77 74
78 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} 75 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {}
79 76
80 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( 77 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor(
81 content::BrowserContext* context) const { 78 content::BrowserContext* context) const {
82 Profile* profile = Profile::FromBrowserContext(context); 79 Profile* profile = Profile::FromBrowserContext(context);
(...skipping 10 matching lines...) Expand all
93 enabled = base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature); 90 enabled = base::FeatureList::IsEnabled(chrome::android::kNTPSnippetsFeature);
94 #endif // OS_ANDROID 91 #endif // OS_ANDROID
95 92
96 SigninManagerBase* signin_manager = 93 SigninManagerBase* signin_manager =
97 SigninManagerFactory::GetForProfile(profile); 94 SigninManagerFactory::GetForProfile(profile);
98 OAuth2TokenService* token_service = 95 OAuth2TokenService* token_service =
99 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 96 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
100 scoped_refptr<net::URLRequestContextGetter> request_context = 97 scoped_refptr<net::URLRequestContextGetter> request_context =
101 content::BrowserContext::GetDefaultStoragePartition(context)-> 98 content::BrowserContext::GetDefaultStoragePartition(context)->
102 GetURLRequestContext(); 99 GetURLRequestContext();
103 ProfileSyncService* sync_service =
104 ProfileSyncServiceFactory::GetForProfile(profile);
105 SuggestionsService* suggestions_service = 100 SuggestionsService* suggestions_service =
106 SuggestionsServiceFactory::GetForProfile(profile); 101 SuggestionsServiceFactory::GetForProfile(profile);
107 102
108 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; 103 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr;
109 #if defined(OS_ANDROID) 104 #if defined(OS_ANDROID)
110 scheduler = NTPSnippetsLauncher::Get(); 105 scheduler = NTPSnippetsLauncher::Get();
111 #endif // OS_ANDROID 106 #endif // OS_ANDROID
112 107
113 base::FilePath database_dir( 108 base::FilePath database_dir(
114 profile->GetPath().Append(ntp_snippets::kDatabaseFolder)); 109 profile->GetPath().Append(ntp_snippets::kDatabaseFolder));
(...skipping 11 matching lines...) Expand all
126 signin_manager, token_service, request_context, 121 signin_manager, token_service, request_context,
127 profile->GetPrefs(), 122 profile->GetPrefs(),
128 base::Bind(&safe_json::SafeJsonParser::Parse), 123 base::Bind(&safe_json::SafeJsonParser::Parse),
129 chrome::GetChannel() == version_info::Channel::STABLE), 124 chrome::GetChannel() == version_info::Channel::STABLE),
130 base::MakeUnique<ImageFetcherImpl>( 125 base::MakeUnique<ImageFetcherImpl>(
131 base::MakeUnique<ImageDecoderImpl>(), request_context.get()), 126 base::MakeUnique<ImageDecoderImpl>(), request_context.get()),
132 base::MakeUnique<ImageDecoderImpl>(), 127 base::MakeUnique<ImageDecoderImpl>(),
133 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir, 128 base::MakeUnique<ntp_snippets::NTPSnippetsDatabase>(database_dir,
134 task_runner), 129 task_runner),
135 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>( 130 base::MakeUnique<ntp_snippets::NTPSnippetsStatusService>(
136 signin_manager, sync_service, profile->GetPrefs())); 131 signin_manager, profile->GetPrefs()));
137 132
138 if (content_suggestions_service->state() == 133 if (content_suggestions_service->state() ==
139 ContentSuggestionsService::State::ENABLED) { 134 ContentSuggestionsService::State::ENABLED) {
140 content_suggestions_service->RegisterProvider(ntp_snippets_service); 135 content_suggestions_service->RegisterProvider(ntp_snippets_service);
141 } 136 }
142 return ntp_snippets_service; 137 return ntp_snippets_service;
143 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698