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

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

Issue 9374009: Install platform apps into a separate data directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 8 years, 10 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 12bda985251fa511830792e017ee3b241457020c..6e072c17ff6916d83bbaf9c28453494edaecd138 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -45,6 +45,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_input_ime_api.h"
#include "chrome/browser/extensions/extension_management_api.h"
+#include "chrome/browser/extensions/extension_pref_value_map.h"
#include "chrome/browser/extensions/extension_preference_api.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_processes_api.h"
@@ -81,6 +82,7 @@
#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/child_process_logging.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -154,6 +156,15 @@ static bool IsSyncableApp(const Extension& extension) {
} // namespace
+// static
+bool ExtensionService::PlatformAppRequiresSeparateDataDirectory() {
+#if defined(OS_MACOSX)
+ return true;
+#else
+ return false;
Robert Sesek 2012/02/09 18:43:59 Leave a TODO here.
sail 2012/02/10 00:13:18 I'm not sure what the plans are for other platform
+#endif
+}
+
ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData()
: background_page_ready(false),
being_upgraded(false),
@@ -2228,25 +2239,13 @@ void ExtensionService::OnExtensionInstalled(
extension, "Extensions.Permissions_Install");
}
- extension_prefs_->OnExtensionInstalled(
- extension,
- initial_enable ? Extension::ENABLED : Extension::DISABLED,
- from_webstore,
- page_ordinal);
-
- // Unpacked extensions default to allowing file access, but if that has been
- // overridden, don't reset the value.
- if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
- !extension_prefs_->HasAllowFileAccessSetting(id)) {
- extension_prefs_->SetAllowFileAccess(id, true);
+ SetupExtensionPrefs(
+ extension_prefs_, extension, from_webstore, page_ordinal, initial_enable);
+ if (initial_enable && PlatformAppRequiresSeparateDataDirectory()) {
+ SetupExtensionPrefsInSeparateDataDirectory(
+ extension, from_webstore, page_ordinal);
}
- // If the extension should automatically block network startup (e.g., it uses
- // the webRequest API), set the preference. Otherwise clear it, in case the
- // extension stopped using a relevant API.
- extension_prefs_->SetDelaysNetworkRequests(
- extension->id(), extension->ImplicitlyDelaysNetworkStartup());
-
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_INSTALLED,
content::Source<Profile>(profile_),
@@ -2707,3 +2706,54 @@ extensions::SocketController* ExtensionService::socket_controller() {
}
return socket_controller_;
}
+
+void ExtensionService::SetupExtensionPrefs(ExtensionPrefs* prefs,
+ const Extension* extension,
+ bool from_webstore,
+ const StringOrdinal& page_ordinal,
+ bool initial_enable) {
+ const std::string& id = extension->id();
+ prefs->OnExtensionInstalled(
+ extension,
+ initial_enable ? Extension::ENABLED : Extension::DISABLED,
+ from_webstore,
+ page_ordinal);
+
+ // Unpacked extensions default to allowing file access, but if that has been
+ // overridden, don't reset the value.
+ if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) &&
+ !prefs->HasAllowFileAccessSetting(id)) {
+ prefs->SetAllowFileAccess(id, true);
+ }
+
+ // If the extension should automatically block network startup (e.g., it uses
+ // the webRequest API), set the preference. Otherwise clear it, in case the
+ // extension stopped using a relevant API.
+ prefs->SetDelaysNetworkRequests(
+ id, extension->ImplicitlyDelaysNetworkStartup());
+}
+
+void ExtensionService::SetupExtensionPrefsInSeparateDataDirectory(
+ const Extension* extension,
+ bool from_webstore,
+ const StringOrdinal& page_ordinal) {
+ const std::string& id = extension->id();
+ FilePath data_dir = web_app::GetWebAppDataDirectory(
+ profile_->GetPath(), id, GURL(extension->launch_web_url()));
+ FilePath profile_path = data_dir.AppendASCII(chrome::kInitialProfile);
+ FilePath pref_path = profile_path.Append(chrome::kPreferencesFilename);
+ scoped_ptr<PrefService> prefs_service(PrefService::CreatePrefService(
+ pref_path, NULL, false));
+
+ ExtensionPrefValueMap map;
+ ExtensionPrefs::RegisterUserPrefs(prefs_service.get());
+ ExtensionPrefs extension_prefs(prefs_service.get(), install_directory_, &map);
+ extension_prefs.Init(false);
+
+ SetupExtensionPrefs(
+ &extension_prefs, extension, from_webstore, page_ordinal, true);
+ extension_prefs.AddGrantedPermissions(id, extension->GetActivePermissions());
+ extension_prefs.SetExtensionState(id, Extension::ENABLED);
+
+ prefs_service->CommitPendingWrite();
+}

Powered by Google App Engine
This is Rietveld 408576698