Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: chrome/browser/background/background_mode_manager.cc

Issue 10298002: No longer start BG mode until a BackgroundContents is loaded (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Prospective fix for cros test failures. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 Profile* profile, 256 Profile* profile,
257 const Extension* extension) { 257 const Extension* extension) {
258 ExtensionService* service = profile->GetExtensionService(); 258 ExtensionService* service = profile->GetExtensionService();
259 extension_misc::LaunchContainer launch_container = 259 extension_misc::LaunchContainer launch_container =
260 service->extension_prefs()->GetLaunchContainer( 260 service->extension_prefs()->GetLaunchContainer(
261 extension, ExtensionPrefs::LAUNCH_REGULAR); 261 extension, ExtensionPrefs::LAUNCH_REGULAR);
262 Browser::OpenApplication(profile, extension, launch_container, GURL(), 262 Browser::OpenApplication(profile, extension, launch_container, GURL(),
263 NEW_FOREGROUND_TAB); 263 NEW_FOREGROUND_TAB);
264 } 264 }
265 265
266 bool BackgroundModeManager::IsBackgroundModeActiveForTest() {
267 return in_background_mode_;
268 }
269
266 int BackgroundModeManager::NumberOfBackgroundModeData() { 270 int BackgroundModeManager::NumberOfBackgroundModeData() {
267 return background_mode_data_.size(); 271 return background_mode_data_.size();
268 } 272 }
269 273
270 /////////////////////////////////////////////////////////////////////////////// 274 ///////////////////////////////////////////////////////////////////////////////
271 // BackgroundModeManager, content::NotificationObserver overrides 275 // BackgroundModeManager, content::NotificationObserver overrides
272 void BackgroundModeManager::Observe( 276 void BackgroundModeManager::Observe(
273 int type, 277 int type,
274 const content::NotificationSource& source, 278 const content::NotificationSource& source,
275 const content::NotificationDetails& details) { 279 const content::NotificationDetails& details) {
276 switch (type) { 280 switch (type) {
277 case chrome::NOTIFICATION_PREF_CHANGED: 281 case chrome::NOTIFICATION_PREF_CHANGED:
278 DCHECK(*content::Details<std::string>(details).ptr() == 282 DCHECK(*content::Details<std::string>(details).ptr() ==
279 prefs::kBackgroundModeEnabled); 283 prefs::kBackgroundModeEnabled);
280 if (IsBackgroundModePrefEnabled()) 284 if (IsBackgroundModePrefEnabled())
281 EnableBackgroundMode(); 285 EnableBackgroundMode();
282 else 286 else
283 DisableBackgroundMode(); 287 DisableBackgroundMode();
284 break; 288 break;
285 case chrome::NOTIFICATION_EXTENSIONS_READY: 289 case chrome::NOTIFICATION_EXTENSIONS_READY:
286 // Extensions are loaded, so we don't need to manually keep the browser 290 // Extensions are loaded, so we don't need to manually keep the browser
287 // process alive any more when running in no-startup-window mode. 291 // process alive any more when running in no-startup-window mode.
288 EndKeepAliveForStartup(); 292 EndKeepAliveForStartup();
289 break; 293 break;
290 294
291 case chrome::NOTIFICATION_EXTENSION_LOADED: { 295 case chrome::NOTIFICATION_EXTENSION_LOADED: {
292 Extension* extension = content::Details<Extension>(details).ptr(); 296 Extension* extension = content::Details<Extension>(details).ptr();
293 if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) { 297 Profile* profile = content::Source<Profile>(source).ptr();
298 if (BackgroundApplicationListModel::IsBackgroundApp(
299 *extension, profile)) {
294 // Extensions loaded after the ExtensionsService is ready should be 300 // Extensions loaded after the ExtensionsService is ready should be
295 // treated as new installs. 301 // treated as new installs.
296 Profile* profile = content::Source<Profile>(source).ptr();
297 if (profile->GetExtensionService()->is_ready()) 302 if (profile->GetExtensionService()->is_ready())
298 OnBackgroundAppInstalled(extension); 303 OnBackgroundAppInstalled(extension);
299 } 304 }
300 } 305 }
301 break; 306 break;
302 case chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED: { 307 case chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED: {
303 UpdatedExtensionPermissionsInfo* info = 308 UpdatedExtensionPermissionsInfo* info =
304 content::Details<UpdatedExtensionPermissionsInfo>(details).ptr(); 309 content::Details<UpdatedExtensionPermissionsInfo>(details).ptr();
305 if (info->permissions->HasAPIPermission( 310 if (info->permissions->HasAPIPermission(
306 ExtensionAPIPermission::kBackground) && 311 ExtensionAPIPermission::kBackground) &&
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 return; 535 return;
531 536
532 // Mark ourselves as running in background mode. 537 // Mark ourselves as running in background mode.
533 in_background_mode_ = true; 538 in_background_mode_ = true;
534 539
535 // Put ourselves in KeepAlive mode and create a status tray icon. 540 // Put ourselves in KeepAlive mode and create a status tray icon.
536 BrowserList::StartKeepAlive(); 541 BrowserList::StartKeepAlive();
537 542
538 // Display a status icon to exit Chrome. 543 // Display a status icon to exit Chrome.
539 InitStatusTrayIcon(); 544 InitStatusTrayIcon();
545
546 content::NotificationService::current()->Notify(
547 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED,
548 content::Source<BackgroundModeManager>(this),
549 content::Details<bool>(&in_background_mode_));
540 } 550 }
541 551
542 void BackgroundModeManager::InitStatusTrayIcon() { 552 void BackgroundModeManager::InitStatusTrayIcon() {
543 // Only initialize status tray icons for those profiles which actually 553 // Only initialize status tray icons for those profiles which actually
544 // have a background app running. 554 // have a background app running.
545 if (keep_alive_for_test_ || GetBackgroundAppCount() > 0) { 555 if (keep_alive_for_test_ || GetBackgroundAppCount() > 0) {
546 CreateStatusTrayIcon(); 556 CreateStatusTrayIcon();
547 } 557 }
548 } 558 }
549 559
550 void BackgroundModeManager::EndBackgroundMode() { 560 void BackgroundModeManager::EndBackgroundMode() {
551 if (!in_background_mode_) 561 if (!in_background_mode_)
552 return; 562 return;
553 in_background_mode_ = false; 563 in_background_mode_ = false;
554 564
555 // End KeepAlive mode and blow away our status tray icon. 565 // End KeepAlive mode and blow away our status tray icon.
556 BrowserList::EndKeepAlive(); 566 BrowserList::EndKeepAlive();
557 567
558 RemoveStatusTrayIcon(); 568 RemoveStatusTrayIcon();
569 content::NotificationService::current()->Notify(
570 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED,
571 content::Source<BackgroundModeManager>(this),
572 content::Details<bool>(&in_background_mode_));
559 } 573 }
560 574
561 void BackgroundModeManager::EnableBackgroundMode() { 575 void BackgroundModeManager::EnableBackgroundMode() {
562 DCHECK(IsBackgroundModePrefEnabled()); 576 DCHECK(IsBackgroundModePrefEnabled());
563 // If background mode should be enabled, but isn't, turn it on. 577 // If background mode should be enabled, but isn't, turn it on.
564 if (!in_background_mode_ && 578 if (!in_background_mode_ &&
565 (GetBackgroundAppCount() > 0 || keep_alive_for_test_)) { 579 (GetBackgroundAppCount() > 0 || keep_alive_for_test_)) {
566 StartBackgroundMode(); 580 StartBackgroundMode();
567 EnableLaunchOnStartup(true); 581 EnableLaunchOnStartup(true);
568 } 582 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 } 761 }
748 } 762 }
749 return profile_it; 763 return profile_it;
750 } 764 }
751 765
752 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { 766 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const {
753 PrefService* service = g_browser_process->local_state(); 767 PrefService* service = g_browser_process->local_state();
754 DCHECK(service); 768 DCHECK(service);
755 return service->GetBoolean(prefs::kBackgroundModeEnabled); 769 return service->GetBoolean(prefs::kBackgroundModeEnabled);
756 } 770 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager.h ('k') | chrome/browser/extensions/app_background_page_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698