| 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 |
| 249 /////////////////////////////////////////////////////////////////////////////// | 268 /////////////////////////////////////////////////////////////////////////////// |
| 250 // BackgroundModeManager, content::NotificationObserver overrides | 269 // BackgroundModeManager, content::NotificationObserver overrides |
| 251 void BackgroundModeManager::Observe( | 270 void BackgroundModeManager::Observe( |
| 252 int type, | 271 int type, |
| 253 const content::NotificationSource& source, | 272 const content::NotificationSource& source, |
| 254 const content::NotificationDetails& details) { | 273 const content::NotificationDetails& details) { |
| 255 switch (type) { | 274 switch (type) { |
| 256 case chrome::NOTIFICATION_PREF_CHANGED: | 275 case chrome::NOTIFICATION_PREF_CHANGED: |
| 257 DCHECK(*content::Details<std::string>(details).ptr() == | 276 DCHECK(*content::Details<std::string>(details).ptr() == |
| 258 prefs::kBackgroundModeEnabled); | 277 prefs::kBackgroundModeEnabled); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 case content::NOTIFICATION_APP_TERMINATING: | 311 case content::NOTIFICATION_APP_TERMINATING: |
| 293 // Make sure we aren't still keeping the app alive (only happens if we | 312 // 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). | 313 // don't receive an EXTENSIONS_READY notification for some reason). |
| 295 EndKeepAliveForStartup(); | 314 EndKeepAliveForStartup(); |
| 296 // Performing an explicit shutdown, so exit background mode (does nothing | 315 // Performing an explicit shutdown, so exit background mode (does nothing |
| 297 // if we aren't in background mode currently). | 316 // if we aren't in background mode currently). |
| 298 EndBackgroundMode(); | 317 EndBackgroundMode(); |
| 299 // Shutting down, so don't listen for any more notifications so we don't | 318 // Shutting down, so don't listen for any more notifications so we don't |
| 300 // try to re-enter/exit background mode again. | 319 // try to re-enter/exit background mode again. |
| 301 registrar_.RemoveAll(); | 320 registrar_.RemoveAll(); |
| 302 for (std::map<Profile*, BackgroundModeInfo>::iterator it = | 321 for (BackgroundModeInfoMap::iterator it = |
| 303 background_mode_data_.begin(); | 322 background_mode_data_.begin(); |
| 304 it != background_mode_data_.end(); | 323 it != background_mode_data_.end(); |
| 305 ++it) { | 324 ++it) { |
| 306 it->second->applications_->RemoveObserver(this); | 325 it->second->applications_->RemoveObserver(this); |
| 307 } | 326 } |
| 308 break; | 327 break; |
| 309 default: | 328 default: |
| 310 NOTREACHED(); | 329 NOTREACHED(); |
| 311 break; | 330 break; |
| 312 } | 331 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 #endif | 376 #endif |
| 358 | 377 |
| 359 StartBackgroundMode(); | 378 StartBackgroundMode(); |
| 360 } | 379 } |
| 361 // List of applications changed so update the UI. | 380 // List of applications changed so update the UI. |
| 362 UpdateStatusTrayIconContextMenu(); | 381 UpdateStatusTrayIconContextMenu(); |
| 363 } | 382 } |
| 364 } | 383 } |
| 365 | 384 |
| 366 /////////////////////////////////////////////////////////////////////////////// | 385 /////////////////////////////////////////////////////////////////////////////// |
| 386 // BackgroundModeManager, ProfileInfoCacheObserver overrides |
| 387 void BackgroundModeManager::OnProfileAdded(const string16& profile_name, |
| 388 const string16& profile_base_dir, |
| 389 const FilePath& profile_path, |
| 390 const gfx::Image* avatar_image) { |
| 391 // 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 |
| 393 // set so we need up to update that with the background_mode_data. |
| 394 for (BackgroundModeInfoMap::const_iterator it = |
| 395 background_mode_data_.begin(); |
| 396 it != background_mode_data_.end(); |
| 397 ++it) { |
| 398 if (it->first->GetPath() == profile_path) { |
| 399 it->second->SetName(profile_name); |
| 400 UpdateStatusTrayIconContextMenu(); |
| 401 return; |
| 402 } |
| 403 } |
| 404 } |
| 405 |
| 406 void BackgroundModeManager::OnProfileRemoved(const string16& profile_name) { |
| 407 // Remove the profile from our map of profiles. |
| 408 BackgroundModeInfoMap::iterator it = |
| 409 GetBackgroundModeIterator(profile_name); |
| 410 // If a profile isn't running a background app, it may not be in the map. |
| 411 if (it != background_mode_data_.end()) { |
| 412 background_mode_data_.erase(it); |
| 413 UpdateStatusTrayIconContextMenu(); |
| 414 } |
| 415 } |
| 416 |
| 417 void BackgroundModeManager::OnProfileNameChanged( |
| 418 const string16& old_profile_name, |
| 419 const string16& new_profile_name) { |
| 420 BackgroundModeInfoMap::const_iterator it = |
| 421 GetBackgroundModeIterator(old_profile_name); |
| 422 // We check that the returned iterator is valid due to unittests, but really |
| 423 // this should only be called on profiles already known by the background |
| 424 // mode manager. |
| 425 if (it != background_mode_data_.end()) { |
| 426 it->second->SetName(new_profile_name); |
| 427 UpdateStatusTrayIconContextMenu(); |
| 428 } |
| 429 } |
| 430 |
| 431 void BackgroundModeManager::OnProfileAvatarChanged( |
| 432 const string16& profile_name, |
| 433 const string16& profile_base_dir, |
| 434 const FilePath& profile_path, |
| 435 const gfx::Image* avatar_image) { |
| 436 |
| 437 } |
| 438 /////////////////////////////////////////////////////////////////////////////// |
| 367 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides | 439 // BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides |
| 368 bool BackgroundModeManager::IsCommandIdChecked( | 440 bool BackgroundModeManager::IsCommandIdChecked( |
| 369 int command_id) const { | 441 int command_id) const { |
| 370 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); | 442 DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); |
| 371 return true; | 443 return true; |
| 372 } | 444 } |
| 373 | 445 |
| 374 bool BackgroundModeManager::IsCommandIdEnabled( | 446 bool BackgroundModeManager::IsCommandIdEnabled( |
| 375 int command_id) const { | 447 int command_id) const { |
| 376 return command_id != IDC_MinimumLabelValue; | 448 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. | 554 // If background mode is currently enabled, turn it off. |
| 483 if (in_background_mode_) { | 555 if (in_background_mode_) { |
| 484 EndBackgroundMode(); | 556 EndBackgroundMode(); |
| 485 EnableLaunchOnStartup(false); | 557 EnableLaunchOnStartup(false); |
| 486 } | 558 } |
| 487 } | 559 } |
| 488 | 560 |
| 489 int BackgroundModeManager::GetBackgroundAppCount() const { | 561 int BackgroundModeManager::GetBackgroundAppCount() const { |
| 490 int count = 0; | 562 int count = 0; |
| 491 // Walk the BackgroundModeData for all profiles and count the number of apps. | 563 // Walk the BackgroundModeData for all profiles and count the number of apps. |
| 492 for (std::map<Profile*, BackgroundModeInfo>::const_iterator it = | 564 for (BackgroundModeInfoMap::const_iterator it = |
| 493 background_mode_data_.begin(); | 565 background_mode_data_.begin(); |
| 494 it != background_mode_data_.end(); | 566 it != background_mode_data_.end(); |
| 495 ++it) { | 567 ++it) { |
| 496 count += it->second->GetBackgroundAppCount(); | 568 count += it->second->GetBackgroundAppCount(); |
| 497 } | 569 } |
| 498 DCHECK(count >= 0); | 570 DCHECK(count >= 0); |
| 499 return count; | 571 return count; |
| 500 } | 572 } |
| 501 | 573 |
| 502 int BackgroundModeManager::GetBackgroundAppCountForProfile( | 574 int BackgroundModeManager::GetBackgroundAppCountForProfile( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 // Create a context menu item for Chrome. | 653 // Create a context menu item for Chrome. |
| 582 ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); | 654 ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); |
| 583 // Add About item | 655 // Add About item |
| 584 menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, | 656 menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, |
| 585 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 657 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 586 menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 658 menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 587 menu->AddSeparator(); | 659 menu->AddSeparator(); |
| 588 | 660 |
| 589 if (background_mode_data_.size() > 1) { | 661 if (background_mode_data_.size() > 1) { |
| 590 std::vector<BackgroundModeData*> bmd_vector; | 662 std::vector<BackgroundModeData*> bmd_vector; |
| 591 for (std::map<Profile*, BackgroundModeInfo>::iterator it = | 663 for (BackgroundModeInfoMap::iterator it = |
| 592 background_mode_data_.begin(); | 664 background_mode_data_.begin(); |
| 593 it != background_mode_data_.end(); | 665 it != background_mode_data_.end(); |
| 594 ++it) { | 666 ++it) { |
| 595 bmd_vector.push_back(it->second.get()); | 667 bmd_vector.push_back(it->second.get()); |
| 596 } | 668 } |
| 597 std::sort(bmd_vector.begin(), bmd_vector.end(), | 669 std::sort(bmd_vector.begin(), bmd_vector.end(), |
| 598 &BackgroundModeData::BackgroundModeDataCompare); | 670 &BackgroundModeData::BackgroundModeDataCompare); |
| 599 for (std::vector<BackgroundModeData*>::const_iterator bmd_it = | 671 for (std::vector<BackgroundModeData*>::const_iterator bmd_it = |
| 600 bmd_vector.begin(); | 672 bmd_vector.begin(); |
| 601 bmd_it != bmd_vector.end(); | 673 bmd_it != bmd_vector.end(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 625 status_icon_ = NULL; | 697 status_icon_ = NULL; |
| 626 context_menu_ = NULL; | 698 context_menu_ = NULL; |
| 627 } | 699 } |
| 628 | 700 |
| 629 BackgroundModeManager::BackgroundModeData* | 701 BackgroundModeManager::BackgroundModeData* |
| 630 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { | 702 BackgroundModeManager::GetBackgroundModeData(Profile* const profile) const { |
| 631 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); | 703 DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); |
| 632 return background_mode_data_.find(profile)->second.get(); | 704 return background_mode_data_.find(profile)->second.get(); |
| 633 } | 705 } |
| 634 | 706 |
| 707 BackgroundModeManager::BackgroundModeInfoMap::iterator |
| 708 BackgroundModeManager::GetBackgroundModeIterator( |
| 709 const string16& profile_name) { |
| 710 BackgroundModeInfoMap::iterator profile_it = |
| 711 background_mode_data_.end(); |
| 712 for (BackgroundModeInfoMap::iterator it = |
| 713 background_mode_data_.begin(); |
| 714 it != background_mode_data_.end(); |
| 715 ++it) { |
| 716 if (it->second->name() == profile_name) { |
| 717 profile_it = it; |
| 718 } |
| 719 } |
| 720 return profile_it; |
| 721 } |
| 722 |
| 635 // static | 723 // static |
| 636 bool BackgroundModeManager::IsBackgroundModePermanentlyDisabled( | 724 bool BackgroundModeManager::IsBackgroundModePermanentlyDisabled( |
| 637 const CommandLine* command_line) { | 725 const CommandLine* command_line) { |
| 638 | 726 |
| 639 // Background mode is disabled if the appropriate flag is passed, or if | 727 // 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 | 728 // extensions are disabled, or if the associated preference is unset. It's |
| 641 // always disabled on chromeos since chrome is always running on that | 729 // always disabled on chromeos since chrome is always running on that |
| 642 // platform, making it superfluous. | 730 // platform, making it superfluous. |
| 643 #if defined(OS_CHROMEOS) | 731 #if defined(OS_CHROMEOS) |
| 644 if (command_line->HasSwitch(switches::kKeepAliveForTest)) | 732 if (command_line->HasSwitch(switches::kKeepAliveForTest)) |
| 645 return false; | 733 return false; |
| 646 return true; | 734 return true; |
| 647 #else | 735 #else |
| 648 bool background_mode_disabled = | 736 bool background_mode_disabled = |
| 649 command_line->HasSwitch(switches::kDisableBackgroundMode) || | 737 command_line->HasSwitch(switches::kDisableBackgroundMode) || |
| 650 command_line->HasSwitch(switches::kDisableExtensions); | 738 command_line->HasSwitch(switches::kDisableExtensions); |
| 651 return background_mode_disabled; | 739 return background_mode_disabled; |
| 652 #endif | 740 #endif |
| 653 } | 741 } |
| 654 | 742 |
| 655 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 743 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 656 PrefService* service = g_browser_process->local_state(); | 744 PrefService* service = g_browser_process->local_state(); |
| 657 DCHECK(service); | 745 DCHECK(service); |
| 658 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 746 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 659 } | 747 } |
| OLD | NEW |