summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorirobert@chromium.org <irobert@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 21:06:17 +0000
committerirobert@chromium.org <irobert@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-02 21:06:17 +0000
commit404fb00891e6eb2c9ab9b4e2d2155d7db36a0b33 (patch)
treeebeec2448954efc6022ae45a1769db2e5fb318f7
parentfea7fc532d1314a531e1c1185c906a7b05e3d257 (diff)
downloadchromium_src-404fb00891e6eb2c9ab9b4e2d2155d7db36a0b33.zip
chromium_src-404fb00891e6eb2c9ab9b4e2d2155d7db36a0b33.tar.gz
chromium_src-404fb00891e6eb2c9ab9b4e2d2155d7db36a0b33.tar.bz2
Remove ExtensionService::GetInstalledAppForRenderer and SetInstalledAppForRenderer, since they do not make sense when multiple apps are in the same process. Replace them with the API ExtensionService::GetIsolatedAppForRenderer.
BUG=140856 Review URL: https://chromiumcodereview.appspot.com/10996049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159764 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_content_browser_client.cc11
-rw-r--r--chrome/browser/extensions/extension_service.cc29
-rw-r--r--chrome/browser/extensions/extension_service.h16
-rw-r--r--chrome/browser/extensions/isolated_app_browsertest.cc13
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc13
-rw-r--r--chrome/browser/profiles/profile_impl.cc16
-rw-r--r--chrome/browser/renderer_host/chrome_render_view_host_observer.cc9
-rw-r--r--chrome/test/base/testing_profile.cc8
8 files changed, 58 insertions, 57 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 8eae62d..fa09d65 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -468,10 +468,15 @@ std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if (extension_service) {
- extension = extension_service->GetInstalledAppForRenderer(
- child_process_id);
+ std::set<std::string> extension_ids =
+ extension_service->process_map()->
+ GetExtensionsInProcess(child_process_id);
+ if (!extension_ids.empty())
+ // Since All the apps in a process share the same storage partition,
+ // we can pick any of them to retrieve the storage partition id.
+ extension =
+ extension_service->extensions()->GetByID(*(extension_ids.begin()));
}
-
return GetStoragePartitionIdForExtension(browser_context, extension);
}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 8c20453..f882874 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -275,16 +275,25 @@ bool ExtensionService::IsInstalledApp(const GURL& url) const {
return !!GetInstalledApp(url);
}
-void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id,
- const Extension* app) {
- installed_app_hosts_[renderer_child_id] = app;
-}
-
-const Extension* ExtensionService::GetInstalledAppForRenderer(
+const Extension* ExtensionService::GetIsolatedAppForRenderer(
int renderer_child_id) const {
- InstalledAppMap::const_iterator i =
- installed_app_hosts_.find(renderer_child_id);
- return i == installed_app_hosts_.end() ? NULL : i->second;
+ 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 is_storage_isolated(),
+ // because it's common for there to be one extension in a process
+ // with is_storage_isolated() == false.
+ if (extension && extension->is_storage_isolated())
+ return extension;
+
+ return NULL;
}
// static
@@ -2458,8 +2467,6 @@ void ExtensionService::Observe(int type,
if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
break;
- installed_app_hosts_.erase(process->GetID());
-
process_map_.RemoveAllFromProcess(process->GetID());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 6e5ee21..2220fbc 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -180,13 +180,9 @@ class ExtensionService
// Returns whether the URL is from either a hosted or packaged app.
bool IsInstalledApp(const GURL& url) const;
- // Associates a renderer process with the given installed app.
- void SetInstalledAppForRenderer(int renderer_child_id,
- const extensions::Extension* app);
-
- // If the renderer is hosting an installed app, returns it, otherwise returns
- // NULL.
- const extensions::Extension* GetInstalledAppForRenderer(
+ // If the renderer is hosting an installed app with isolated storage,
+ // returns it, otherwise returns NULL.
+ const extensions::Extension* GetIsolatedAppForRenderer(
int renderer_child_id) const;
// Attempts to uninstall an extension from a given ExtensionService. Returns
@@ -760,12 +756,6 @@ class ExtensionService
// The map of extension IDs to their runtime data.
ExtensionRuntimeDataMap extension_runtime_data_;
- // Holds a map between renderer process IDs that are associated with an
- // installed app and their app.
- typedef std::map<int, scoped_refptr<const extensions::Extension> >
- InstalledAppMap;
- InstalledAppMap installed_app_hosts_;
-
// The full path to the directory where extensions are installed.
FilePath install_directory_;
diff --git a/chrome/browser/extensions/isolated_app_browsertest.cc b/chrome/browser/extensions/isolated_app_browsertest.cc
index 82b153f..266d5a4 100644
--- a/chrome/browser/extensions/isolated_app_browsertest.cc
+++ b/chrome/browser/extensions/isolated_app_browsertest.cc
@@ -53,10 +53,17 @@ class IsolatedAppTest : public ExtensionBrowserTest {
Profile::FromBrowserContext(contents->GetBrowserContext());
ExtensionService* service = profile->GetExtensionService();
if (service) {
- installed_app = service->GetInstalledAppForRenderer(
- contents->GetRenderProcessHost()->GetID());
+ std::set<std::string> extension_ids =
+ service->process_map()->GetExtensionsInProcess(
+ contents->GetRenderViewHost()->GetProcess()->GetID());
+ for (std::set<std::string>::iterator iter = extension_ids.begin();
+ iter != extension_ids.end(); ++iter) {
+ installed_app = service->extensions()->GetByID(*iter);
+ if (installed_app && installed_app->is_app())
+ return installed_app;
+ }
}
- return installed_app;
+ return NULL;
}
private:
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index a05c6dc..ddb5623 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -248,12 +248,13 @@ net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() {
net::URLRequestContextGetter*
OffTheRecordProfileImpl::GetRequestContextForRenderProcess(
int renderer_child_id) {
- if (GetExtensionService()) {
- const extensions::Extension* installed_app = GetExtensionService()->
- GetInstalledAppForRenderer(renderer_child_id);
- if (installed_app != NULL && installed_app->is_storage_isolated()) {
- return GetRequestContextForStoragePartition(installed_app->id());
- }
+ ExtensionService* extension_service =
+ extensions::ExtensionSystem::Get(this)->extension_service();
+ if (extension_service) {
+ const extensions::Extension* extension =
+ extension_service->GetIsolatedAppForRenderer(renderer_child_id);
+ if (extension)
+ return GetRequestContextForStoragePartition(extension->id());
}
content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 93f8489..8b0bfa4 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -677,10 +677,10 @@ net::URLRequestContextGetter* ProfileImpl::GetRequestContextForRenderProcess(
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(this)->extension_service();
if (extension_service) {
- const extensions::Extension* installed_app = extension_service->
- GetInstalledAppForRenderer(renderer_child_id);
- if (installed_app && installed_app->is_storage_isolated())
- return GetRequestContextForStoragePartition(installed_app->id());
+ const extensions::Extension* extension =
+ extension_service->GetIsolatedAppForRenderer(renderer_child_id);
+ if (extension)
+ return GetRequestContextForStoragePartition(extension->id());
}
content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
@@ -709,10 +709,10 @@ ProfileImpl::GetMediaRequestContextForRenderProcess(
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(this)->extension_service();
if (extension_service) {
- const extensions::Extension* installed_app = extension_service->
- GetInstalledAppForRenderer(renderer_child_id);
- if (installed_app && installed_app->is_storage_isolated())
- return io_data_.GetIsolatedMediaRequestContextGetter(installed_app->id());
+ const extensions::Extension* extension =
+ extension_service->GetIsolatedAppForRenderer(renderer_child_id);
+ if (extension)
+ return io_data_.GetIsolatedMediaRequestContextGetter(extension->id());
}
content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
diff --git a/chrome/browser/renderer_host/chrome_render_view_host_observer.cc b/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
index 05c0499..9d8e4cf 100644
--- a/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
+++ b/chrome/browser/renderer_host/chrome_render_view_host_observer.cc
@@ -92,15 +92,6 @@ void ChromeRenderViewHostObserver::InitRenderViewForExtensions() {
content::RenderProcessHost* process = render_view_host()->GetProcess();
- if (extension->is_app()) {
- // Though we already record the associated process ID for the renderer in
- // InitRenderViewHostForExtensions, the process might have crashed and been
- // restarted (hence the re-initialization), so we need to update that
- // mapping.
- profile_->GetExtensionService()->SetInstalledAppForRenderer(
- process->GetID(), extension);
- }
-
// Some extensions use chrome:// URLs.
Extension::Type type = extension->GetType();
if (type == Extension::TYPE_EXTENSION ||
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 9f34ca3..ffffe3f 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -613,10 +613,10 @@ net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(this)->extension_service();
if (extension_service) {
- const extensions::Extension* installed_app = extension_service->
- GetInstalledAppForRenderer(renderer_child_id);
- if (installed_app != NULL && installed_app->is_storage_isolated())
- return GetRequestContextForStoragePartition(installed_app->id());
+ const extensions::Extension* extension =
+ extension_service->GetIsolatedAppForRenderer(renderer_child_id);
+ if (extension)
+ return GetRequestContextForStoragePartition(extension->id());
}
content::RenderProcessHost* rph = content::RenderProcessHost::FromID(