| 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/browser/user_metrics.h" | 30 #include "content/browser/user_metrics.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 378 |
| 378 StartBackgroundMode(); | 379 StartBackgroundMode(); |
| 379 } | 380 } |
| 380 // List of applications changed so update the UI. | 381 // List of applications changed so update the UI. |
| 381 UpdateStatusTrayIconContextMenu(); | 382 UpdateStatusTrayIconContextMenu(); |
| 382 } | 383 } |
| 383 } | 384 } |
| 384 | 385 |
| 385 /////////////////////////////////////////////////////////////////////////////// | 386 /////////////////////////////////////////////////////////////////////////////// |
| 386 // BackgroundModeManager, ProfileInfoCacheObserver overrides | 387 // BackgroundModeManager, ProfileInfoCacheObserver overrides |
| 387 void BackgroundModeManager::OnProfileAdded(const string16& profile_name, | 388 void BackgroundModeManager::OnProfileAdded(const FilePath& profile_path) { |
| 388 const string16& profile_base_dir, | 389 ProfileInfoCache& cache = |
| 389 const FilePath& profile_path, | 390 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 390 const gfx::Image* avatar_image) { | 391 string16 profile_name = cache.GetNameOfProfileAtIndex( |
| 392 cache.GetIndexOfProfileWithPath(profile_path)); |
| 391 // At this point, the profile should be registered with the background mode | 393 // At this point, the profile should be registered with the background mode |
| 392 // manager, but when it's actually added to the cache is when its name is | 394 // manager, but when it's actually added to the cache is when its name is |
| 393 // set so we need up to update that with the background_mode_data. | 395 // set so we need up to update that with the background_mode_data. |
| 394 for (BackgroundModeInfoMap::const_iterator it = | 396 for (BackgroundModeInfoMap::const_iterator it = |
| 395 background_mode_data_.begin(); | 397 background_mode_data_.begin(); |
| 396 it != background_mode_data_.end(); | 398 it != background_mode_data_.end(); |
| 397 ++it) { | 399 ++it) { |
| 398 if (it->first->GetPath() == profile_path) { | 400 if (it->first->GetPath() == profile_path) { |
| 399 it->second->SetName(profile_name); | 401 it->second->SetName(profile_name); |
| 400 UpdateStatusTrayIconContextMenu(); | 402 UpdateStatusTrayIconContextMenu(); |
| 401 return; | 403 return; |
| 402 } | 404 } |
| 403 } | 405 } |
| 404 } | 406 } |
| 405 | 407 |
| 406 void BackgroundModeManager::OnProfileWillBeRemoved( | 408 void BackgroundModeManager::OnProfileWillBeRemoved( |
| 407 const string16& profile_name) { | 409 const FilePath& profile_path) { |
| 410 ProfileInfoCache& cache = |
| 411 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 412 string16 profile_name = cache.GetNameOfProfileAtIndex( |
| 413 cache.GetIndexOfProfileWithPath(profile_path)); |
| 408 // Remove the profile from our map of profiles. | 414 // Remove the profile from our map of profiles. |
| 409 BackgroundModeInfoMap::iterator it = | 415 BackgroundModeInfoMap::iterator it = |
| 410 GetBackgroundModeIterator(profile_name); | 416 GetBackgroundModeIterator(profile_name); |
| 411 // If a profile isn't running a background app, it may not be in the map. | 417 // If a profile isn't running a background app, it may not be in the map. |
| 412 if (it != background_mode_data_.end()) { | 418 if (it != background_mode_data_.end()) { |
| 413 background_mode_data_.erase(it); | 419 background_mode_data_.erase(it); |
| 414 UpdateStatusTrayIconContextMenu(); | 420 UpdateStatusTrayIconContextMenu(); |
| 415 } | 421 } |
| 416 } | 422 } |
| 417 | 423 |
| 418 void BackgroundModeManager::OnProfileWasRemoved(const string16& profile_name) { | 424 void BackgroundModeManager::OnProfileWasRemoved( |
| 425 const FilePath& profile_path, |
| 426 const string16& profile_name) { |
| 419 } | 427 } |
| 420 | 428 |
| 421 void BackgroundModeManager::OnProfileNameChanged( | 429 void BackgroundModeManager::OnProfileNameChanged( |
| 422 const string16& old_profile_name, | 430 const FilePath& profile_path, |
| 423 const string16& new_profile_name) { | 431 const string16& old_profile_name) { |
| 432 ProfileInfoCache& cache = |
| 433 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 434 string16 new_profile_name = cache.GetNameOfProfileAtIndex( |
| 435 cache.GetIndexOfProfileWithPath(profile_path)); |
| 424 BackgroundModeInfoMap::const_iterator it = | 436 BackgroundModeInfoMap::const_iterator it = |
| 425 GetBackgroundModeIterator(old_profile_name); | 437 GetBackgroundModeIterator(old_profile_name); |
| 426 // We check that the returned iterator is valid due to unittests, but really | 438 // We check that the returned iterator is valid due to unittests, but really |
| 427 // this should only be called on profiles already known by the background | 439 // this should only be called on profiles already known by the background |
| 428 // mode manager. | 440 // mode manager. |
| 429 if (it != background_mode_data_.end()) { | 441 if (it != background_mode_data_.end()) { |
| 430 it->second->SetName(new_profile_name); | 442 it->second->SetName(new_profile_name); |
| 431 UpdateStatusTrayIconContextMenu(); | 443 UpdateStatusTrayIconContextMenu(); |
| 432 } | 444 } |
| 433 } | 445 } |
| 434 | 446 |
| 435 void BackgroundModeManager::OnProfileAvatarChanged( | 447 void BackgroundModeManager::OnProfileAvatarChanged( |
| 436 const string16& profile_name, | 448 const FilePath& profile_path) { |
| 437 const string16& profile_base_dir, | |
| 438 const FilePath& profile_path, | |
| 439 const gfx::Image* avatar_image) { | |
| 440 | 449 |
| 441 } | 450 } |
| 442 /////////////////////////////////////////////////////////////////////////////// | 451 /////////////////////////////////////////////////////////////////////////////// |
| 443 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides | 452 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides |
| 444 bool BackgroundModeManager::IsCommandIdChecked( | 453 bool BackgroundModeManager::IsCommandIdChecked( |
| 445 int command_id) const { | 454 int command_id) const { |
| 446 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); | 455 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); |
| 447 return true; | 456 return true; |
| 448 } | 457 } |
| 449 | 458 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 command_line->HasSwitch(switches::kDisableExtensions); | 751 command_line->HasSwitch(switches::kDisableExtensions); |
| 743 return background_mode_disabled; | 752 return background_mode_disabled; |
| 744 #endif | 753 #endif |
| 745 } | 754 } |
| 746 | 755 |
| 747 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 756 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 748 PrefService* service = g_browser_process->local_state(); | 757 PrefService* service = g_browser_process->local_state(); |
| 749 DCHECK(service); | 758 DCHECK(service); |
| 750 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 759 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 751 } | 760 } |
| OLD | NEW |