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