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