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

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: Rebase continued Created 6 years, 2 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"
37 #include "chrome/browser/ui/user_manager.h"
36 #include "chrome/common/chrome_constants.h" 38 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/extensions/extension_constants.h" 40 #include "chrome/common/extensions/extension_constants.h"
39 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
40 #include "chrome/grit/chromium_strings.h" 42 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 43 #include "chrome/grit/generated_resources.h"
42 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/user_metrics.h" 45 #include "content/public/browser/user_metrics.h"
44 #include "extensions/browser/extension_system.h" 46 #include "extensions/browser/extension_system.h"
45 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 GetBackgroundModeIterator(old_profile_name); 478 GetBackgroundModeIterator(old_profile_name);
477 // We check that the returned iterator is valid due to unittests, but really 479 // 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 480 // this should only be called on profiles already known by the background
479 // mode manager. 481 // mode manager.
480 if (it != background_mode_data_.end()) { 482 if (it != background_mode_data_.end()) {
481 it->second->SetName(new_profile_name); 483 it->second->SetName(new_profile_name);
482 UpdateStatusTrayIconContextMenu(); 484 UpdateStatusTrayIconContextMenu();
483 } 485 }
484 } 486 }
485 487
488 BackgroundModeManager::BackgroundModeData*
489 BackgroundModeManager::GetBackgroundModeDataForLastProfile() const {
490 Profile* most_recent_profile = g_browser_process->profile_manager()->
491 GetLastUsedProfileAllowedByPolicy();
492 BackgroundModeInfoMap::const_iterator profile_background_data =
493 background_mode_data_.find(most_recent_profile);
494
495 if (profile_background_data == background_mode_data_.end())
496 return NULL;
497
498 // Do not permit a locked profile to be used to open a browser.
499 ProfileInfoCache& cache =
500 g_browser_process->profile_manager()->GetProfileInfoCache();
501 if (cache.ProfileIsSigninRequiredAtIndex(cache.GetIndexOfProfileWithPath(
502 profile_background_data->first->GetPath())))
503 return NULL;
504
505 return profile_background_data->second.get();
506 }
507
486 /////////////////////////////////////////////////////////////////////////////// 508 ///////////////////////////////////////////////////////////////////////////////
487 // BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides 509 // BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides
488 void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) { 510 void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) {
489 // When a browser window is necessary, we use the first profile. The windows 511 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) { 512 switch (command_id) {
494 case IDC_ABOUT: 513 case IDC_ABOUT:
495 chrome::ShowAboutChrome(bmd->GetBrowserWindow()); 514 if (bmd) {
515 chrome::ShowAboutChrome(bmd->GetBrowserWindow());
516 } else {
517 UserManager::Show(base::FilePath(),
518 profiles::USER_MANAGER_NO_TUTORIAL,
519 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME);
520 }
496 break; 521 break;
497 case IDC_TASK_MANAGER: 522 case IDC_TASK_MANAGER:
498 chrome::OpenTaskManager(bmd->GetBrowserWindow()); 523 if (bmd) {
524 chrome::OpenTaskManager(bmd->GetBrowserWindow());
525 } else {
526 UserManager::Show(base::FilePath(),
527 profiles::USER_MANAGER_NO_TUTORIAL,
528 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER);
529 }
499 break; 530 break;
500 case IDC_EXIT: 531 case IDC_EXIT:
501 content::RecordAction(UserMetricsAction("Exit")); 532 content::RecordAction(UserMetricsAction("Exit"));
502 chrome::CloseAllBrowsers(); 533 chrome::CloseAllBrowsers();
503 break; 534 break;
504 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { 535 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: {
505 // Background mode must already be enabled (as otherwise this menu would 536 // Background mode must already be enabled (as otherwise this menu would
506 // not be visible). 537 // not be visible).
507 DCHECK(IsBackgroundModePrefEnabled()); 538 DCHECK(IsBackgroundModePrefEnabled());
508 DCHECK(chrome::WillKeepAlive()); 539 DCHECK(chrome::WillKeepAlive());
509 540
510 // Set the background mode pref to "disabled" - the resulting notification 541 // Set the background mode pref to "disabled" - the resulting notification
511 // will result in a call to DisableBackgroundMode(). 542 // will result in a call to DisableBackgroundMode().
512 PrefService* service = g_browser_process->local_state(); 543 PrefService* service = g_browser_process->local_state();
513 DCHECK(service); 544 DCHECK(service);
514 service->SetBoolean(prefs::kBackgroundModeEnabled, false); 545 service->SetBoolean(prefs::kBackgroundModeEnabled, false);
515 break; 546 break;
516 } 547 }
517 default: 548 default:
518 bmd->ExecuteCommand(command_id, event_flags); 549 if (bmd) {
550 bmd->ExecuteCommand(command_id, event_flags);
551 } else {
552 UserManager::Show(base::FilePath(),
553 profiles::USER_MANAGER_NO_TUTORIAL,
554 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
555 }
519 break; 556 break;
520 } 557 }
521 } 558 }
522 559
523 560
524 /////////////////////////////////////////////////////////////////////////////// 561 ///////////////////////////////////////////////////////////////////////////////
525 // BackgroundModeManager, private 562 // BackgroundModeManager, private
526 void BackgroundModeManager::DecrementKeepAliveCountForStartup() { 563 void BackgroundModeManager::DecrementKeepAliveCountForStartup() {
527 if (keep_alive_for_startup_) { 564 if (keep_alive_for_startup_) {
528 keep_alive_for_startup_ = false; 565 keep_alive_for_startup_ = false;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 837 }
801 } 838 }
802 return profile_it; 839 return profile_it;
803 } 840 }
804 841
805 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { 842 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const {
806 PrefService* service = g_browser_process->local_state(); 843 PrefService* service = g_browser_process->local_state();
807 DCHECK(service); 844 DCHECK(service);
808 return service->GetBoolean(prefs::kBackgroundModeEnabled); 845 return service->GetBoolean(prefs::kBackgroundModeEnabled);
809 } 846 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager.h ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698