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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 void BackgroundModeManager::RegisterProfile(Profile* profile) { | 192 void BackgroundModeManager::RegisterProfile(Profile* profile) { |
193 // We don't want to register multiple times for one profile. | 193 // We don't want to register multiple times for one profile. |
194 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); | 194 DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); |
195 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, | 195 BackgroundModeInfo bmd(new BackgroundModeData(current_command_id_++, |
196 profile, this)); | 196 profile, this)); |
197 background_mode_data_[profile] = bmd; | 197 background_mode_data_[profile] = bmd; |
198 | 198 |
199 // Listen for when extensions are loaded/unloaded so we can track the | 199 // Listen for when extensions are loaded/unloaded or add/remove the |
200 // number of background apps and modify our keep-alive and launch-on-startup | 200 // background permission so we can track the number of background apps and |
201 // state appropriately. | 201 // modify our keep-alive and launch-on-startup state appropriately. |
202 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 202 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
203 Source<Profile>(profile)); | 203 Source<Profile>(profile)); |
204 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 204 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
205 Source<Profile>(profile)); | 205 Source<Profile>(profile)); |
| 206 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, |
| 207 Source<Profile>(profile)); |
206 | 208 |
207 // Check for the presence of background apps after all extensions have been | 209 // Check for the presence of background apps after all extensions have been |
208 // loaded, to handle the case where an extension has been manually removed | 210 // loaded, to handle the case where an extension has been manually removed |
209 // while Chrome was not running. | 211 // while Chrome was not running. |
210 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
211 Source<Profile>(profile)); | 213 Source<Profile>(profile)); |
212 | 214 |
213 bmd->applications_->AddObserver(this); | 215 bmd->applications_->AddObserver(this); |
214 | 216 |
215 // If we're adding a new profile and running in multi-profile mode, this new | 217 // If we're adding a new profile and running in multi-profile mode, this new |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // If we already got an unload notification when it was disabled, ignore | 269 // If we already got an unload notification when it was disabled, ignore |
268 // this one. | 270 // this one. |
269 // TODO(atwilson): Change BackgroundModeManager to use | 271 // TODO(atwilson): Change BackgroundModeManager to use |
270 // BackgroundApplicationListModel instead of tracking the count here. | 272 // BackgroundApplicationListModel instead of tracking the count here. |
271 if (info->already_disabled) | 273 if (info->already_disabled) |
272 return; | 274 return; |
273 OnBackgroundAppUnloaded(); | 275 OnBackgroundAppUnloaded(); |
274 OnBackgroundAppUninstalled(); | 276 OnBackgroundAppUninstalled(); |
275 } | 277 } |
276 break; | 278 break; |
| 279 case chrome::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED: { |
| 280 UpdatedExtensionPermissionsInfo* info = |
| 281 Details<UpdatedExtensionPermissionsInfo>(details).ptr(); |
| 282 if (!info->permissions->HasAPIPermission( |
| 283 ExtensionAPIPermission::kBackground)) |
| 284 break; |
| 285 |
| 286 if (info->reason == UpdatedExtensionPermissionsInfo::ADDED) { |
| 287 OnBackgroundAppInstalled(info->extension); |
| 288 OnBackgroundAppLoaded(); |
| 289 } else { |
| 290 OnBackgroundAppUnloaded(); |
| 291 OnBackgroundAppUninstalled(); |
| 292 } |
| 293 } |
| 294 break; |
277 case content::NOTIFICATION_APP_TERMINATING: | 295 case content::NOTIFICATION_APP_TERMINATING: |
278 // Make sure we aren't still keeping the app alive (only happens if we | 296 // Make sure we aren't still keeping the app alive (only happens if we |
279 // don't receive an EXTENSIONS_READY notification for some reason). | 297 // don't receive an EXTENSIONS_READY notification for some reason). |
280 EndKeepAliveForStartup(); | 298 EndKeepAliveForStartup(); |
281 // Performing an explicit shutdown, so exit background mode (does nothing | 299 // Performing an explicit shutdown, so exit background mode (does nothing |
282 // if we aren't in background mode currently). | 300 // if we aren't in background mode currently). |
283 EndBackgroundMode(); | 301 EndBackgroundMode(); |
284 // Shutting down, so don't listen for any more notifications so we don't | 302 // Shutting down, so don't listen for any more notifications so we don't |
285 // try to re-enter/exit background mode again. | 303 // try to re-enter/exit background mode again. |
286 registrar_.RemoveAll(); | 304 registrar_.RemoveAll(); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 command_line->HasSwitch(switches::kDisableExtensions); | 608 command_line->HasSwitch(switches::kDisableExtensions); |
591 return background_mode_disabled; | 609 return background_mode_disabled; |
592 #endif | 610 #endif |
593 } | 611 } |
594 | 612 |
595 bool BackgroundModeManager::IsBackgroundModePrefEnabled() { | 613 bool BackgroundModeManager::IsBackgroundModePrefEnabled() { |
596 PrefService* service = g_browser_process->local_state(); | 614 PrefService* service = g_browser_process->local_state(); |
597 DCHECK(service); | 615 DCHECK(service); |
598 return service->GetBoolean(prefs::kBackgroundModeEnabled); | 616 return service->GetBoolean(prefs::kBackgroundModeEnabled); |
599 } | 617 } |
OLD | NEW |