| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 // We're going away, so exit background mode (does nothing if we aren't in | 219 // We're going away, so exit background mode (does nothing if we aren't in |
| 220 // background mode currently). This is primarily needed for unit tests, | 220 // background mode currently). This is primarily needed for unit tests, |
| 221 // because in an actual running system we'd get an APP_TERMINATING | 221 // because in an actual running system we'd get an APP_TERMINATING |
| 222 // notification before being destroyed. | 222 // notification before being destroyed. |
| 223 EndBackgroundMode(); | 223 EndBackgroundMode(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // static | 226 // static |
| 227 void BackgroundModeManager::RegisterPrefs(PrefRegistrySimple* registry) { | 227 void BackgroundModeManager::RegisterPrefs(PrefRegistrySimple* registry) { |
| 228 registry->RegisterBooleanPref(prefs::kUserCreatedLoginItem, false); | 228 #if defined(OS_MACOSX) |
| 229 registry->RegisterBooleanPref(prefs::kUserRemovedLoginItem, false); | 229 registry->RegisterBooleanPref(prefs::kUserRemovedLoginItem, false); |
| 230 registry->RegisterBooleanPref(prefs::kChromeCreatedLoginItem, false); |
| 231 registry->RegisterBooleanPref(prefs::kMigratedLoginItemPref, false); |
| 232 #endif |
| 230 registry->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); | 233 registry->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); |
| 231 } | 234 } |
| 232 | 235 |
| 233 | 236 |
| 234 void BackgroundModeManager::RegisterProfile(Profile* profile) { | 237 void BackgroundModeManager::RegisterProfile(Profile* profile) { |
| 235 // We don't want to register multiple times for one profile. | 238 // We don't want to register multiple times for one profile. |
| 236 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); | 239 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); |
| 237 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, | 240 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, |
| 238 profile)); | 241 profile)); |
| 239 background_mode_data_[profile] = bmd; | 242 background_mode_data_[profile] = bmd; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if (!ShouldBeInBackgroundMode()) { | 378 if (!ShouldBeInBackgroundMode()) { |
| 376 // We've uninstalled our last background app, make sure we exit background | 379 // We've uninstalled our last background app, make sure we exit background |
| 377 // mode and no longer launch on startup. | 380 // mode and no longer launch on startup. |
| 378 EnableLaunchOnStartup(false); | 381 EnableLaunchOnStartup(false); |
| 379 EndBackgroundMode(); | 382 EndBackgroundMode(); |
| 380 } else { | 383 } else { |
| 381 // We have at least one background app running - make sure we're in | 384 // We have at least one background app running - make sure we're in |
| 382 // background mode. | 385 // background mode. |
| 383 if (!in_background_mode_) { | 386 if (!in_background_mode_) { |
| 384 // We're entering background mode - make sure we have launch-on-startup | 387 // We're entering background mode - make sure we have launch-on-startup |
| 385 // enabled. | 388 // enabled. On Mac, the platform-specific code tracks whether the user |
| 386 // On a Mac, we use 'login items' mechanism which has user-facing UI so we | 389 // has deleted a login item in the past, and if so, no login item will |
| 387 // don't want to stomp on user choice every time we start and load | 390 // be created (to avoid overriding the specific user action). |
| 388 // registered extensions. This means that if a background app is removed | |
| 389 // or added while Chrome is not running, we could leave Chrome in the | |
| 390 // wrong state, but this is better than constantly forcing Chrome to | |
| 391 // launch on startup even after the user removes the LoginItem manually. | |
| 392 #if !defined(OS_MACOSX) | |
| 393 EnableLaunchOnStartup(true); | 391 EnableLaunchOnStartup(true); |
| 394 #endif | |
| 395 | 392 |
| 396 StartBackgroundMode(); | 393 StartBackgroundMode(); |
| 397 } | 394 } |
| 398 // List of applications changed so update the UI. | 395 // List of applications changed so update the UI. |
| 399 UpdateStatusTrayIconContextMenu(); | 396 UpdateStatusTrayIconContextMenu(); |
| 400 } | 397 } |
| 401 } | 398 } |
| 402 | 399 |
| 403 /////////////////////////////////////////////////////////////////////////////// | 400 /////////////////////////////////////////////////////////////////////////////// |
| 404 // BackgroundModeManager, ProfileInfoCacheObserver overrides | 401 // BackgroundModeManager, ProfileInfoCacheObserver overrides |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 return IsBackgroundModePrefEnabled() && | 620 return IsBackgroundModePrefEnabled() && |
| 624 (GetBackgroundAppCount() > 0 || keep_alive_for_test_); | 621 (GetBackgroundAppCount() > 0 || keep_alive_for_test_); |
| 625 } | 622 } |
| 626 | 623 |
| 627 void BackgroundModeManager::OnBackgroundAppInstalled( | 624 void BackgroundModeManager::OnBackgroundAppInstalled( |
| 628 const Extension* extension) { | 625 const Extension* extension) { |
| 629 // Background mode is disabled - don't do anything. | 626 // Background mode is disabled - don't do anything. |
| 630 if (!IsBackgroundModePrefEnabled()) | 627 if (!IsBackgroundModePrefEnabled()) |
| 631 return; | 628 return; |
| 632 | 629 |
| 633 // Special behavior for the Mac: We enable "launch-on-startup" only on new app | |
| 634 // installation rather than every time we go into background mode. This is | |
| 635 // because the Mac exposes "Open at Login" UI to the user and we don't want to | |
| 636 // clobber the user's selection on every browser launch. | |
| 637 // Other platforms enable launch-on-startup in OnApplicationListChanged(). | |
| 638 #if defined(OS_MACOSX) | |
| 639 EnableLaunchOnStartup(true); | |
| 640 #endif | |
| 641 | |
| 642 // Check if we need a status tray icon and make one if we do (needed so we | 630 // Check if we need a status tray icon and make one if we do (needed so we |
| 643 // can display the app-installed notification below). | 631 // can display the app-installed notification below). |
| 644 CreateStatusTrayIcon(); | 632 CreateStatusTrayIcon(); |
| 645 | 633 |
| 646 // Notify the user that a background app has been installed. | 634 // Notify the user that a background app has been installed. |
| 647 if (extension) // NULL when called by unit tests. | 635 if (extension) // NULL when called by unit tests. |
| 648 DisplayAppInstalledNotification(extension); | 636 DisplayAppInstalledNotification(extension); |
| 649 } | 637 } |
| 650 | 638 |
| 651 void BackgroundModeManager::CreateStatusTrayIcon() { | 639 void BackgroundModeManager::CreateStatusTrayIcon() { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 } | 765 } |
| 778 } | 766 } |
| 779 return profile_it; | 767 return profile_it; |
| 780 } | 768 } |
| 781 | 769 |
| 782 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 770 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 783 PrefService* service = g_browser_process->local_state(); | 771 PrefService* service = g_browser_process->local_state(); |
| 784 DCHECK(service); | 772 DCHECK(service); |
| 785 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 773 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 786 } | 774 } |
| OLD | NEW |