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

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

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 9 years, 4 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) 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
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/browser/extensions/convert_web_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698