OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/chrome/browser/application_context_impl.h" | 5 #include "ios/chrome/browser/application_context_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "components/history/core/browser/history_service.h" | 25 #include "components/history/core/browser/history_service.h" |
26 #include "components/keyed_service/core/service_access_type.h" | 26 #include "components/keyed_service/core/service_access_type.h" |
27 #include "components/metrics/metrics_service.h" | 27 #include "components/metrics/metrics_service.h" |
28 #include "components/metrics_services_manager/metrics_services_manager.h" | 28 #include "components/metrics_services_manager/metrics_services_manager.h" |
29 #include "components/net_log/chrome_net_log.h" | 29 #include "components/net_log/chrome_net_log.h" |
30 #include "components/network_time/network_time_tracker.h" | 30 #include "components/network_time/network_time_tracker.h" |
31 #include "components/physical_web/data_source/physical_web_data_source.h" | 31 #include "components/physical_web/data_source/physical_web_data_source.h" |
32 #include "components/prefs/pref_registry_simple.h" | 32 #include "components/prefs/pref_registry_simple.h" |
33 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
34 #include "components/translate/core/browser/translate_download_manager.h" | 34 #include "components/translate/core/browser/translate_download_manager.h" |
| 35 #include "components/ukm/public/ukm_recorder.h" |
35 #include "components/ukm/ukm_service.h" | 36 #include "components/ukm/ukm_service.h" |
36 #include "components/update_client/configurator.h" | 37 #include "components/update_client/configurator.h" |
37 #include "components/update_client/update_query_params.h" | 38 #include "components/update_client/update_query_params.h" |
38 #include "components/variations/service/variations_service.h" | 39 #include "components/variations/service/variations_service.h" |
39 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 40 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
40 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager_impl.h" | 41 #include "ios/chrome/browser/browser_state/chrome_browser_state_manager_impl.h" |
41 #include "ios/chrome/browser/chrome_paths.h" | 42 #include "ios/chrome/browser/chrome_paths.h" |
42 #include "ios/chrome/browser/component_updater/ios_component_updater_configurato
r.h" | 43 #include "ios/chrome/browser/component_updater/ios_component_updater_configurato
r.h" |
43 #include "ios/chrome/browser/history/history_service_factory.h" | 44 #include "ios/chrome/browser/history/history_service_factory.h" |
44 #include "ios/chrome/browser/ios_chrome_io_thread.h" | 45 #include "ios/chrome/browser/ios_chrome_io_thread.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 136 |
136 // Tell the metrics services that the application resumes. | 137 // Tell the metrics services that the application resumes. |
137 metrics::MetricsService* metrics_service = GetMetricsService(); | 138 metrics::MetricsService* metrics_service = GetMetricsService(); |
138 if (metrics_service && local_state) { | 139 if (metrics_service && local_state) { |
139 metrics_service->OnAppEnterForeground(); | 140 metrics_service->OnAppEnterForeground(); |
140 local_state->CommitPendingWrite(); | 141 local_state->CommitPendingWrite(); |
141 } | 142 } |
142 variations::VariationsService* variations_service = GetVariationsService(); | 143 variations::VariationsService* variations_service = GetVariationsService(); |
143 if (variations_service) | 144 if (variations_service) |
144 variations_service->OnAppEnterForeground(); | 145 variations_service->OnAppEnterForeground(); |
145 ukm::UkmService* ukm_service = GetUkmService(); | 146 ukm::UkmService* ukm_service = GetMetricsServicesManager()->GetUkmService(); |
146 if (ukm_service) | 147 if (ukm_service) |
147 ukm_service->OnAppEnterForeground(); | 148 ukm_service->OnAppEnterForeground(); |
148 } | 149 } |
149 | 150 |
150 void ApplicationContextImpl::OnAppEnterBackground() { | 151 void ApplicationContextImpl::OnAppEnterBackground() { |
151 DCHECK(thread_checker_.CalledOnValidThread()); | 152 DCHECK(thread_checker_.CalledOnValidThread()); |
152 // Mark all the ChromeBrowserStates as clean and persist history. | 153 // Mark all the ChromeBrowserStates as clean and persist history. |
153 std::vector<ios::ChromeBrowserState*> loaded_browser_state = | 154 std::vector<ios::ChromeBrowserState*> loaded_browser_state = |
154 GetChromeBrowserStateManager()->GetLoadedBrowserStates(); | 155 GetChromeBrowserStateManager()->GetLoadedBrowserStates(); |
155 for (ios::ChromeBrowserState* browser_state : loaded_browser_state) { | 156 for (ios::ChromeBrowserState* browser_state : loaded_browser_state) { |
156 if (history::HistoryService* history_service = | 157 if (history::HistoryService* history_service = |
157 ios::HistoryServiceFactory::GetForBrowserStateIfExists( | 158 ios::HistoryServiceFactory::GetForBrowserStateIfExists( |
158 browser_state, ServiceAccessType::EXPLICIT_ACCESS)) { | 159 browser_state, ServiceAccessType::EXPLICIT_ACCESS)) { |
159 history_service->HandleBackgrounding(); | 160 history_service->HandleBackgrounding(); |
160 } | 161 } |
161 | 162 |
162 PrefService* browser_state_prefs = browser_state->GetPrefs(); | 163 PrefService* browser_state_prefs = browser_state->GetPrefs(); |
163 if (browser_state_prefs) | 164 if (browser_state_prefs) |
164 browser_state_prefs->CommitPendingWrite(); | 165 browser_state_prefs->CommitPendingWrite(); |
165 } | 166 } |
166 | 167 |
167 PrefService* local_state = GetLocalState(); | 168 PrefService* local_state = GetLocalState(); |
168 local_state->SetBoolean(prefs::kLastSessionExitedCleanly, true); | 169 local_state->SetBoolean(prefs::kLastSessionExitedCleanly, true); |
169 | 170 |
170 // Tell the metrics services they were cleanly shutdown. | 171 // Tell the metrics services they were cleanly shutdown. |
171 metrics::MetricsService* metrics_service = GetMetricsService(); | 172 metrics::MetricsService* metrics_service = GetMetricsService(); |
172 if (metrics_service && local_state) | 173 if (metrics_service && local_state) |
173 metrics_service->OnAppEnterBackground(); | 174 metrics_service->OnAppEnterBackground(); |
174 ukm::UkmService* ukm_service = GetUkmService(); | 175 ukm::UkmService* ukm_service = GetMetricsServicesManager()->GetUkmService(); |
175 if (ukm_service) | 176 if (ukm_service) |
176 ukm_service->OnAppEnterBackground(); | 177 ukm_service->OnAppEnterBackground(); |
177 | 178 |
178 // Persisting to disk is protected by a critical task, so no other special | 179 // Persisting to disk is protected by a critical task, so no other special |
179 // handling is necessary on iOS. | 180 // handling is necessary on iOS. |
180 } | 181 } |
181 | 182 |
182 bool ApplicationContextImpl::WasLastShutdownClean() { | 183 bool ApplicationContextImpl::WasLastShutdownClean() { |
183 DCHECK(thread_checker_.CalledOnValidThread()); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
184 // Make sure the locale state is created as the file is initialized there. | 185 // Make sure the locale state is created as the file is initialized there. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 GetLocalState()))); | 224 GetLocalState()))); |
224 } | 225 } |
225 return metrics_services_manager_.get(); | 226 return metrics_services_manager_.get(); |
226 } | 227 } |
227 | 228 |
228 metrics::MetricsService* ApplicationContextImpl::GetMetricsService() { | 229 metrics::MetricsService* ApplicationContextImpl::GetMetricsService() { |
229 DCHECK(thread_checker_.CalledOnValidThread()); | 230 DCHECK(thread_checker_.CalledOnValidThread()); |
230 return GetMetricsServicesManager()->GetMetricsService(); | 231 return GetMetricsServicesManager()->GetMetricsService(); |
231 } | 232 } |
232 | 233 |
233 ukm::UkmService* ApplicationContextImpl::GetUkmService() { | 234 ukm::UkmRecorder* ApplicationContextImpl::GetUkmRecorder() { |
234 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
235 return GetMetricsServicesManager()->GetUkmService(); | 236 return GetMetricsServicesManager()->GetUkmService(); |
236 } | 237 } |
237 | 238 |
238 variations::VariationsService* ApplicationContextImpl::GetVariationsService() { | 239 variations::VariationsService* ApplicationContextImpl::GetVariationsService() { |
239 DCHECK(thread_checker_.CalledOnValidThread()); | 240 DCHECK(thread_checker_.CalledOnValidThread()); |
240 return GetMetricsServicesManager()->GetVariationsService(); | 241 return GetMetricsServicesManager()->GetVariationsService(); |
241 } | 242 } |
242 | 243 |
243 rappor::RapporServiceImpl* ApplicationContextImpl::GetRapporServiceImpl() { | 244 rappor::RapporServiceImpl* ApplicationContextImpl::GetRapporServiceImpl() { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 359 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
359 | 360 |
360 gcm_driver_ = gcm::CreateGCMDriverDesktop( | 361 gcm_driver_ = gcm::CreateGCMDriverDesktop( |
361 base::WrapUnique(new gcm::GCMClientFactory), GetLocalState(), store_path, | 362 base::WrapUnique(new gcm::GCMClientFactory), GetLocalState(), store_path, |
362 GetSystemURLRequestContext(), ::GetChannel(), | 363 GetSystemURLRequestContext(), ::GetChannel(), |
363 IOSChromeGCMProfileServiceFactory::GetProductCategoryForSubtypes(), | 364 IOSChromeGCMProfileServiceFactory::GetProductCategoryForSubtypes(), |
364 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI), | 365 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI), |
365 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), | 366 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), |
366 blocking_task_runner); | 367 blocking_task_runner); |
367 } | 368 } |
OLD | NEW |