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

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: Casts for win64 compile Created 6 years, 6 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 <vector>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
12 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/google/google_util.h" 21 #include "chrome/browser/google/google_util.h"
20 #include "chrome/browser/memory_details.h" 22 #include "chrome/browser/memory_details.h"
21 #include "chrome/browser/metrics/extensions_metrics_provider.h" 23 #include "chrome/browser/metrics/extensions_metrics_provider.h"
22 #include "chrome/browser/metrics/metrics_service.h" 24 #include "chrome/browser/metrics/metrics_service.h"
23 #include "chrome/browser/ui/browser_otr_state.h" 25 #include "chrome/browser/ui/browser_otr_state.h"
24 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/chrome_version_info.h" 28 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/crash_keys.h" 29 #include "chrome/common/crash_keys.h"
28 #include "chrome/common/render_messages.h" 30 #include "chrome/common/render_messages.h"
31 #include "components/metrics/net/net_metrics_log_uploader.h"
29 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/histogram_fetcher.h" 33 #include "content/public/browser/histogram_fetcher.h"
31 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/render_process_host.h" 35 #include "content/public/browser/render_process_host.h"
33 36
34 #if !defined(OS_ANDROID) 37 #if !defined(OS_ANDROID)
35 #include "chrome/browser/service_process/service_process_control.h" 38 #include "chrome/browser/service_process/service_process_control.h"
36 #endif 39 #endif
37 40
38 #if defined(OS_CHROMEOS) 41 #if defined(OS_CHROMEOS)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!version_info.IsOfficialBuild()) 178 if (!version_info.IsOfficialBuild())
176 version.append("-devel"); 179 version.append("-devel");
177 return version; 180 return version;
178 } 181 }
179 182
180 void ChromeMetricsServiceClient::OnLogUploadComplete() { 183 void ChromeMetricsServiceClient::OnLogUploadComplete() {
181 // Collect network stats after each UMA upload. 184 // Collect network stats after each UMA upload.
182 network_stats_uploader_.CollectAndReportNetworkStats(); 185 network_stats_uploader_.CollectAndReportNetworkStats();
183 } 186 }
184 187
188 void ChromeMetricsServiceClient::StartGatheringMetrics(
189 const base::Closure& done_callback) {
190 // TODO(blundell): Move all metrics gathering tasks from MetricsService to
191 // here.
192 #if defined(OS_CHROMEOS)
193 chromeos_metrics_provider_->InitTaskGetHardwareClass(done_callback);
194 #else
195 done_callback.Run();
196 #endif
197 }
198
185 void ChromeMetricsServiceClient::CollectFinalMetrics( 199 void ChromeMetricsServiceClient::CollectFinalMetrics(
186 const base::Closure& done_callback) { 200 const base::Closure& done_callback) {
187 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
188 202
189 collect_final_metrics_done_callback_ = done_callback; 203 collect_final_metrics_done_callback_ = done_callback;
190 204
191 // Begin the multi-step process of collecting memory usage histograms: 205 // Begin the multi-step process of collecting memory usage histograms:
192 // First spawn a task to collect the memory details; when that task is 206 // First spawn a task to collect the memory details; when that task is
193 // finished, it will call OnMemoryDetailCollectionDone. That will in turn 207 // finished, it will call OnMemoryDetailCollectionDone. That will in turn
194 // call HistogramSynchronization to collect histograms from all renderers and 208 // call HistogramSynchronization to collect histograms from all renderers and
(...skipping 10 matching lines...) Expand all
205 details->StartFetch(MemoryDetails::UPDATE_USER_METRICS); 219 details->StartFetch(MemoryDetails::UPDATE_USER_METRICS);
206 220
207 // Collect WebCore cache information to put into a histogram. 221 // Collect WebCore cache information to put into a histogram.
208 for (content::RenderProcessHost::iterator i( 222 for (content::RenderProcessHost::iterator i(
209 content::RenderProcessHost::AllHostsIterator()); 223 content::RenderProcessHost::AllHostsIterator());
210 !i.IsAtEnd(); i.Advance()) { 224 !i.IsAtEnd(); i.Advance()) {
211 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats()); 225 i.GetCurrentValue()->Send(new ChromeViewMsg_GetCacheResourceStats());
212 } 226 }
213 } 227 }
214 228
229 scoped_ptr<metrics::MetricsLogUploader>
230 ChromeMetricsServiceClient::CreateUploader(
231 const std::string& server_url,
232 const std::string& mime_type,
233 const base::Callback<void(int)>& on_upload_complete) {
234 return scoped_ptr<metrics::MetricsLogUploader>(
235 new metrics::NetMetricsLogUploader(
236 g_browser_process->system_request_context(), server_url, mime_type,
237 on_upload_complete));
238 }
239
215 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() { 240 void ChromeMetricsServiceClient::OnMemoryDetailCollectionDone() {
216 DCHECK(thread_checker_.CalledOnValidThread()); 241 DCHECK(thread_checker_.CalledOnValidThread());
217 242
218 // This function should only be called as the callback from an ansynchronous 243 // This function should only be called as the callback from an ansynchronous
219 // step. 244 // step.
220 DCHECK(waiting_for_collect_final_metrics_step_); 245 DCHECK(waiting_for_collect_final_metrics_step_);
221 246
222 // Create a callback_task for OnHistogramSynchronizationDone. 247 // Create a callback_task for OnHistogramSynchronizationDone.
223 base::Closure callback = base::Bind( 248 base::Closure callback = base::Bind(
224 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone, 249 &ChromeMetricsServiceClient::OnHistogramSynchronizationDone,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: 353 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED:
329 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: 354 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
330 metrics_service_->OnApplicationNotIdle(); 355 metrics_service_->OnApplicationNotIdle();
331 break; 356 break;
332 357
333 default: 358 default:
334 NOTREACHED(); 359 NOTREACHED();
335 } 360 }
336 } 361 }
337 362
338 void ChromeMetricsServiceClient::StartGatheringMetrics(
339 const base::Closure& done_callback) {
340 // TODO(blundell): Move all metrics gathering tasks from MetricsService to
341 // here.
342 #if defined(OS_CHROMEOS)
343 chromeos_metrics_provider_->InitTaskGetHardwareClass(done_callback);
344 #else
345 done_callback.Run();
346 #endif
347 }
348
349 #if defined(OS_WIN) 363 #if defined(OS_WIN)
350 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() { 364 void ChromeMetricsServiceClient::CountBrowserCrashDumpAttempts() {
351 // Open the registry key for iteration. 365 // Open the registry key for iteration.
352 base::win::RegKey regkey; 366 base::win::RegKey regkey;
353 if (regkey.Open(HKEY_CURRENT_USER, 367 if (regkey.Open(HKEY_CURRENT_USER,
354 chrome::kBrowserCrashDumpAttemptsRegistryPath, 368 chrome::kBrowserCrashDumpAttemptsRegistryPath,
355 KEY_ALL_ACCESS) != ERROR_SUCCESS) { 369 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
356 return; 370 return;
357 } 371 }
358 372
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // Capture the histogram samples. 404 // Capture the histogram samples.
391 if (dumps_with_crash != 0) 405 if (dumps_with_crash != 0)
392 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash); 406 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithCrash", dumps_with_crash);
393 if (dumps_with_no_crash != 0) 407 if (dumps_with_no_crash != 0)
394 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash); 408 UMA_HISTOGRAM_COUNTS("Chrome.BrowserDumpsWithNoCrash", dumps_with_no_crash);
395 int total_dumps = dumps_with_crash + dumps_with_no_crash; 409 int total_dumps = dumps_with_crash + dumps_with_no_crash;
396 if (total_dumps != 0) 410 if (total_dumps != 0)
397 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps); 411 UMA_HISTOGRAM_COUNTS("Chrome.BrowserCrashDumpAttempts", total_dumps);
398 } 412 }
399 #endif // defined(OS_WIN) 413 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.h ('k') | chrome/browser/metrics/compression_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698