diff options
author | rockot <rockot@chromium.org> | 2015-07-29 10:58:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-29 17:58:47 +0000 |
commit | 494f0070b4e5d8d3970826039ac69db1897035b9 (patch) | |
tree | dfd2be8edf01208d0562c8dd6190a16cde149202 /extensions/shell/browser | |
parent | 7c5f055ea53ec83a866b27f1c5ed0363490390c3 (diff) | |
download | chromium_src-494f0070b4e5d8d3970826039ac69db1897035b9.zip chromium_src-494f0070b4e5d8d3970826039ac69db1897035b9.tar.gz chromium_src-494f0070b4e5d8d3970826039ac69db1897035b9.tar.bz2 |
Defer extension process creation until IO data initialized
When a new extension is loaded, profile data on the IO
thread (namely the extension's entry in InfoMap) is updated
asynchronously. This data is needed to fulfill
chrome-extension URL requests coming from the extension
process.
It's possible for the extension process to start up and
request a resource (e.g. its background page) before this
async update actually executes on the IO thread, causing
the resource request to fail.
This CL prevents the extension process from starting until
the necessary IO data has been successfully updated.
BUG=514459
R=asargent@chromium.org
Review URL: https://codereview.chromium.org/1257193003
Cr-Commit-Position: refs/heads/master@{#340917}
Diffstat (limited to 'extensions/shell/browser')
-rw-r--r-- | extensions/shell/browser/shell_extension_system.cc | 32 | ||||
-rw-r--r-- | extensions/shell/browser/shell_extension_system.h | 8 |
2 files changed, 27 insertions, 13 deletions
diff --git a/extensions/shell/browser/shell_extension_system.cc b/extensions/shell/browser/shell_extension_system.cc index e5f5a52..8e9c30a 100644 --- a/extensions/shell/browser/shell_extension_system.cc +++ b/extensions/shell/browser/shell_extension_system.cc @@ -29,8 +29,7 @@ using content::BrowserThread; namespace extensions { ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context) - : browser_context_(browser_context) { -} + : browser_context_(browser_context), weak_factory_(this) {} ShellExtensionSystem::~ShellExtensionSystem() { } @@ -59,7 +58,11 @@ const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) { ExtensionRegistry::Get(browser_context_)->AddEnabled(extension.get()); - RegisterExtensionWithRequestContexts(extension.get()); + RegisterExtensionWithRequestContexts( + extension.get(), + base::Bind( + &ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts, + weak_factory_.GetWeakPtr(), extension)); content::NotificationService::current()->Notify( extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, @@ -134,15 +137,13 @@ QuotaService* ShellExtensionSystem::quota_service() { } void ShellExtensionSystem::RegisterExtensionWithRequestContexts( - const Extension* extension) { - BrowserThread::PostTask(BrowserThread::IO, - FROM_HERE, - base::Bind(&InfoMap::AddExtension, - info_map(), - make_scoped_refptr(extension), - base::Time::Now(), - false, - false)); + const Extension* extension, + const base::Closure& callback) { + BrowserThread::PostTaskAndReply(BrowserThread::IO, FROM_HERE, + base::Bind(&InfoMap::AddExtension, info_map(), + make_scoped_refptr(extension), + base::Time::Now(), false, false), + callback); } void ShellExtensionSystem::UnregisterExtensionWithRequestContexts( @@ -163,4 +164,11 @@ scoped_ptr<ExtensionSet> ShellExtensionSystem::GetDependentExtensions( return make_scoped_ptr(new ExtensionSet()); } +void ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts( + scoped_refptr<Extension> extension) { + ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); + registry->AddReady(extension); + registry->TriggerOnReady(extension.get()); +} + } // namespace extensions diff --git a/extensions/shell/browser/shell_extension_system.h b/extensions/shell/browser/shell_extension_system.h index 2cbdd5f..3fd5d11 100644 --- a/extensions/shell/browser/shell_extension_system.h +++ b/extensions/shell/browser/shell_extension_system.h @@ -8,6 +8,7 @@ #include <vector> #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" #include "extensions/browser/extension_system.h" #include "extensions/common/one_shot_event.h" @@ -59,7 +60,8 @@ class ShellExtensionSystem : public ExtensionSystem { InfoMap* info_map() override; QuotaService* quota_service() override; void RegisterExtensionWithRequestContexts( - const Extension* extension) override; + const Extension* extension, + const base::Closure& callback) override; void UnregisterExtensionWithRequestContexts( const std::string& extension_id, const UnloadedExtensionInfo::Reason reason) override; @@ -69,6 +71,8 @@ class ShellExtensionSystem : public ExtensionSystem { const Extension* extension) override; private: + void OnExtensionRegisteredWithRequestContexts( + scoped_refptr<Extension> extension); content::BrowserContext* browser_context_; // Not owned. // Data to be accessed on the IO thread. Must outlive process_manager_. @@ -80,6 +84,8 @@ class ShellExtensionSystem : public ExtensionSystem { // Signaled when the extension system has completed its startup tasks. OneShotEvent ready_; + base::WeakPtrFactory<ShellExtensionSystem> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(ShellExtensionSystem); }; |