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

Side by Side Diff: chrome/browser/background/background_mode_manager.cc

Issue 564453003: Access to Chrome via the System Tray should go through the User Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: string16->string. Simplify OnbrowserWindowReady. Created 6 years, 3 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
OLDNEW
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
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/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "chrome/grit/chromium_strings.h" 41 #include "chrome/grit/chromium_strings.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
509 533
510 // Set the background mode pref to "disabled" - the resulting notification 534 // Set the background mode pref to "disabled" - the resulting notification
511 // will result in a call to DisableBackgroundMode(). 535 // will result in a call to DisableBackgroundMode().
512 PrefService* service = g_browser_process->local_state(); 536 PrefService* service = g_browser_process->local_state();
513 DCHECK(service); 537 DCHECK(service);
514 service->SetBoolean(prefs::kBackgroundModeEnabled, false); 538 service->SetBoolean(prefs::kBackgroundModeEnabled, false);
515 break; 539 break;
516 } 540 }
517 default: 541 default:
518 bmd->ExecuteCommand(command_id, event_flags); 542 bmd->ExecuteCommand(command_id, event_flags);
Andrew T Wilson (Slow) 2014/09/15 13:59:21 What happens here (i.e. if you click on a backgrou
Mike Lerman 2014/09/15 16:43:11 It will! Excellent point, good sir.
519 break; 543 break;
520 } 544 }
521 } 545 }
522 546
523 547
524 /////////////////////////////////////////////////////////////////////////////// 548 ///////////////////////////////////////////////////////////////////////////////
525 // BackgroundModeManager, private 549 // BackgroundModeManager, private
526 void BackgroundModeManager::DecrementKeepAliveCountForStartup() { 550 void BackgroundModeManager::DecrementKeepAliveCountForStartup() {
527 if (keep_alive_for_startup_) { 551 if (keep_alive_for_startup_) {
528 keep_alive_for_startup_ = false; 552 keep_alive_for_startup_ = false;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager.h ('k') | chrome/browser/profiles/avatar_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698