| OLD | NEW |
| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (containing_menu) { | 146 if (containing_menu) { |
| 147 int menu_command_id = command_id_extension_vector_->size(); | 147 int menu_command_id = command_id_extension_vector_->size(); |
| 148 // Check that the command ID is within the dynamic range. | 148 // Check that the command ID is within the dynamic range. |
| 149 DCHECK(menu_command_id < IDC_MinimumLabelValue); | 149 DCHECK(menu_command_id < IDC_MinimumLabelValue); |
| 150 command_id_extension_vector_->push_back(kInvalidExtensionIndex); | 150 command_id_extension_vector_->push_back(kInvalidExtensionIndex); |
| 151 containing_menu->AddSubMenu(menu_command_id, name_, menu); | 151 containing_menu->AddSubMenu(menu_command_id, name_, menu); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void BackgroundModeManager::BackgroundModeData::SetName( | 155 void BackgroundModeManager::BackgroundModeData::SetName( |
| 156 const string16& new_profile_name) { | 156 const base::string16& new_profile_name) { |
| 157 name_ = new_profile_name; | 157 name_ = new_profile_name; |
| 158 } | 158 } |
| 159 | 159 |
| 160 string16 BackgroundModeManager::BackgroundModeData::name() { | 160 string16 BackgroundModeManager::BackgroundModeData::name() { |
| 161 return name_; | 161 return name_; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // static | 164 // static |
| 165 bool BackgroundModeManager::BackgroundModeData::BackgroundModeDataCompare( | 165 bool BackgroundModeManager::BackgroundModeData::BackgroundModeDataCompare( |
| 166 const BackgroundModeData* bmd1, | 166 const BackgroundModeData* bmd1, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 void BackgroundModeManager::RegisterProfile(Profile* profile) { | 262 void BackgroundModeManager::RegisterProfile(Profile* profile) { |
| 263 // We don't want to register multiple times for one profile. | 263 // We don't want to register multiple times for one profile. |
| 264 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); | 264 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); |
| 265 BackgroundModeInfo bmd(new BackgroundModeData(profile, | 265 BackgroundModeInfo bmd(new BackgroundModeData(profile, |
| 266 &command_id_extension_vector_)); | 266 &command_id_extension_vector_)); |
| 267 background_mode_data_[profile] = bmd; | 267 background_mode_data_[profile] = bmd; |
| 268 | 268 |
| 269 // Initially set the name for this background mode data. | 269 // Initially set the name for this background mode data. |
| 270 size_t index = profile_cache_->GetIndexOfProfileWithPath(profile->GetPath()); | 270 size_t index = profile_cache_->GetIndexOfProfileWithPath(profile->GetPath()); |
| 271 string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME); | 271 base::string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME); |
| 272 if (index != std::string::npos) | 272 if (index != std::string::npos) |
| 273 name = profile_cache_->GetNameOfProfileAtIndex(index); | 273 name = profile_cache_->GetNameOfProfileAtIndex(index); |
| 274 bmd->SetName(name); | 274 bmd->SetName(name); |
| 275 | 275 |
| 276 // Listen for when extensions are loaded or add the background permission so | 276 // Listen for when extensions are loaded or add the background permission so |
| 277 // we can display a "background app installed" notification and enter | 277 // we can display a "background app installed" notification and enter |
| 278 // "launch on login" mode on the Mac. | 278 // "launch on login" mode on the Mac. |
| 279 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 279 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 280 content::Source<Profile>(profile)); | 280 content::Source<Profile>(profile)); |
| 281 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, | 281 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // List of applications changed so update the UI. | 424 // List of applications changed so update the UI. |
| 425 UpdateStatusTrayIconContextMenu(); | 425 UpdateStatusTrayIconContextMenu(); |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 /////////////////////////////////////////////////////////////////////////////// | 429 /////////////////////////////////////////////////////////////////////////////// |
| 430 // BackgroundModeManager, ProfileInfoCacheObserver overrides | 430 // BackgroundModeManager, ProfileInfoCacheObserver overrides |
| 431 void BackgroundModeManager::OnProfileAdded(const base::FilePath& profile_path) { | 431 void BackgroundModeManager::OnProfileAdded(const base::FilePath& profile_path) { |
| 432 ProfileInfoCache& cache = | 432 ProfileInfoCache& cache = |
| 433 g_browser_process->profile_manager()->GetProfileInfoCache(); | 433 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 434 string16 profile_name = cache.GetNameOfProfileAtIndex( | 434 base::string16 profile_name = cache.GetNameOfProfileAtIndex( |
| 435 cache.GetIndexOfProfileWithPath(profile_path)); | 435 cache.GetIndexOfProfileWithPath(profile_path)); |
| 436 // At this point, the profile should be registered with the background mode | 436 // At this point, the profile should be registered with the background mode |
| 437 // manager, but when it's actually added to the cache is when its name is | 437 // manager, but when it's actually added to the cache is when its name is |
| 438 // set so we need up to update that with the background_mode_data. | 438 // set so we need up to update that with the background_mode_data. |
| 439 for (BackgroundModeInfoMap::const_iterator it = | 439 for (BackgroundModeInfoMap::const_iterator it = |
| 440 background_mode_data_.begin(); | 440 background_mode_data_.begin(); |
| 441 it != background_mode_data_.end(); | 441 it != background_mode_data_.end(); |
| 442 ++it) { | 442 ++it) { |
| 443 if (it->first->GetPath() == profile_path) { | 443 if (it->first->GetPath() == profile_path) { |
| 444 it->second->SetName(profile_name); | 444 it->second->SetName(profile_name); |
| 445 UpdateStatusTrayIconContextMenu(); | 445 UpdateStatusTrayIconContextMenu(); |
| 446 return; | 446 return; |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 void BackgroundModeManager::OnProfileWillBeRemoved( | 451 void BackgroundModeManager::OnProfileWillBeRemoved( |
| 452 const base::FilePath& profile_path) { | 452 const base::FilePath& profile_path) { |
| 453 ProfileInfoCache& cache = | 453 ProfileInfoCache& cache = |
| 454 g_browser_process->profile_manager()->GetProfileInfoCache(); | 454 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 455 string16 profile_name = cache.GetNameOfProfileAtIndex( | 455 base::string16 profile_name = cache.GetNameOfProfileAtIndex( |
| 456 cache.GetIndexOfProfileWithPath(profile_path)); | 456 cache.GetIndexOfProfileWithPath(profile_path)); |
| 457 // Remove the profile from our map of profiles. | 457 // Remove the profile from our map of profiles. |
| 458 BackgroundModeInfoMap::iterator it = | 458 BackgroundModeInfoMap::iterator it = |
| 459 GetBackgroundModeIterator(profile_name); | 459 GetBackgroundModeIterator(profile_name); |
| 460 // If a profile isn't running a background app, it may not be in the map. | 460 // If a profile isn't running a background app, it may not be in the map. |
| 461 if (it != background_mode_data_.end()) { | 461 if (it != background_mode_data_.end()) { |
| 462 background_mode_data_.erase(it); | 462 background_mode_data_.erase(it); |
| 463 UpdateStatusTrayIconContextMenu(); | 463 UpdateStatusTrayIconContextMenu(); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 void BackgroundModeManager::OnProfileNameChanged( | 467 void BackgroundModeManager::OnProfileNameChanged( |
| 468 const base::FilePath& profile_path, | 468 const base::FilePath& profile_path, |
| 469 const string16& old_profile_name) { | 469 const base::string16& old_profile_name) { |
| 470 ProfileInfoCache& cache = | 470 ProfileInfoCache& cache = |
| 471 g_browser_process->profile_manager()->GetProfileInfoCache(); | 471 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 472 string16 new_profile_name = cache.GetNameOfProfileAtIndex( | 472 base::string16 new_profile_name = cache.GetNameOfProfileAtIndex( |
| 473 cache.GetIndexOfProfileWithPath(profile_path)); | 473 cache.GetIndexOfProfileWithPath(profile_path)); |
| 474 BackgroundModeInfoMap::const_iterator it = | 474 BackgroundModeInfoMap::const_iterator it = |
| 475 GetBackgroundModeIterator(old_profile_name); | 475 GetBackgroundModeIterator(old_profile_name); |
| 476 // We check that the returned iterator is valid due to unittests, but really | 476 // We check that the returned iterator is valid due to unittests, but really |
| 477 // this should only be called on profiles already known by the background | 477 // this should only be called on profiles already known by the background |
| 478 // mode manager. | 478 // mode manager. |
| 479 if (it != background_mode_data_.end()) { | 479 if (it != background_mode_data_.end()) { |
| 480 it->second->SetName(new_profile_name); | 480 it->second->SetName(new_profile_name); |
| 481 UpdateStatusTrayIconContextMenu(); | 481 UpdateStatusTrayIconContextMenu(); |
| 482 } | 482 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 } | 796 } |
| 797 | 797 |
| 798 BackgroundModeManager::BackgroundModeData* | 798 BackgroundModeManager::BackgroundModeData* |
| 799 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { | 799 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { |
| 800 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); | 800 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); |
| 801 return background_mode_data_.find(profile)->second.get(); | 801 return background_mode_data_.find(profile)->second.get(); |
| 802 } | 802 } |
| 803 | 803 |
| 804 BackgroundModeManager::BackgroundModeInfoMap::iterator | 804 BackgroundModeManager::BackgroundModeInfoMap::iterator |
| 805 BackgroundModeManager::GetBackgroundModeIterator( | 805 BackgroundModeManager::GetBackgroundModeIterator( |
| 806 const string16& profile_name) { | 806 const base::string16& profile_name) { |
| 807 BackgroundModeInfoMap::iterator profile_it = | 807 BackgroundModeInfoMap::iterator profile_it = |
| 808 background_mode_data_.end(); | 808 background_mode_data_.end(); |
| 809 for (BackgroundModeInfoMap::iterator it = | 809 for (BackgroundModeInfoMap::iterator it = |
| 810 background_mode_data_.begin(); | 810 background_mode_data_.begin(); |
| 811 it != background_mode_data_.end(); | 811 it != background_mode_data_.end(); |
| 812 ++it) { | 812 ++it) { |
| 813 if (it->second->name() == profile_name) { | 813 if (it->second->name() == profile_name) { |
| 814 profile_it = it; | 814 profile_it = it; |
| 815 } | 815 } |
| 816 } | 816 } |
| 817 return profile_it; | 817 return profile_it; |
| 818 } | 818 } |
| 819 | 819 |
| 820 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 820 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 821 PrefService* service = g_browser_process->local_state(); | 821 PrefService* service = g_browser_process->local_state(); |
| 822 DCHECK(service); | 822 DCHECK(service); |
| 823 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 823 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 824 } | 824 } |
| OLD | NEW |