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

Side by Side Diff: ios/chrome/browser/application_context_impl.cc

Issue 2722113004: Flush UKM metrics when backgrounded on Android and iOS. (Closed)
Patch Set: add missing newline Created 3 years, 9 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
« components/ukm/ukm_service.cc ('K') | « components/ukm/ukm_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 = g_browser_process->ukm_service();
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 = g_browser_process->ukm_service();
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 352 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
347 353
348 gcm_driver_ = gcm::CreateGCMDriverDesktop( 354 gcm_driver_ = gcm::CreateGCMDriverDesktop(
349 base::WrapUnique(new gcm::GCMClientFactory), GetLocalState(), store_path, 355 base::WrapUnique(new gcm::GCMClientFactory), GetLocalState(), store_path,
350 GetSystemURLRequestContext(), ::GetChannel(), 356 GetSystemURLRequestContext(), ::GetChannel(),
351 IOSChromeGCMProfileServiceFactory::GetProductCategoryForSubtypes(), 357 IOSChromeGCMProfileServiceFactory::GetProductCategoryForSubtypes(),
352 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI), 358 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI),
353 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), 359 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO),
354 blocking_task_runner); 360 blocking_task_runner);
355 } 361 }
OLDNEW
« components/ukm/ukm_service.cc ('K') | « components/ukm/ukm_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698