Chromium Code Reviews| 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" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 32 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 34 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 37 | 37 |
| 38 BackgroundModeManager::BackgroundModeData::BackgroundModeData( | 38 BackgroundModeManager::BackgroundModeData::BackgroundModeData( |
| 39 int command_id, | 39 int command_id, |
| 40 Profile* profile, | 40 Profile* profile) |
| 41 BackgroundModeManager* background_mode_manager) | |
| 42 : applications_(new BackgroundApplicationListModel(profile)), | 41 : applications_(new BackgroundApplicationListModel(profile)), |
| 43 command_id_(command_id), | 42 command_id_(command_id), |
| 44 profile_(profile), | 43 profile_(profile) { |
| 45 background_mode_manager_(background_mode_manager) { | |
| 46 name_ = UTF8ToUTF16(profile_->GetProfileName()); | |
| 47 if (name_.empty()) | |
| 48 name_ = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME); | |
| 49 } | 44 } |
| 50 | 45 |
| 51 BackgroundModeManager::BackgroundModeData::~BackgroundModeData() { | 46 BackgroundModeManager::BackgroundModeData::~BackgroundModeData() { |
| 52 } | 47 } |
| 53 | 48 |
| 54 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
| 55 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides | 50 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides |
| 56 bool BackgroundModeManager::BackgroundModeData::IsCommandIdChecked( | 51 bool BackgroundModeManager::BackgroundModeData::IsCommandIdChecked( |
| 57 int command_id) const { | 52 int command_id) const { |
| 58 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); | 53 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 const std::string& name = (*cursor)->name(); | 109 const std::string& name = (*cursor)->name(); |
| 115 menu->AddItem(position, UTF8ToUTF16(name)); | 110 menu->AddItem(position, UTF8ToUTF16(name)); |
| 116 if (icon) | 111 if (icon) |
| 117 menu->SetIcon(menu->GetItemCount() - 1, *icon); | 112 menu->SetIcon(menu->GetItemCount() - 1, *icon); |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 if (containing_menu) | 115 if (containing_menu) |
| 121 containing_menu->AddSubMenu(command_id_, name_, menu); | 116 containing_menu->AddSubMenu(command_id_, name_, menu); |
| 122 } | 117 } |
| 123 | 118 |
| 119 void BackgroundModeManager::BackgroundModeData::SetName( | |
| 120 const string16& new_profile_name) { | |
| 121 name_ = new_profile_name; | |
| 122 } | |
| 123 | |
| 124 string16 BackgroundModeManager::BackgroundModeData::name() { | |
| 125 return name_; | |
| 126 } | |
| 127 | |
| 124 // static | 128 // static |
| 125 bool BackgroundModeManager::BackgroundModeData::BackgroundModeDataCompare( | 129 bool BackgroundModeManager::BackgroundModeData::BackgroundModeDataCompare( |
| 126 const BackgroundModeData* bmd1, | 130 const BackgroundModeData* bmd1, |
| 127 const BackgroundModeData* bmd2) { | 131 const BackgroundModeData* bmd2) { |
| 128 return bmd1->name_ < bmd2->name_; | 132 return bmd1->name_ < bmd2->name_; |
| 129 } | 133 } |
| 130 | 134 |
| 131 | 135 |
| 132 /////////////////////////////////////////////////////////////////////////////// | 136 /////////////////////////////////////////////////////////////////////////////// |
| 133 // BackgroundModeManager, public | 137 // BackgroundModeManager, public |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 144 current_command_id_(0) { | 148 current_command_id_(0) { |
| 145 // We should never start up if there is no browser process or if we are | 149 // We should never start up if there is no browser process or if we are |
| 146 // currently quitting. | 150 // currently quitting. |
| 147 CHECK(g_browser_process != NULL); | 151 CHECK(g_browser_process != NULL); |
| 148 CHECK(!browser_shutdown::IsTryingToQuit()); | 152 CHECK(!browser_shutdown::IsTryingToQuit()); |
| 149 // If background mode is currently disabled, just exit - don't listen for any | 153 // If background mode is currently disabled, just exit - don't listen for any |
| 150 // notifications. | 154 // notifications. |
| 151 if (IsBackgroundModePermanentlyDisabled(command_line)) | 155 if (IsBackgroundModePermanentlyDisabled(command_line)) |
| 152 return; | 156 return; |
| 153 | 157 |
| 158 // Add self as an observer for the profile info cache so we know when profiles | |
| 159 // are deleted and their names change. | |
| 160 profile_cache_->AddObserver(this); | |
| 161 | |
| 154 // Listen for the background mode preference changing. | 162 // Listen for the background mode preference changing. |
| 155 if (g_browser_process->local_state()) { // Skip for unit tests | 163 if (g_browser_process->local_state()) { // Skip for unit tests |
| 156 pref_registrar_.Init(g_browser_process->local_state()); | 164 pref_registrar_.Init(g_browser_process->local_state()); |
| 157 pref_registrar_.Add(prefs::kBackgroundModeEnabled, this); | 165 pref_registrar_.Add(prefs::kBackgroundModeEnabled, this); |
| 158 } | 166 } |
| 159 | 167 |
| 160 // Keep the browser alive until extensions are done loading - this is needed | 168 // Keep the browser alive until extensions are done loading - this is needed |
| 161 // by the --no-startup-window flag. We want to stay alive until we load | 169 // by the --no-startup-window flag. We want to stay alive until we load |
| 162 // extensions, at which point we should either run in background mode (if | 170 // extensions, at which point we should either run in background mode (if |
| 163 // there are background apps) or exit if there are none. | 171 // there are background apps) or exit if there are none. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 176 | 184 |
| 177 // Listen for the application shutting down so we can decrement our KeepAlive | 185 // Listen for the application shutting down so we can decrement our KeepAlive |
| 178 // count. | 186 // count. |
| 179 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 187 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 180 content::NotificationService::AllSources()); | 188 content::NotificationService::AllSources()); |
| 181 } | 189 } |
| 182 | 190 |
| 183 BackgroundModeManager::~BackgroundModeManager() { | 191 BackgroundModeManager::~BackgroundModeManager() { |
| 184 // Remove ourselves from the application observer list (only needed by unit | 192 // Remove ourselves from the application observer list (only needed by unit |
| 185 // tests since APP_TERMINATING is what does this in a real running system). | 193 // tests since APP_TERMINATING is what does this in a real running system). |
| 186 for (std::map<Profile*, BackgroundModeInfo>::iterator it = | 194 for (BackgroundModeInfoMap::iterator it = |
| 187 background_mode_data_.begin(); | 195 background_mode_data_.begin(); |
| 188 it != background_mode_data_.end(); | 196 it != background_mode_data_.end(); |
| 189 ++it) { | 197 ++it) { |
| 190 it->second->applications_->RemoveObserver(this); | 198 it->second->applications_->RemoveObserver(this); |
| 191 } | 199 } |
| 192 | 200 |
| 193 // We're going away, so exit background mode (does nothing if we aren't in | 201 // We're going away, so exit background mode (does nothing if we aren't in |
| 194 // background mode currently). This is primarily needed for unit tests, | 202 // background mode currently). This is primarily needed for unit tests, |
| 195 // because in an actual running system we'd get an APP_TERMINATING | 203 // because in an actual running system we'd get an APP_TERMINATING |
| 196 // notification before being destroyed. | 204 // notification before being destroyed. |
| 197 EndBackgroundMode(); | 205 EndBackgroundMode(); |
| 198 } | 206 } |
| 199 | 207 |
| 200 // static | 208 // static |
| 201 void BackgroundModeManager::RegisterPrefs(PrefService* prefs) { | 209 void BackgroundModeManager::RegisterPrefs(PrefService* prefs) { |
| 202 prefs->RegisterBooleanPref(prefs::kUserCreatedLoginItem, false); | 210 prefs->RegisterBooleanPref(prefs::kUserCreatedLoginItem, false); |
| 203 prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); | 211 prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); |
| 204 } | 212 } |
| 205 | 213 |
| 206 | 214 |
| 207 void BackgroundModeManager::RegisterProfile(Profile* profile) { | 215 void BackgroundModeManager::RegisterProfile(Profile* profile) { |
| 208 // We don't want to register multiple times for one profile. | 216 // We don't want to register multiple times for one profile. |
| 209 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); | 217 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); |
| 210 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, | 218 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, |
| 211 profile, this)); | 219 profile)); |
| 212 background_mode_data_[profile] = bmd; | 220 background_mode_data_[profile] = bmd; |
| 213 | 221 |
| 222 // Initially set the name for this background mode data. | |
| 223 size_t index = profile_cache_->GetIndexOfProfileWithPath(profile->GetPath()); | |
| 224 string16 name = l10n_util::GetStringUTF16(IDS_PROFILES_DEFAULT_NAME); | |
| 225 if (index != std::string::npos) | |
| 226 name = profile_cache_->GetNameOfProfileAtIndex(index); | |
| 227 bmd->SetName(name); | |
| 228 | |
| 214 // Listen for when extensions are loaded or add the background permission so | 229 // Listen for when extensions are loaded or add the background permission so |
| 215 // we can display a "background app installed" notification and enter | 230 // we can display a "background app installed" notification and enter |
| 216 // "launch on login" mode on the Mac. | 231 // "launch on login" mode on the Mac. |
| 217 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 232 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 218 content::Source<Profile>(profile)); | 233 content::Source<Profile>(profile)); |
| 219 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, | 234 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, |
| 220 content::Source<Profile>(profile)); | 235 content::Source<Profile>(profile)); |
| 221 | 236 |
| 222 | 237 |
| 223 // Check for the presence of background apps after all extensions have been | 238 // Check for the presence of background apps after all extensions have been |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 239 Profile* profile, | 254 Profile* profile, |
| 240 const Extension* extension) { | 255 const Extension* extension) { |
| 241 ExtensionService* service = profile->GetExtensionService(); | 256 ExtensionService* service = profile->GetExtensionService(); |
| 242 extension_misc::LaunchContainer launch_container = | 257 extension_misc::LaunchContainer launch_container = |
| 243 service->extension_prefs()->GetLaunchContainer( | 258 service->extension_prefs()->GetLaunchContainer( |
| 244 extension, ExtensionPrefs::LAUNCH_REGULAR); | 259 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 245 Browser::OpenApplication(profile, extension, launch_container, GURL(), | 260 Browser::OpenApplication(profile, extension, launch_container, GURL(), |
| 246 NEW_FOREGROUND_TAB); | 261 NEW_FOREGROUND_TAB); |
| 247 } | 262 } |
| 248 | 263 |
| 264 int BackgroundModeManager::NumberOfBackgroundModeData() { | |
| 265 return background_mode_data_.size(); | |
| 266 } | |
| 267 | |
| 268 string16 BackgroundModeManager::BackgroundModeDataName(Profile* profile) { | |
| 269 return background_mode_data_[profile]->name(); | |
|
Andrew T Wilson (Slow)
2011/12/06 06:46:02
Perhaps we should add a DCHECK(background_mode_dat
rpetterson
2011/12/06 20:09:05
Function removed.
| |
| 270 } | |
| 271 | |
| 272 | |
| 249 /////////////////////////////////////////////////////////////////////////////// | 273 /////////////////////////////////////////////////////////////////////////////// |
| 250 // BackgroundModeManager, content::NotificationObserver overrides | 274 // BackgroundModeManager, content::NotificationObserver overrides |
| 251 void BackgroundModeManager::Observe( | 275 void BackgroundModeManager::Observe( |
| 252 int type, | 276 int type, |
| 253 const content::NotificationSource& source, | 277 const content::NotificationSource& source, |
| 254 const content::NotificationDetails& details) { | 278 const content::NotificationDetails& details) { |
| 255 switch (type) { | 279 switch (type) { |
| 256 case chrome::NOTIFICATION_PREF_CHANGED: | 280 case chrome::NOTIFICATION_PREF_CHANGED: |
| 257 DCHECK(*content::Details<std::string>(details).ptr() == | 281 DCHECK(*content::Details<std::string>(details).ptr() == |
| 258 prefs::kBackgroundModeEnabled); | 282 prefs::kBackgroundModeEnabled); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 case content::NOTIFICATION_APP_TERMINATING: | 316 case content::NOTIFICATION_APP_TERMINATING: |
| 293 // Make sure we aren't still keeping the app alive (only happens if we | 317 // Make sure we aren't still keeping the app alive (only happens if we |
| 294 // don't receive an EXTENSIONS_READY notification for some reason). | 318 // don't receive an EXTENSIONS_READY notification for some reason). |
| 295 EndKeepAliveForStartup(); | 319 EndKeepAliveForStartup(); |
| 296 // Performing an explicit shutdown, so exit background mode (does nothing | 320 // Performing an explicit shutdown, so exit background mode (does nothing |
| 297 // if we aren't in background mode currently). | 321 // if we aren't in background mode currently). |
| 298 EndBackgroundMode(); | 322 EndBackgroundMode(); |
| 299 // Shutting down, so don't listen for any more notifications so we don't | 323 // Shutting down, so don't listen for any more notifications so we don't |
| 300 // try to re-enter/exit background mode again. | 324 // try to re-enter/exit background mode again. |
| 301 registrar_.RemoveAll(); | 325 registrar_.RemoveAll(); |
| 302 for (std::map<Profile*, BackgroundModeInfo>::iterator it = | 326 for (BackgroundModeInfoMap::iterator it = |
| 303 background_mode_data_.begin(); | 327 background_mode_data_.begin(); |
| 304 it != background_mode_data_.end(); | 328 it != background_mode_data_.end(); |
| 305 ++it) { | 329 ++it) { |
| 306 it->second->applications_->RemoveObserver(this); | 330 it->second->applications_->RemoveObserver(this); |
| 307 } | 331 } |
| 308 break; | 332 break; |
| 309 default: | 333 default: |
| 310 NOTREACHED(); | 334 NOTREACHED(); |
| 311 break; | 335 break; |
| 312 } | 336 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 #endif | 381 #endif |
| 358 | 382 |
| 359 StartBackgroundMode(); | 383 StartBackgroundMode(); |
| 360 } | 384 } |
| 361 // List of applications changed so update the UI. | 385 // List of applications changed so update the UI. |
| 362 UpdateStatusTrayIconContextMenu(); | 386 UpdateStatusTrayIconContextMenu(); |
| 363 } | 387 } |
| 364 } | 388 } |
| 365 | 389 |
| 366 /////////////////////////////////////////////////////////////////////////////// | 390 /////////////////////////////////////////////////////////////////////////////// |
| 391 // BackgroundModeManager, ProfileInfoCacheObserver overrides | |
| 392 void BackgroundModeManager::OnProfileAdded(const string16& profile_name, | |
| 393 const string16& profile_base_dir) { | |
| 394 // At this point, the profile should be registered with the background mode | |
| 395 // manager, but when it's actually added to the cache is when its name is | |
| 396 // set so we need up to update that with the background_mode_data. | |
| 397 for (BackgroundModeInfoMap::const_iterator it = | |
| 398 background_mode_data_.begin(); | |
| 399 it != background_mode_data_.end(); | |
| 400 ++it) { | |
| 401 if (it->first->GetPath().BaseName().LossyDisplayName() == | |
| 402 profile_base_dir) { | |
| 403 it->second->SetName(profile_name); | |
| 404 UpdateStatusTrayIconContextMenu(); | |
|
Andrew T Wilson (Slow)
2011/12/06 06:46:02
Should we break out of the loop here/early return?
rpetterson
2011/12/06 20:09:05
Done.
| |
| 405 } | |
| 406 } | |
| 407 } | |
| 408 | |
| 409 void BackgroundModeManager::OnProfileRemoved(const string16& profile_name) { | |
| 410 // Remove the profile from our map of profiles | |
|
Andrew T Wilson (Slow)
2011/12/06 06:46:02
nit: period at the end of the comment.
rpetterson
2011/12/06 20:09:05
Done.
| |
| 411 BackgroundModeInfoMap::iterator it = | |
| 412 GetBackgroundModeIterator(profile_name); | |
| 413 // If a profile isn't running a background app, it may not be in the map | |
|
Andrew T Wilson (Slow)
2011/12/06 06:46:02
nit: period at end of comment
rpetterson
2011/12/06 20:09:05
Done.
| |
| 414 if (it != background_mode_data_.end()) { | |
| 415 background_mode_data_.erase(it); | |
| 416 UpdateStatusTrayIconContextMenu(); | |
| 417 } | |
| 418 } | |
| 419 | |
| 420 void BackgroundModeManager::OnProfileNameChanged( | |
| 421 const string16& old_profile_name, | |
| 422 const string16& new_profile_name) { | |
| 423 BackgroundModeInfoMap::const_iterator it = | |
| 424 GetBackgroundModeIterator(old_profile_name); | |
| 425 // We check for if due to unittests, but really this should only be called on | |
|
Andrew T Wilson (Slow)
2011/12/06 06:46:02
nit: "We check for if" - did you omit a word here?
rpetterson
2011/12/06 20:09:05
Done.
| |
| 426 // profiles already known by the background mode manager. | |
| 427 if (it != background_mode_data_.end()) { | |
| 428 it->second->SetName(new_profile_name); | |
| 429 UpdateStatusTrayIconContextMenu(); | |
| 430 } | |
| 431 } | |
| 432 | |
| 433 /////////////////////////////////////////////////////////////////////////////// | |
| 367 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides | 434 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides |
| 368 bool BackgroundModeManager::IsCommandIdChecked( | 435 bool BackgroundModeManager::IsCommandIdChecked( |
| 369 int command_id) const { | 436 int command_id) const { |
| 370 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); | 437 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); |
| 371 return true; | 438 return true; |
| 372 } | 439 } |
| 373 | 440 |
| 374 bool BackgroundModeManager::IsCommandIdEnabled( | 441 bool BackgroundModeManager::IsCommandIdEnabled( |
| 375 int command_id) const { | 442 int command_id) const { |
| 376 return command_id != IDC_MinimumLabelValue; | 443 return command_id != IDC_MinimumLabelValue; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 // If background mode is currently enabled, turn it off. | 549 // If background mode is currently enabled, turn it off. |
| 483 if (in_background_mode_) { | 550 if (in_background_mode_) { |
| 484 EndBackgroundMode(); | 551 EndBackgroundMode(); |
| 485 EnableLaunchOnStartup(false); | 552 EnableLaunchOnStartup(false); |
| 486 } | 553 } |
| 487 } | 554 } |
| 488 | 555 |
| 489 int BackgroundModeManager::GetBackgroundAppCount() const { | 556 int BackgroundModeManager::GetBackgroundAppCount() const { |
| 490 int count = 0; | 557 int count = 0; |
| 491 // Walk the BackgroundModeData for all profiles and count the number of apps. | 558 // Walk the BackgroundModeData for all profiles and count the number of apps. |
| 492 for (std::map<Profile*, BackgroundModeInfo>::const_iterator it = | 559 for (BackgroundModeInfoMap::const_iterator it = |
| 493 background_mode_data_.begin(); | 560 background_mode_data_.begin(); |
| 494 it != background_mode_data_.end(); | 561 it != background_mode_data_.end(); |
| 495 ++it) { | 562 ++it) { |
| 496 count += it->second->GetBackgroundAppCount(); | 563 count += it->second->GetBackgroundAppCount(); |
| 497 } | 564 } |
| 498 DCHECK(count >= 0); | 565 DCHECK(count >= 0); |
| 499 return count; | 566 return count; |
| 500 } | 567 } |
| 501 | 568 |
| 502 int BackgroundModeManager::GetBackgroundAppCountForProfile( | 569 int BackgroundModeManager::GetBackgroundAppCountForProfile( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 // Create a context menu item for Chrome. | 648 // Create a context menu item for Chrome. |
| 582 ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); | 649 ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); |
| 583 // Add About item | 650 // Add About item |
| 584 menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, | 651 menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, |
| 585 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 652 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 586 menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 653 menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 587 menu->AddSeparator(); | 654 menu->AddSeparator(); |
| 588 | 655 |
| 589 if (background_mode_data_.size() > 1) { | 656 if (background_mode_data_.size() > 1) { |
| 590 std::vector<BackgroundModeData*> bmd_vector; | 657 std::vector<BackgroundModeData*> bmd_vector; |
| 591 for (std::map<Profile*, BackgroundModeInfo>::iterator it = | 658 for (BackgroundModeInfoMap::iterator it = |
| 592 background_mode_data_.begin(); | 659 background_mode_data_.begin(); |
| 593 it != background_mode_data_.end(); | 660 it != background_mode_data_.end(); |
| 594 ++it) { | 661 ++it) { |
| 595 bmd_vector.push_back(it->second.get()); | 662 bmd_vector.push_back(it->second.get()); |
| 596 } | 663 } |
| 597 std::sort(bmd_vector.begin(), bmd_vector.end(), | 664 std::sort(bmd_vector.begin(), bmd_vector.end(), |
| 598 &BackgroundModeData::BackgroundModeDataCompare); | 665 &BackgroundModeData::BackgroundModeDataCompare); |
| 599 for (std::vector<BackgroundModeData*>::const_iterator bmd_it = | 666 for (std::vector<BackgroundModeData*>::const_iterator bmd_it = |
| 600 bmd_vector.begin(); | 667 bmd_vector.begin(); |
| 601 bmd_it != bmd_vector.end(); | 668 bmd_it != bmd_vector.end(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 625 status_icon_ = NULL; | 692 status_icon_ = NULL; |
| 626 context_menu_ = NULL; | 693 context_menu_ = NULL; |
| 627 } | 694 } |
| 628 | 695 |
| 629 BackgroundModeManager::BackgroundModeData* | 696 BackgroundModeManager::BackgroundModeData* |
| 630 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { | 697 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { |
| 631 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); | 698 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); |
| 632 return background_mode_data_.find(profile)->second.get(); | 699 return background_mode_data_.find(profile)->second.get(); |
| 633 } | 700 } |
| 634 | 701 |
| 702 BackgroundModeManager::BackgroundModeInfoMap::iterator | |
| 703 BackgroundModeManager::GetBackgroundModeIterator( | |
| 704 const string16& profile_name) { | |
| 705 BackgroundModeInfoMap::iterator profile_it = | |
| 706 background_mode_data_.end(); | |
| 707 for (BackgroundModeInfoMap::iterator it = | |
| 708 background_mode_data_.begin(); | |
| 709 it != background_mode_data_.end(); | |
| 710 ++it) { | |
| 711 if (it->second->name() == profile_name) { | |
| 712 profile_it = it; | |
| 713 } | |
| 714 } | |
| 715 return profile_it; | |
| 716 } | |
| 717 | |
| 635 // static | 718 // static |
| 636 bool BackgroundModeManager::IsBackgroundModePermanentlyDisabled( | 719 bool BackgroundModeManager::IsBackgroundModePermanentlyDisabled( |
| 637 const CommandLine* command_line) { | 720 const CommandLine* command_line) { |
| 638 | 721 |
| 639 // Background mode is disabled if the appropriate flag is passed, or if | 722 // Background mode is disabled if the appropriate flag is passed, or if |
| 640 // extensions are disabled, or if the associated preference is unset. It's | 723 // extensions are disabled, or if the associated preference is unset. It's |
| 641 // always disabled on chromeos since chrome is always running on that | 724 // always disabled on chromeos since chrome is always running on that |
| 642 // platform, making it superfluous. | 725 // platform, making it superfluous. |
| 643 #if defined(OS_CHROMEOS) | 726 #if defined(OS_CHROMEOS) |
| 644 if (command_line->HasSwitch(switches::kKeepAliveForTest)) | 727 if (command_line->HasSwitch(switches::kKeepAliveForTest)) |
| 645 return false; | 728 return false; |
| 646 return true; | 729 return true; |
| 647 #else | 730 #else |
| 648 bool background_mode_disabled = | 731 bool background_mode_disabled = |
| 649 command_line->HasSwitch(switches::kDisableBackgroundMode) || | 732 command_line->HasSwitch(switches::kDisableBackgroundMode) || |
| 650 command_line->HasSwitch(switches::kDisableExtensions); | 733 command_line->HasSwitch(switches::kDisableExtensions); |
| 651 return background_mode_disabled; | 734 return background_mode_disabled; |
| 652 #endif | 735 #endif |
| 653 } | 736 } |
| 654 | 737 |
| 655 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 738 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 656 PrefService* service = g_browser_process->local_state(); | 739 PrefService* service = g_browser_process->local_state(); |
| 657 DCHECK(service); | 740 DCHECK(service); |
| 658 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 741 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 659 } | 742 } |
| OLD | NEW |