| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/background/background_application_list_model.h" | 13 #include "chrome/browser/background/background_application_list_model.h" |
| 14 #include "chrome/browser/background/background_mode_manager.h" | 14 #include "chrome/browser/background/background_mode_manager.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/status_icons/status_icon.h" | 21 #include "chrome/browser/status_icons/status_icon.h" |
| 21 #include "chrome/browser/status_icons/status_tray.h" | 22 #include "chrome/browser/status_icons/status_tray.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 380 |
| 380 StartBackgroundMode(); | 381 StartBackgroundMode(); |
| 381 } | 382 } |
| 382 // List of applications changed so update the UI. | 383 // List of applications changed so update the UI. |
| 383 UpdateStatusTrayIconContextMenu(); | 384 UpdateStatusTrayIconContextMenu(); |
| 384 } | 385 } |
| 385 } | 386 } |
| 386 | 387 |
| 387 /////////////////////////////////////////////////////////////////////////////// | 388 /////////////////////////////////////////////////////////////////////////////// |
| 388 // BackgroundModeManager, ProfileInfoCacheObserver overrides | 389 // BackgroundModeManager, ProfileInfoCacheObserver overrides |
| 389 void BackgroundModeManager::OnProfileAdded(const string16& profile_name, | 390 void BackgroundModeManager::OnProfileAdded(const FilePath& profile_path, |
| 390 const string16& profile_base_dir, | 391 const string16& profile_base_dir) { |
| 391 const FilePath& profile_path, | 392 ProfileInfoCache& cache = |
| 392 const gfx::Image* avatar_image) { | 393 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 394 string16 profile_name = cache.GetNameOfProfileAtIndex( |
| 395 cache.GetIndexOfProfileWithPath(profile_path)); |
| 393 // At this point, the profile should be registered with the background mode | 396 // At this point, the profile should be registered with the background mode |
| 394 // manager, but when it's actually added to the cache is when its name is | 397 // manager, but when it's actually added to the cache is when its name is |
| 395 // set so we need up to update that with the background_mode_data. | 398 // set so we need up to update that with the background_mode_data. |
| 396 for (BackgroundModeInfoMap::const_iterator it = | 399 for (BackgroundModeInfoMap::const_iterator it = |
| 397 background_mode_data_.begin(); | 400 background_mode_data_.begin(); |
| 398 it != background_mode_data_.end(); | 401 it != background_mode_data_.end(); |
| 399 ++it) { | 402 ++it) { |
| 400 if (it->first->GetPath() == profile_path) { | 403 if (it->first->GetPath() == profile_path) { |
| 401 it->second->SetName(profile_name); | 404 it->second->SetName(profile_name); |
| 402 UpdateStatusTrayIconContextMenu(); | 405 UpdateStatusTrayIconContextMenu(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 428 // We check that the returned iterator is valid due to unittests, but really | 431 // We check that the returned iterator is valid due to unittests, but really |
| 429 // this should only be called on profiles already known by the background | 432 // this should only be called on profiles already known by the background |
| 430 // mode manager. | 433 // mode manager. |
| 431 if (it != background_mode_data_.end()) { | 434 if (it != background_mode_data_.end()) { |
| 432 it->second->SetName(new_profile_name); | 435 it->second->SetName(new_profile_name); |
| 433 UpdateStatusTrayIconContextMenu(); | 436 UpdateStatusTrayIconContextMenu(); |
| 434 } | 437 } |
| 435 } | 438 } |
| 436 | 439 |
| 437 void BackgroundModeManager::OnProfileAvatarChanged( | 440 void BackgroundModeManager::OnProfileAvatarChanged( |
| 438 const string16& profile_name, | |
| 439 const string16& profile_base_dir, | |
| 440 const FilePath& profile_path, | 441 const FilePath& profile_path, |
| 441 const gfx::Image* avatar_image) { | 442 const string16& profile_base_dir) { |
| 442 | 443 |
| 443 } | 444 } |
| 444 /////////////////////////////////////////////////////////////////////////////// | 445 /////////////////////////////////////////////////////////////////////////////// |
| 445 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides | 446 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides |
| 446 bool BackgroundModeManager::IsCommandIdChecked( | 447 bool BackgroundModeManager::IsCommandIdChecked( |
| 447 int command_id) const { | 448 int command_id) const { |
| 448 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); | 449 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); |
| 449 return true; | 450 return true; |
| 450 } | 451 } |
| 451 | 452 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 command_line->HasSwitch(switches::kDisableExtensions); | 745 command_line->HasSwitch(switches::kDisableExtensions); |
| 745 return background_mode_disabled; | 746 return background_mode_disabled; |
| 746 #endif | 747 #endif |
| 747 } | 748 } |
| 748 | 749 |
| 749 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 750 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 750 PrefService* service = g_browser_process->local_state(); | 751 PrefService* service = g_browser_process->local_state(); |
| 751 DCHECK(service); | 752 DCHECK(service); |
| 752 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 753 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 753 } | 754 } |
| OLD | NEW |