| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/lifetime/application_lifetime.h" | 23 #include "chrome/browser/lifetime/application_lifetime.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_info_cache.h" | 25 #include "chrome/browser/profiles/profile_info_cache.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/status_icons/status_icon.h" | 27 #include "chrome/browser/status_icons/status_icon.h" |
| 28 #include "chrome/browser/status_icons/status_tray.h" | 28 #include "chrome/browser/status_icons/status_tray.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_commands.h" | 30 #include "chrome/browser/ui/browser_commands.h" |
| 31 #include "chrome/browser/ui/browser_dialogs.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/browser_list.h" | 33 #include "chrome/browser/ui/browser_list.h" |
| 33 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
| 34 #include "chrome/browser/ui/extensions/application_launch.h" | 35 #include "chrome/browser/ui/extensions/application_launch.h" |
| 35 #include "chrome/browser/ui/host_desktop.h" | 36 #include "chrome/browser/ui/host_desktop.h" |
| 36 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
| 37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/extensions/extension_constants.h" | 39 #include "chrome/common/extensions/extension_constants.h" |
| 39 #include "chrome/common/extensions/manifest_url_handler.h" | 40 #include "chrome/common/extensions/manifest_url_handler.h" |
| 40 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 GetBackgroundModeIterator(old_profile_name); | 477 GetBackgroundModeIterator(old_profile_name); |
| 477 // We check that the returned iterator is valid due to unittests, but really | 478 // We check that the returned iterator is valid due to unittests, but really |
| 478 // this should only be called on profiles already known by the background | 479 // this should only be called on profiles already known by the background |
| 479 // mode manager. | 480 // mode manager. |
| 480 if (it != background_mode_data_.end()) { | 481 if (it != background_mode_data_.end()) { |
| 481 it->second->SetName(new_profile_name); | 482 it->second->SetName(new_profile_name); |
| 482 UpdateStatusTrayIconContextMenu(); | 483 UpdateStatusTrayIconContextMenu(); |
| 483 } | 484 } |
| 484 } | 485 } |
| 485 | 486 |
| 487 BackgroundModeManager::BackgroundModeData* |
| 488 BackgroundModeManager::GetBackgroundModeDataForLastProfile() const { |
| 489 Profile* most_recent_profile = g_browser_process->profile_manager()-> |
| 490 GetLastUsedProfileAllowedByPolicy(); |
| 491 BackgroundModeInfoMap::const_iterator profile_background_data = |
| 492 background_mode_data_.find(most_recent_profile); |
| 493 |
| 494 if (profile_background_data == background_mode_data_.end()) |
| 495 return NULL; |
| 496 |
| 497 // Do not permit a locked profile to be used to open a browser. |
| 498 ProfileInfoCache& cache = |
| 499 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 500 if (cache.ProfileIsSigninRequiredAtIndex(cache.GetIndexOfProfileWithPath( |
| 501 profile_background_data->first->GetPath()))) |
| 502 return NULL; |
| 503 |
| 504 return profile_background_data->second.get(); |
| 505 } |
| 506 |
| 486 /////////////////////////////////////////////////////////////////////////////// | 507 /////////////////////////////////////////////////////////////////////////////// |
| 487 // BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides | 508 // BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides |
| 488 void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) { | 509 void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) { |
| 489 // When a browser window is necessary, we use the first profile. The windows | 510 BackgroundModeData* bmd = GetBackgroundModeDataForLastProfile(); |
| 490 // opened for these commands are not profile-specific, so any profile would | |
| 491 // work and the first is convenient. | |
| 492 BackgroundModeData* bmd = background_mode_data_.begin()->second.get(); | |
| 493 switch (command_id) { | 511 switch (command_id) { |
| 494 case IDC_ABOUT: | 512 case IDC_ABOUT: |
| 495 chrome::ShowAboutChrome(bmd->GetBrowserWindow()); | 513 if (bmd) |
| 514 chrome::ShowAboutChrome(bmd->GetBrowserWindow()); |
| 515 else |
| 516 chrome::ShowUserManagerThenAboutChrome(); |
| 496 break; | 517 break; |
| 497 case IDC_TASK_MANAGER: | 518 case IDC_TASK_MANAGER: |
| 498 chrome::OpenTaskManager(bmd->GetBrowserWindow()); | 519 if (bmd) |
| 520 chrome::OpenTaskManager(bmd->GetBrowserWindow()); |
| 521 else |
| 522 chrome::ShowUserManagerThenTaskManager(); |
| 499 break; | 523 break; |
| 500 case IDC_EXIT: | 524 case IDC_EXIT: |
| 501 content::RecordAction(UserMetricsAction("Exit")); | 525 content::RecordAction(UserMetricsAction("Exit")); |
| 502 chrome::CloseAllBrowsers(); | 526 chrome::CloseAllBrowsers(); |
| 503 break; | 527 break; |
| 504 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { | 528 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { |
| 505 // Background mode must already be enabled (as otherwise this menu would | 529 // Background mode must already be enabled (as otherwise this menu would |
| 506 // not be visible). | 530 // not be visible). |
| 507 DCHECK(IsBackgroundModePrefEnabled()); | 531 DCHECK(IsBackgroundModePrefEnabled()); |
| 508 DCHECK(chrome::WillKeepAlive()); | 532 DCHECK(chrome::WillKeepAlive()); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 824 } |
| 801 } | 825 } |
| 802 return profile_it; | 826 return profile_it; |
| 803 } | 827 } |
| 804 | 828 |
| 805 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 829 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 806 PrefService* service = g_browser_process->local_state(); | 830 PrefService* service = g_browser_process->local_state(); |
| 807 DCHECK(service); | 831 DCHECK(service); |
| 808 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 832 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 809 } | 833 } |
| OLD | NEW |