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

Unified Diff: chrome/browser/extensions/extension_service.cc

Issue 25366003: Moved some functions off ExtensionService into a new file extension_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windows compile Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index b38bc6f97df2bacec1ff21e17fa2ad5afe573464..f5ad54a8e49419c6692f0e452787f1696b71eb5e 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -50,6 +50,7 @@
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_sync_data.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/external_install_ui.h"
#include "chrome/browser/extensions/external_provider_impl.h"
#include "chrome/browser/extensions/external_provider_interface.h"
@@ -282,28 +283,6 @@ bool ExtensionService::IsInstalledApp(const GURL& url) const {
return !!GetInstalledApp(url);
}
-const Extension* ExtensionService::GetIsolatedAppForRenderer(
- int renderer_child_id) const {
- std::set<std::string> extension_ids =
- process_map_.GetExtensionsInProcess(renderer_child_id);
- // All apps in one process share the same partition.
- // It is only possible for the app to have isolated storage
- // if there is only 1 app in the process.
- if (extension_ids.size() != 1)
- return NULL;
-
- const extensions::Extension* extension =
- extensions_.GetByID(*(extension_ids.begin()));
- // We still need to check if the extension has isolated storage,
- // because it's common for there to be one extension in a process
- // without isolated storage.
- if (extension &&
- extensions::AppIsolationInfo::HasIsolatedStorage(extension))
- return extension;
-
- return NULL;
-}
-
// static
// This function is used to implement the command-line switch
// --uninstall-extension, and to uninstall an extension via sync. The LOG
@@ -1242,6 +1221,10 @@ extensions::ExtensionPrefs* ExtensionService::extension_prefs() {
return extension_prefs_;
}
+const extensions::ExtensionPrefs* ExtensionService::extension_prefs() const {
+ return extension_prefs_;
+}
+
extensions::SettingsFrontend* ExtensionService::settings_frontend() {
return settings_frontend_.get();
}
@@ -1407,9 +1390,11 @@ syncer::SyncError ExtensionService::ProcessSyncChanges(
extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData(
const Extension& extension) const {
- return extensions::ExtensionSyncData(extension,
- IsExtensionEnabled(extension.id()),
- IsIncognitoEnabled(extension.id()));
+ return extensions::ExtensionSyncData(
+ extension,
+ IsExtensionEnabled(extension.id()),
+ extension_util::IsIncognitoEnabled(extension.id(),
Yoyo Zhou 2013/10/15 21:25:49 nit: line break is extraneous
benwells 2013/10/17 06:56:55 Done.
+ this));
}
extensions::AppSyncData ExtensionService::GetAppSyncData(
@@ -1417,7 +1402,8 @@ extensions::AppSyncData ExtensionService::GetAppSyncData(
return extensions::AppSyncData(
extension,
IsExtensionEnabled(extension.id()),
- IsIncognitoEnabled(extension.id()),
+ extension_util::IsIncognitoEnabled(extension.id(),
Yoyo Zhou 2013/10/15 21:25:49 ditto
benwells 2013/10/17 06:56:55 Done.
+ this),
extension_prefs_->extension_sorting()->GetAppLaunchOrdinal(
extension.id()),
extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id()));
@@ -1562,7 +1548,8 @@ bool ExtensionService::ProcessExtensionSyncDataHelper(
bool extension_installed = (extension != NULL);
int result = extension ?
extension->version()->CompareTo(extension_sync_data.version()) : 0;
- SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled());
+ extension_util::SetIsIncognitoEnabled(
+ id, this, extension_sync_data.incognito_enabled());
extension = NULL; // No longer safe to use.
if (extension_installed) {
@@ -1599,79 +1586,6 @@ bool ExtensionService::ProcessExtensionSyncDataHelper(
return true;
}
-bool ExtensionService::IsIncognitoEnabled(
- const std::string& extension_id) const {
- const Extension* extension = GetInstalledExtension(extension_id);
- if (extension && !extension->can_be_incognito_enabled())
- return false;
- // If this is an existing component extension we always allow it to
- // work in incognito mode.
- if (extension && extension->location() == Manifest::COMPONENT)
- return true;
- if (extension && extension->force_incognito_enabled())
- return true;
-
- // Check the prefs.
- return extension_prefs_->IsIncognitoEnabled(extension_id);
-}
-
-void ExtensionService::SetIsIncognitoEnabled(
- const std::string& extension_id, bool enabled) {
- const Extension* extension = GetInstalledExtension(extension_id);
- if (extension && !extension->can_be_incognito_enabled())
- return;
- if (extension && extension->location() == Manifest::COMPONENT) {
- // This shouldn't be called for component extensions unless they are
- // syncable.
- DCHECK(extensions::sync_helper::IsSyncable(extension));
-
- // If we are here, make sure the we aren't trying to change the value.
- DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id));
-
- return;
- }
-
- // Broadcast unloaded and loaded events to update browser state. Only bother
- // if the value changed and the extension is actually enabled, since there is
- // no UI otherwise.
- bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
- if (enabled == old_enabled)
- return;
-
- extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
-
- bool extension_is_enabled = extensions_.Contains(extension_id);
-
- // When we reload the extension the ID may be invalidated if we've passed it
- // by const ref everywhere. Make a copy to be safe.
- std::string id = extension_id;
- if (extension_is_enabled)
- ReloadExtension(id);
-
- // Reloading the extension invalidates the |extension| pointer.
- extension = GetInstalledExtension(id);
- if (extension)
- SyncExtensionChangeIfNeeded(*extension);
-}
-
-bool ExtensionService::CanCrossIncognito(const Extension* extension) const {
- // We allow the extension to see events and data from another profile iff it
- // uses "spanning" behavior and it has incognito access. "split" mode
- // extensions only see events for a matching profile.
- CHECK(extension);
- return IsIncognitoEnabled(extension->id()) &&
- !extensions::IncognitoInfo::IsSplitMode(extension);
-}
-
-bool ExtensionService::CanLoadInIncognito(const Extension* extension) const {
- if (extension->is_hosted_app())
- return true;
- // Packaged apps and regular extensions need to be enabled specifically for
- // incognito (and split mode should be set).
- return extensions::IncognitoInfo::IsSplitMode(extension) &&
- IsIncognitoEnabled(extension->id());
-}
-
void ExtensionService::OnExtensionMoved(
const std::string& moved_extension_id,
const std::string& predecessor_extension_id,
@@ -1686,27 +1600,6 @@ void ExtensionService::OnExtensionMoved(
SyncExtensionChangeIfNeeded(*extension);
}
-bool ExtensionService::AllowFileAccess(const Extension* extension) const {
- return (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableExtensionsFileAccessCheck) ||
- extension_prefs_->AllowFileAccess(extension->id()));
-}
-
-void ExtensionService::SetAllowFileAccess(const Extension* extension,
- bool allow) {
- // Reload to update browser state. Only bother if the value changed and the
- // extension is actually enabled, since there is no UI otherwise.
- bool old_allow = AllowFileAccess(extension);
- if (allow == old_allow)
- return;
-
- extension_prefs_->SetAllowFileAccess(extension->id(), allow);
-
- bool extension_is_enabled = extensions_.Contains(extension->id());
- if (extension_is_enabled)
- ReloadExtension(extension->id());
-}
-
// Some extensions will autoupdate themselves externally from Chrome. These
// are typically part of some larger client application package. To support
// these, the extension will register its location in the the preferences file

Powered by Google App Engine
This is Rietveld 408576698