OLD | NEW |
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/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" | 10 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
11 #include "chrome/common/channel_info.h" | 11 #include "chrome/common/channel_info.h" |
12 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
13 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 13 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
14 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 14 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
15 #include "components/ntp_snippets/ntp_snippets_service.h" | 15 #include "components/ntp_snippets/ntp_snippets_service.h" |
16 #include "components/safe_json/safe_json_parser.h" | 16 #include "components/safe_json/safe_json_parser.h" |
17 #include "components/version_info/version_info.h" | 17 #include "components/version_info/version_info.h" |
18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/storage_partition.h" | |
21 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
22 | 21 |
23 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
24 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" | 23 #include "chrome/browser/android/ntp/ntp_snippets_launcher.h" |
25 #endif // OS_ANDROID | 24 #endif // OS_ANDROID |
26 | 25 |
27 using content::BrowserThread; | 26 using content::BrowserThread; |
28 using suggestions::SuggestionsService; | 27 using suggestions::SuggestionsService; |
29 using suggestions::SuggestionsServiceFactory; | 28 using suggestions::SuggestionsServiceFactory; |
30 | 29 |
(...skipping 16 matching lines...) Expand all Loading... |
47 BrowserContextDependencyManager::GetInstance()) { | 46 BrowserContextDependencyManager::GetInstance()) { |
48 DependsOn(SuggestionsServiceFactory::GetInstance()); | 47 DependsOn(SuggestionsServiceFactory::GetInstance()); |
49 } | 48 } |
50 | 49 |
51 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} | 50 NTPSnippetsServiceFactory::~NTPSnippetsServiceFactory() {} |
52 | 51 |
53 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( | 52 KeyedService* NTPSnippetsServiceFactory::BuildServiceInstanceFor( |
54 content::BrowserContext* context) const { | 53 content::BrowserContext* context) const { |
55 Profile* profile = Profile::FromBrowserContext(context); | 54 Profile* profile = Profile::FromBrowserContext(context); |
56 scoped_refptr<net::URLRequestContextGetter> request_context = | 55 scoped_refptr<net::URLRequestContextGetter> request_context = |
57 content::BrowserContext::GetDefaultStoragePartition(context)-> | 56 context->GetRequestContext(); |
58 GetURLRequestContext(); | |
59 SuggestionsService* suggestions_service = | 57 SuggestionsService* suggestions_service = |
60 SuggestionsServiceFactory::GetForProfile(profile); | 58 SuggestionsServiceFactory::GetForProfile(profile); |
61 | 59 |
62 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; | 60 ntp_snippets::NTPSnippetsScheduler* scheduler = nullptr; |
63 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
64 scheduler = NTPSnippetsLauncher::Get(); | 62 scheduler = NTPSnippetsLauncher::Get(); |
65 #endif // OS_ANDROID | 63 #endif // OS_ANDROID |
66 | 64 |
67 scoped_refptr<base::SequencedTaskRunner> task_runner = | 65 scoped_refptr<base::SequencedTaskRunner> task_runner = |
68 BrowserThread::GetBlockingPool() | 66 BrowserThread::GetBlockingPool() |
69 ->GetSequencedTaskRunnerWithShutdownBehavior( | 67 ->GetSequencedTaskRunnerWithShutdownBehavior( |
70 base::SequencedWorkerPool::GetSequenceToken(), | 68 base::SequencedWorkerPool::GetSequenceToken(), |
71 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 69 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
72 | 70 |
73 return new ntp_snippets::NTPSnippetsService( | 71 return new ntp_snippets::NTPSnippetsService( |
74 profile->GetPrefs(), suggestions_service, task_runner, | 72 profile->GetPrefs(), suggestions_service, task_runner, |
75 g_browser_process->GetApplicationLocale(), scheduler, | 73 g_browser_process->GetApplicationLocale(), scheduler, |
76 make_scoped_ptr(new ntp_snippets::NTPSnippetsFetcher( | 74 make_scoped_ptr(new ntp_snippets::NTPSnippetsFetcher( |
77 task_runner, request_context, | 75 task_runner, request_context, |
78 chrome::GetChannel() == version_info::Channel::STABLE)), | 76 chrome::GetChannel() == version_info::Channel::STABLE)), |
79 base::Bind(&safe_json::SafeJsonParser::Parse)); | 77 base::Bind(&safe_json::SafeJsonParser::Parse)); |
80 } | 78 } |
OLD | NEW |