| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 752 } |
| 748 } | 753 } |
| 749 return profile_it; | 754 return profile_it; |
| 750 } | 755 } |
| 751 | 756 |
| 752 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 757 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 753 PrefService* service = g_browser_process->local_state(); | 758 PrefService* service = g_browser_process->local_state(); |
| 754 DCHECK(service); | 759 DCHECK(service); |
| 755 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 760 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 756 } | 761 } |
| OLD | NEW |