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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 bool new_value = true; | |
Mihai Parparita -not on Chrome
2012/05/03 19:32:35
Why not use &in_background_mode_?
Andrew T Wilson (Slow)
2012/05/03 21:36:58
Good idea - heh, the dangers of writing code too l
| |
547 content::NotificationService::current()->Notify( | |
548 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, | |
549 content::Source<BackgroundModeManager>(this), | |
550 content::Details<bool>(&new_value)); | |
540 } | 551 } |
541 | 552 |
542 void BackgroundModeManager::InitStatusTrayIcon() { | 553 void BackgroundModeManager::InitStatusTrayIcon() { |
543 // Only initialize status tray icons for those profiles which actually | 554 // Only initialize status tray icons for those profiles which actually |
544 // have a background app running. | 555 // have a background app running. |
545 if (keep_alive_for_test_ || GetBackgroundAppCount() > 0) { | 556 if (keep_alive_for_test_ || GetBackgroundAppCount() > 0) { |
546 CreateStatusTrayIcon(); | 557 CreateStatusTrayIcon(); |
547 } | 558 } |
548 } | 559 } |
549 | 560 |
550 void BackgroundModeManager::EndBackgroundMode() { | 561 void BackgroundModeManager::EndBackgroundMode() { |
551 if (!in_background_mode_) | 562 if (!in_background_mode_) |
552 return; | 563 return; |
553 in_background_mode_ = false; | 564 in_background_mode_ = false; |
554 | 565 |
555 // End KeepAlive mode and blow away our status tray icon. | 566 // End KeepAlive mode and blow away our status tray icon. |
556 BrowserList::EndKeepAlive(); | 567 BrowserList::EndKeepAlive(); |
557 | 568 |
558 RemoveStatusTrayIcon(); | 569 RemoveStatusTrayIcon(); |
570 bool new_value = false; | |
Mihai Parparita -not on Chrome
2012/05/03 19:32:35
Same here.
Andrew T Wilson (Slow)
2012/05/03 21:36:58
Done.
| |
571 content::NotificationService::current()->Notify( | |
572 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, | |
573 content::Source<BackgroundModeManager>(this), | |
574 content::Details<bool>(&new_value)); | |
559 } | 575 } |
560 | 576 |
561 void BackgroundModeManager::EnableBackgroundMode() { | 577 void BackgroundModeManager::EnableBackgroundMode() { |
562 DCHECK(IsBackgroundModePrefEnabled()); | 578 DCHECK(IsBackgroundModePrefEnabled()); |
563 // If background mode should be enabled, but isn't, turn it on. | 579 // If background mode should be enabled, but isn't, turn it on. |
564 if (!in_background_mode_ && | 580 if (!in_background_mode_ && |
565 (GetBackgroundAppCount() > 0 || keep_alive_for_test_)) { | 581 (GetBackgroundAppCount() > 0 || keep_alive_for_test_)) { |
566 StartBackgroundMode(); | 582 StartBackgroundMode(); |
567 EnableLaunchOnStartup(true); | 583 EnableLaunchOnStartup(true); |
568 } | 584 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 } | 763 } |
748 } | 764 } |
749 return profile_it; | 765 return profile_it; |
750 } | 766 } |
751 | 767 |
752 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 768 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
753 PrefService* service = g_browser_process->local_state(); | 769 PrefService* service = g_browser_process->local_state(); |
754 DCHECK(service); | 770 DCHECK(service); |
755 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 771 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
756 } | 772 } |
OLD | NEW |