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

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

Issue 1922083004: Allow fetching personalized snippets from ChromeReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet another unittest fix Created 4 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/resources/snippets_internals.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/suggestions/image_fetcher_impl.h" 11 #include "chrome/browser/search/suggestions/image_fetcher_impl.h"
12 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 12 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/common/channel_info.h" 15 #include "chrome/common/channel_info.h"
14 #include "components/image_fetcher/image_fetcher.h" 16 #include "components/image_fetcher/image_fetcher.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h" 17 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 18 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
17 #include "components/ntp_snippets/ntp_snippets_scheduler.h" 19 #include "components/ntp_snippets/ntp_snippets_scheduler.h"
18 #include "components/ntp_snippets/ntp_snippets_service.h" 20 #include "components/ntp_snippets/ntp_snippets_service.h"
19 #include "components/safe_json/safe_json_parser.h" 21 #include "components/safe_json/safe_json_parser.h"
22 #include "components/signin/core/browser/profile_oauth2_token_service.h"
23 #include "components/signin/core/browser/signin_manager.h"
20 #include "components/version_info/version_info.h" 24 #include "components/version_info/version_info.h"
21 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
24 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
25 29
26 #if defined(OS_ANDROID) 30 #if defined(OS_ANDROID)
27 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" 31 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h"
28 #endif // OS_ANDROID 32 #endif // OS_ANDROID
29 33
(...skipping 12 matching lines...) Expand all
42 Profile* profile) { 46 Profile* profile) {
43 DCHECK(!profile->IsOffTheRecord()); 47 DCHECK(!profile->IsOffTheRecord());
44 return static_cast<ntp_snippets::NTPSnippetsService*>( 48 return static_cast<ntp_snippets::NTPSnippetsService*>(
45 GetInstance()->GetServiceForBrowserContext(profile, true)); 49 GetInstance()->GetServiceForBrowserContext(profile, true));
46 } 50 }
47 51
48 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory() 52 NTPSnippetsServiceFactory::NTPSnippetsServiceFactory()
49 : BrowserContextKeyedServiceFactory( 53 : BrowserContextKeyedServiceFactory(
50 "NTPSnippetsService", 54 "NTPSnippetsService",
51 BrowserContextDependencyManager::GetInstance()) { 55 BrowserContextDependencyManager::GetInstance()) {
56 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
57 DependsOn(SigninManagerFactory::GetInstance());
52 DependsOn(SuggestionsServiceFactory::GetInstance()); 58 DependsOn(SuggestionsServiceFactory::GetInstance());
53 } 59 }
54 60
55 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} 61 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {}
56 62
57 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( 63 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor(
58 content::BrowserContext* context) const { 64 content::BrowserContext* context) const {
59 Profile* profile = Profile::FromBrowserContext(context); 65 Profile* profile = Profile::FromBrowserContext(context);
66 SigninManagerBase* signin_manager =
67 SigninManagerFactory::GetForProfile(profile);
68 OAuth2TokenService* token_service =
69 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
60 scoped_refptr<net::URLRequestContextGetter> request_context = 70 scoped_refptr<net::URLRequestContextGetter> request_context =
61 content::BrowserContext::GetDefaultStoragePartition(context)-> 71 content::BrowserContext::GetDefaultStoragePartition(context)->
62 GetURLRequestContext(); 72 GetURLRequestContext();
63 SuggestionsService* suggestions_service = 73 SuggestionsService* suggestions_service =
64 SuggestionsServiceFactory::GetForProfile(profile); 74 SuggestionsServiceFactory::GetForProfile(profile);
65 75
66 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; 76 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr;
67 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
68 scheduler = NTPSnippetsLauncher::Get(); 78 scheduler = NTPSnippetsLauncher::Get();
69 #endif // OS_ANDROID 79 #endif // OS_ANDROID
70 80
71 scoped_refptr<base::SequencedTaskRunner> task_runner = 81 scoped_refptr<base::SequencedTaskRunner> task_runner =
72 BrowserThread::GetBlockingPool() 82 BrowserThread::GetBlockingPool()
73 ->GetSequencedTaskRunnerWithShutdownBehavior( 83 ->GetSequencedTaskRunnerWithShutdownBehavior(
74 base::SequencedWorkerPool::GetSequenceToken(), 84 base::SequencedWorkerPool::GetSequenceToken(),
75 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); 85 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
76 86
77 return new ntp_snippets::NTPSnippetsService( 87 return new ntp_snippets::NTPSnippetsService(
78 profile->GetPrefs(), suggestions_service, task_runner, 88 profile->GetPrefs(), suggestions_service, task_runner,
79 g_browser_process->GetApplicationLocale(), scheduler, 89 g_browser_process->GetApplicationLocale(), scheduler,
80 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher( 90 base::WrapUnique(new ntp_snippets::NTPSnippetsFetcher(
81 request_context, base::Bind(&safe_json::SafeJsonParser::Parse), 91 signin_manager, token_service, request_context,
92 base::Bind(&safe_json::SafeJsonParser::Parse),
82 chrome::GetChannel() == version_info::Channel::STABLE)), 93 chrome::GetChannel() == version_info::Channel::STABLE)),
83 base::WrapUnique(new ImageFetcherImpl(request_context.get()))); 94 base::WrapUnique(new ImageFetcherImpl(request_context.get())));
84 } 95 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/snippets_internals.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698