| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/ui/chrome_pages.h" | 30 #include "chrome/browser/ui/chrome_pages.h" |
| 31 #include "chrome/browser/ui/extensions/application_launch.h" | 31 #include "chrome/browser/ui/extensions/application_launch.h" |
| 32 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| 36 #include "chrome/common/extensions/extension_constants.h" | 36 #include "chrome/common/extensions/extension_constants.h" |
| 37 #include "chrome/common/extensions/permissions/permission_set.h" | 37 #include "chrome/common/extensions/permissions/permission_set.h" |
| 38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 39 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/notification_types.h" | |
| 41 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 42 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 43 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 44 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 46 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 47 | 46 |
| 48 using content::UserMetricsAction; | 47 using content::UserMetricsAction; |
| 49 using extensions::Extension; | 48 using extensions::Extension; |
| 50 using extensions::UpdatedExtensionPermissionsInfo; | 49 using extensions::UpdatedExtensionPermissionsInfo; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // If the -keep-alive-for-test flag is passed, then always keep chrome running | 184 // If the -keep-alive-for-test flag is passed, then always keep chrome running |
| 186 // in the background until the user explicitly terminates it. | 185 // in the background until the user explicitly terminates it. |
| 187 if (command_line->HasSwitch(switches::kKeepAliveForTest)) | 186 if (command_line->HasSwitch(switches::kKeepAliveForTest)) |
| 188 keep_alive_for_test_ = true; | 187 keep_alive_for_test_ = true; |
| 189 | 188 |
| 190 if (ShouldBeInBackgroundMode()) | 189 if (ShouldBeInBackgroundMode()) |
| 191 StartBackgroundMode(); | 190 StartBackgroundMode(); |
| 192 | 191 |
| 193 // Listen for the application shutting down so we can decrement our KeepAlive | 192 // Listen for the application shutting down so we can decrement our KeepAlive |
| 194 // count. | 193 // count. |
| 195 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 194 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 196 content::NotificationService::AllSources()); | 195 content::NotificationService::AllSources()); |
| 197 } | 196 } |
| 198 | 197 |
| 199 BackgroundModeManager::~BackgroundModeManager() { | 198 BackgroundModeManager::~BackgroundModeManager() { |
| 200 // Remove ourselves from the application observer list (only needed by unit | 199 // Remove ourselves from the application observer list (only needed by unit |
| 201 // tests since APP_TERMINATING is what does this in a real running system). | 200 // tests since APP_TERMINATING is what does this in a real running system). |
| 202 for (BackgroundModeInfoMap::iterator it = | 201 for (BackgroundModeInfoMap::iterator it = |
| 203 background_mode_data_.begin(); | 202 background_mode_data_.begin(); |
| 204 it != background_mode_data_.end(); | 203 it != background_mode_data_.end(); |
| 205 ++it) { | 204 ++it) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 UpdatedExtensionPermissionsInfo* info = | 311 UpdatedExtensionPermissionsInfo* info = |
| 313 content::Details<UpdatedExtensionPermissionsInfo>(details).ptr(); | 312 content::Details<UpdatedExtensionPermissionsInfo>(details).ptr(); |
| 314 if (info->permissions->HasAPIPermission( | 313 if (info->permissions->HasAPIPermission( |
| 315 extensions::APIPermission::kBackground) && | 314 extensions::APIPermission::kBackground) && |
| 316 info->reason == UpdatedExtensionPermissionsInfo::ADDED) { | 315 info->reason == UpdatedExtensionPermissionsInfo::ADDED) { |
| 317 // Turned on background permission, so treat this as a new install. | 316 // Turned on background permission, so treat this as a new install. |
| 318 OnBackgroundAppInstalled(info->extension); | 317 OnBackgroundAppInstalled(info->extension); |
| 319 } | 318 } |
| 320 } | 319 } |
| 321 break; | 320 break; |
| 322 case content::NOTIFICATION_APP_TERMINATING: | 321 case chrome::NOTIFICATION_APP_TERMINATING: |
| 323 // Make sure we aren't still keeping the app alive (only happens if we | 322 // Make sure we aren't still keeping the app alive (only happens if we |
| 324 // don't receive an EXTENSIONS_READY notification for some reason). | 323 // don't receive an EXTENSIONS_READY notification for some reason). |
| 325 EndKeepAliveForStartup(); | 324 EndKeepAliveForStartup(); |
| 326 // Performing an explicit shutdown, so exit background mode (does nothing | 325 // Performing an explicit shutdown, so exit background mode (does nothing |
| 327 // if we aren't in background mode currently). | 326 // if we aren't in background mode currently). |
| 328 EndBackgroundMode(); | 327 EndBackgroundMode(); |
| 329 // Shutting down, so don't listen for any more notifications so we don't | 328 // Shutting down, so don't listen for any more notifications so we don't |
| 330 // try to re-enter/exit background mode again. | 329 // try to re-enter/exit background mode again. |
| 331 registrar_.RemoveAll(); | 330 registrar_.RemoveAll(); |
| 332 for (BackgroundModeInfoMap::iterator it = | 331 for (BackgroundModeInfoMap::iterator it = |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 771 } |
| 773 } | 772 } |
| 774 return profile_it; | 773 return profile_it; |
| 775 } | 774 } |
| 776 | 775 |
| 777 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { | 776 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { |
| 778 PrefService* service = g_browser_process->local_state(); | 777 PrefService* service = g_browser_process->local_state(); |
| 779 DCHECK(service); | 778 DCHECK(service); |
| 780 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 779 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
| 781 } | 780 } |
| OLD | NEW |