Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_browser_main_extra_parts_metrics.h" | 5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/cpu.h" | 11 #include "base/cpu.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/about_flags.h" | 19 #include "chrome/browser/about_flags.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_browser_main.h" | 21 #include "chrome/browser/chrome_browser_main.h" |
| 22 #include "chrome/browser/mac/bluetooth_utility.h" | 22 #include "chrome/browser/mac/bluetooth_utility.h" |
| 23 #include "chrome/browser/shell_integration.h" | 23 #include "chrome/browser/shell_integration.h" |
| 24 #include "chrome/browser/ui/browser.h" | |
| 25 #include "chrome/browser/ui/browser_list.h" | |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 24 #include "components/flags_ui/pref_service_flags_storage.h" | 27 #include "components/flags_ui/pref_service_flags_storage.h" |
| 25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 27 #include "ui/base/touch/touch_device.h" | 30 #include "ui/base/touch/touch_device.h" |
| 28 #include "ui/base/ui_base_switches.h" | 31 #include "ui/base/ui_base_switches.h" |
| 29 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
| 30 | 33 |
| 31 #if !defined(OS_ANDROID) | 34 #if !defined(OS_ANDROID) |
| 32 #include "chrome/browser/metrics/first_web_contents_profiler.h" | 35 #include "chrome/browser/metrics/first_web_contents_profiler.h" |
| 33 #include "chrome/browser/metrics/tab_usage_recorder.h" | 36 #include "chrome/browser/metrics/tab_usage_recorder.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 base::Bind(&RecordIsPinnedToTaskbarHistogram), | 416 base::Bind(&RecordIsPinnedToTaskbarHistogram), |
| 414 kStartupMetricsGatheringDelay); | 417 kStartupMetricsGatheringDelay); |
| 415 #endif // defined(OS_WIN) | 418 #endif // defined(OS_WIN) |
| 416 | 419 |
| 417 display_count_ = display::Screen::GetScreen()->GetNumDisplays(); | 420 display_count_ = display::Screen::GetScreen()->GetNumDisplays(); |
| 418 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnStartup", display_count_); | 421 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnStartup", display_count_); |
| 419 display::Screen::GetScreen()->AddObserver(this); | 422 display::Screen::GetScreen()->AddObserver(this); |
| 420 is_screen_observer_ = true; | 423 is_screen_observer_ = true; |
| 421 | 424 |
| 422 #if !defined(OS_ANDROID) | 425 #if !defined(OS_ANDROID) |
| 423 metrics::BeginFirstWebContentsProfiling(); | 426 const BrowserList* browser_list = BrowserList::GetInstance(); |
| 427 | |
| 428 auto first_browser = browser_list->begin(); | |
| 429 if (first_browser == browser_list->end()) | |
| 430 DCHECK(0); | |
|
sky
2017/04/07 21:52:14
I'm not entirely sure it's valid to assume there i
eugenebng
2017/04/10 12:04:43
Thank you for comments, overlooked this part of co
| |
| 431 | |
| 432 TabStripModel* tab_strip = (*first_browser)->tab_strip_model(); | |
| 433 DCHECK(tab_strip); | |
| 434 if (tab_strip->empty()) { | |
| 435 // Start web contents profiling later, when there will be a tab to profile | |
| 436 tab_strip->AddObserver(this); | |
|
sky
2017/04/07 21:52:14
Make sure you deal with case of this being deleted
| |
| 437 } else { | |
| 438 metrics::BeginFirstWebContentsProfiling(); | |
| 439 } | |
| 424 metrics::TabUsageRecorder::InitializeIfNeeded(); | 440 metrics::TabUsageRecorder::InitializeIfNeeded(); |
| 425 #endif // !defined(OS_ANDROID) | 441 #endif // !defined(OS_ANDROID) |
| 426 } | 442 } |
| 427 | 443 |
| 444 void ChromeBrowserMainExtraPartsMetrics::TabInsertedAt( | |
| 445 TabStripModel* tab_strip_model, | |
| 446 content::WebContents* contents, | |
| 447 int index, | |
| 448 bool foreground) { | |
| 449 VLOG(0) << "begin profiling!"; | |
|
sky
2017/04/07 21:52:14
Remove VLOGs.
| |
| 450 metrics::BeginFirstWebContentsProfiling(); | |
| 451 tab_strip_model->RemoveObserver(this); | |
| 452 } | |
| 453 | |
| 428 void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded( | 454 void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded( |
| 429 const display::Display& new_display) { | 455 const display::Display& new_display) { |
| 430 EmitDisplaysChangedMetric(); | 456 EmitDisplaysChangedMetric(); |
| 431 } | 457 } |
| 432 | 458 |
| 433 void ChromeBrowserMainExtraPartsMetrics::OnDisplayRemoved( | 459 void ChromeBrowserMainExtraPartsMetrics::OnDisplayRemoved( |
| 434 const display::Display& old_display) { | 460 const display::Display& old_display) { |
| 435 EmitDisplaysChangedMetric(); | 461 EmitDisplaysChangedMetric(); |
| 436 } | 462 } |
| 437 | 463 |
| 438 void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged( | 464 void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged( |
| 439 const display::Display& display, | 465 const display::Display& display, |
| 440 uint32_t changed_metrics) {} | 466 uint32_t changed_metrics) {} |
| 441 | 467 |
| 442 void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() { | 468 void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() { |
| 443 int display_count = display::Screen::GetScreen()->GetNumDisplays(); | 469 int display_count = display::Screen::GetScreen()->GetNumDisplays(); |
| 444 if (display_count != display_count_) { | 470 if (display_count != display_count_) { |
| 445 display_count_ = display_count; | 471 display_count_ = display_count; |
| 446 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnChange", display_count_); | 472 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnChange", display_count_); |
| 447 } | 473 } |
| 448 } | 474 } |
| 449 | 475 |
| 450 namespace chrome { | 476 namespace chrome { |
| 451 | 477 |
| 452 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { | 478 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { |
| 453 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics()); | 479 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics()); |
| 454 } | 480 } |
| 455 | 481 |
| 456 } // namespace chrome | 482 } // namespace chrome |
| OLD | NEW |