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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 291153013: Make MetricsService upload logs through an interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 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 | Annotate | Revision Log
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 "chrome/browser/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
20 #include "chrome/browser/memory_details.h" 20 #include "chrome/browser/memory_details.h"
21 #include "chrome/browser/metrics/metrics_service.h" 21 #include "chrome/browser/metrics/metrics_service.h"
22 #include "chrome/browser/ui/browser_otr_state.h" 22 #include "chrome/browser/ui/browser_otr_state.h"
23 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
26 #include "chrome/common/crash_keys.h" 26 #include "chrome/common/crash_keys.h"
27 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
28 #include "components/metrics/net/net_metrics_log_uploader.h"
28 #include "content/public/browser/histogram_fetcher.h" 29 #include "content/public/browser/histogram_fetcher.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
31 32
32 #if !defined(OS_ANDROID) 33 #if !defined(OS_ANDROID)
33 #include "chrome/browser/service_process/service_process_control.h" 34 #include "chrome/browser/service_process/service_process_control.h"
34 #endif 35 #endif
35 36
36 #if defined(OS_WIN) 37 #if defined(OS_WIN)
37 #include <windows.h> 38 #include <windows.h>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (!version_info.IsOfficialBuild()) 137 if (!version_info.IsOfficialBuild())
137 version.append("-devel"); 138 version.append("-devel");
138 return version; 139 return version;
139 } 140 }
140 141
141 void ChromeMetricsServiceClient::OnLogUploadComplete() { 142 void ChromeMetricsServiceClient::OnLogUploadComplete() {
142 // Collect network stats after each UMA upload. 143 // Collect network stats after each UMA upload.
143 network_stats_uploader_.CollectAndReportNetworkStats(); 144 network_stats_uploader_.CollectAndReportNetworkStats();
144 } 145 }
145 146
147 void ChromeMetricsServiceClient::StartGatheringMetrics(
148 const base::Closure& done_callback) {
149 // TODO(blundell): Move metrics gathering tasks from MetricsService to here.
150 done_callback.Run();
151 }
152
146 void ChromeMetricsServiceClient::CollectFinalMetrics( 153 void ChromeMetricsServiceClient::CollectFinalMetrics(
147 const base::Closure& done_callback) { 154 const base::Closure& done_callback) {
148 DCHECK(thread_checker_.CalledOnValidThread()); 155 DCHECK(thread_checker_.CalledOnValidThread());
149 156
150 collect_final_metrics_done_callback_ = done_callback; 157 collect_final_metrics_done_callback_ = done_callback;
151 158
152 // Begin the multi-step process of collecting memory usage histograms: 159 // Begin the multi-step process of collecting memory usage histograms:
153 // First spawn a task to collect the memory details; when that task is 160 // First spawn a task to collect the memory details; when that task is
154 // finished, it will call OnMemoryDetailCollectionDone. That will in turn 161 // finished, it will call OnMemoryDetailCollectionDone. That will in turn
155 // call HistogramSynchronization to collect histograms from all renderers and 162 // call HistogramSynchronization to collect histograms from all renderers and
(...skipping 10 matching lines...) Expand all
166 details->StartFetch(MemoryDetails::UPDATE_USER_METRICS); 173 details->StartFetch(MemoryDetails::UPDATE_USER_METRICS);
167 174
168 // Collect WebCore cache information to put into a histogram. 175 // Collect WebCore cache information to put into a histogram.
169 for (content::RenderProcessHost::iterator i( 176 for (content::RenderProcessHost::iterator i(
170 content::RenderProcessHost::AllHostsIterator()); 177 content::RenderProcessHost::AllHostsIterator());
171 !i.IsAtEnd(); i.Advance()) { 178 !i.IsAtEnd(); i.Advance()) {
172 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats()); 179 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats());
173 } 180 }
174 } 181 }
175 182
183 scoped_ptr<metrics::MetricsLogUploader>
184 ChromeMetricsServiceClient::CreateUploader(
185 const std::string& server_url,
186 const std::string& mime_type,
187 const base::Callback<void(int)> on_upload_complete) {
188 return scoped_ptr<metrics::MetricsLogUploader>(
189 new metrics::NetMetricsLogUploader(
190 g_browser_process->system_request_context(), server_url, mime_type,
191 on_upload_complete));
192 }
193
176 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() { 194 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() {
177 DCHECK(thread_checker_.CalledOnValidThread()); 195 DCHECK(thread_checker_.CalledOnValidThread());
178 196
179 // This function should only be called as the callback from an ansynchronous 197 // This function should only be called as the callback from an ansynchronous
180 // step. 198 // step.
181 DCHECK(waiting_for_collect_final_metrics_step_); 199 DCHECK(waiting_for_collect_final_metrics_step_);
182 200
183 // Create a callback_task for OnHistogramSynchronizationDone. 201 // Create a callback_task for OnHistogramSynchronizationDone.
184 base::Closure callback = base::Bind( 202 base::Closure callback = base::Bind(
185 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone, 203 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // TODO(isherman): Remove this NULL check: http://crbug.com/375248 309 // TODO(isherman): Remove this NULL check: http://crbug.com/375248
292 if (service_) 310 if (service_)
293 service_->OnApplicationNotIdle(); 311 service_->OnApplicationNotIdle();
294 break; 312 break;
295 313
296 default: 314 default:
297 NOTREACHED(); 315 NOTREACHED();
298 } 316 }
299 } 317 }
300 318
301 void ChromeMetricsServiceClient::StartGatheringMetrics(
302 const base::Closure& done_callback) {
303 // TODO(blundell): Move metrics gathering tasks from MetricsService to here.
304 done_callback.Run();
305 }
306
307 #if defined(OS_WIN) 319 #if defined(OS_WIN)
308 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { 320 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() {
309 // Open the registry key for iteration. 321 // Open the registry key for iteration.
310 base::win::RegKey regkey; 322 base::win::RegKey regkey;
311 if (regkey.Open(HKEY_CURRENT_USER, 323 if (regkey.Open(HKEY_CURRENT_USER,
312 chrome::kBrowserCrashDumpAttemptsRegistryPath, 324 chrome::kBrowserCrashDumpAttemptsRegistryPath,
313 KEY_ALL_ACCESS) != ERROR_SUCCESS) { 325 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
314 return; 326 return;
315 } 327 }
316 328
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // Capture the histogram samples. 360 // Capture the histogram samples.
349 if (dumps_with_crash != 0) 361 if (dumps_with_crash != 0)
350 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); 362 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash);
351 if (dumps_with_no_crash != 0) 363 if (dumps_with_no_crash != 0)
352 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); 364 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash);
353 int total_dumps = dumps_with_crash + dumps_with_no_crash; 365 int total_dumps = dumps_with_crash + dumps_with_no_crash;
354 if (total_dumps != 0) 366 if (total_dumps != 0)
355 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); 367 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps);
356 } 368 }
357 #endif // defined(OS_WIN) 369 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698