| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/background/background_mode_manager.h" | 5 #include "chrome/browser/background/background_mode_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "extensions/common/permissions/permission_set.h" | 59 #include "extensions/common/permissions/permission_set.h" |
| 60 #include "grit/chrome_unscaled_resources.h" | 60 #include "grit/chrome_unscaled_resources.h" |
| 61 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
| 62 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
| 63 | 63 |
| 64 using base::UserMetricsAction; | 64 using base::UserMetricsAction; |
| 65 using extensions::Extension; | 65 using extensions::Extension; |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 // Records histogram about which auto-launch pattern (if any) was used to launch | |
| 70 // the current process based on |command_line|. | |
| 71 void RecordAutoLaunchState(const base::CommandLine& command_line) { | |
| 72 enum AutoLaunchState { | |
| 73 AUTO_LAUNCH_NONE = 0, | |
| 74 AUTO_LAUNCH_BACKGROUND = 1, | |
| 75 AUTO_LAUNCH_FOREGROUND = 2, | |
| 76 AUTO_LAUNCH_FOREGROUND_USELESS = 3, | |
| 77 AUTO_LAUNCH_NUM_STATES | |
| 78 } auto_launch_state = AUTO_LAUNCH_NONE; | |
| 79 | |
| 80 if (command_line.HasSwitch(switches::kNoStartupWindow)) | |
| 81 auto_launch_state = AUTO_LAUNCH_BACKGROUND; | |
| 82 | |
| 83 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup)) { | |
| 84 // The only purpose of kAutoLaunchAtStartup is to override a background | |
| 85 // auto-launch from kNoStartupWindow into a foreground auto-launch. It's a | |
| 86 // meaningless switch on its own. | |
| 87 if (auto_launch_state == AUTO_LAUNCH_BACKGROUND) { | |
| 88 auto_launch_state = AUTO_LAUNCH_FOREGROUND; | |
| 89 } else { | |
| 90 auto_launch_state = AUTO_LAUNCH_FOREGROUND_USELESS; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 // Observe the AutoLaunchStates in the wild. According to the platform- | |
| 95 // specific implementations of EnableLaunchOnStartup(), we'd expect only Mac | |
| 96 // and Windows to have any sort of AutoLaunchState and only Windows should use | |
| 97 // FOREGROUND if at all (it was only used by a deprecated experiment and a | |
| 98 // master pref which may not be used much). Tighten up auto-launch settings | |
| 99 // based on the result of usage in the wild. | |
| 100 UMA_HISTOGRAM_ENUMERATION("BackgroundMode.OnStartup.AutoLaunchState", | |
| 101 auto_launch_state, AUTO_LAUNCH_NUM_STATES); | |
| 102 } | |
| 103 | |
| 104 // Enum for recording menu item clicks in UMA. | 69 // Enum for recording menu item clicks in UMA. |
| 105 // NOTE: Do not renumber these as that would confuse interpretation of | 70 // NOTE: Do not renumber these as that would confuse interpretation of |
| 106 // previously logged data. When making changes, also update histograms.xml. | 71 // previously logged data. When making changes, also update histograms.xml. |
| 107 enum MenuItem { | 72 enum MenuItem { |
| 108 MENU_ITEM_ABOUT = 0, | 73 MENU_ITEM_ABOUT = 0, |
| 109 MENU_ITEM_TASK_MANAGER = 1, | 74 MENU_ITEM_TASK_MANAGER = 1, |
| 110 MENU_ITEM_BACKGROUND_CLIENT = 2, | 75 MENU_ITEM_BACKGROUND_CLIENT = 2, |
| 111 MENU_ITEM_KEEP_RUNNING = 3, | 76 MENU_ITEM_KEEP_RUNNING = 3, |
| 112 MENU_ITEM_EXIT = 4, | 77 MENU_ITEM_EXIT = 4, |
| 113 MENU_ITEM_NUM_STATES | 78 MENU_ITEM_NUM_STATES |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 weak_factory_(this) { | 278 weak_factory_(this) { |
| 314 // We should never start up if there is no browser process or if we are | 279 // We should never start up if there is no browser process or if we are |
| 315 // currently quitting. | 280 // currently quitting. |
| 316 CHECK(g_browser_process != NULL); | 281 CHECK(g_browser_process != NULL); |
| 317 CHECK(!browser_shutdown::IsTryingToQuit()); | 282 CHECK(!browser_shutdown::IsTryingToQuit()); |
| 318 | 283 |
| 319 // Add self as an observer for the profile info cache so we know when profiles | 284 // Add self as an observer for the profile info cache so we know when profiles |
| 320 // are deleted and their names change. | 285 // are deleted and their names change. |
| 321 profile_cache_->AddObserver(this); | 286 profile_cache_->AddObserver(this); |
| 322 | 287 |
| 323 RecordAutoLaunchState(command_line); | 288 UMA_HISTOGRAM_BOOLEAN("BackgroundMode.OnStartup.AutoLaunchState", |
| 289 command_line.HasSwitch(switches::kNoStartupWindow)); |
| 324 UMA_HISTOGRAM_BOOLEAN("BackgroundMode.OnStartup.IsBackgroundModePrefEnabled", | 290 UMA_HISTOGRAM_BOOLEAN("BackgroundMode.OnStartup.IsBackgroundModePrefEnabled", |
| 325 IsBackgroundModePrefEnabled()); | 291 IsBackgroundModePrefEnabled()); |
| 326 | 292 |
| 327 // Listen for the background mode preference changing. | 293 // Listen for the background mode preference changing. |
| 328 if (g_browser_process->local_state()) { // Skip for unit tests | 294 if (g_browser_process->local_state()) { // Skip for unit tests |
| 329 pref_registrar_.Init(g_browser_process->local_state()); | 295 pref_registrar_.Init(g_browser_process->local_state()); |
| 330 pref_registrar_.Add( | 296 pref_registrar_.Add( |
| 331 prefs::kBackgroundModeEnabled, | 297 prefs::kBackgroundModeEnabled, |
| 332 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged, | 298 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged, |
| 333 base::Unretained(this))); | 299 base::Unretained(this))); |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 } | 991 } |
| 1026 } | 992 } |
| 1027 return profile_it; | 993 return profile_it; |
| 1028 } | 994 } |
| 1029 | 995 |
| 1030 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 996 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 1031 PrefService* service = g_browser_process->local_state(); | 997 PrefService* service = g_browser_process->local_state(); |
| 1032 DCHECK(service); | 998 DCHECK(service); |
| 1033 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 999 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 1034 } | 1000 } |
| OLD | NEW |