Skip to content

Commit

Permalink
app_shell: Extract extension runtime data from ExtensionService
Browse files Browse the repository at this point in the history
This allows ExtensionHost to use the data when there is no ExtensionService, such as when running app_shell.

BUG=332982
TEST=Added unit test, existing extensions browser tests
TBR=msw@chromium.org for mechanical change to chrome/browser/ui/views/

Review URL: https://codereview.chromium.org/131743021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246449 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamescook@chromium.org committed Jan 22, 2014
1 parent e18b1c8 commit 45f5b7d
Show file tree
Hide file tree
Showing 25 changed files with 430 additions and 142 deletions.
7 changes: 7 additions & 0 deletions apps/shell/shell_extension_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "extensions/browser/info_map.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/runtime_data.h"

using content::BrowserContext;
using content::BrowserThread;
Expand Down Expand Up @@ -77,6 +78,8 @@ void ShellExtensionSystem::Shutdown() {
}

void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
runtime_data_.reset(
new RuntimeData(ExtensionRegistry::Get(browser_context_)));
lazy_background_task_queue_.reset(
new LazyBackgroundTaskQueue(browser_context_));
event_router_.reset(
Expand All @@ -88,6 +91,10 @@ ExtensionService* ShellExtensionSystem::extension_service() {
return NULL;
}

RuntimeData* ShellExtensionSystem::runtime_data() {
return runtime_data_.get();
}

ManagementPolicy* ShellExtensionSystem::management_policy() {
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions apps/shell/shell_extension_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ShellExtensionSystem : public ExtensionSystem {
// ExtensionSystem implementation:
virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE;
virtual ExtensionService* extension_service() OVERRIDE;
virtual RuntimeData* runtime_data() OVERRIDE;
virtual ManagementPolicy* management_policy() OVERRIDE;
virtual UserScriptMaster* user_script_master() OVERRIDE;
virtual ProcessManager* process_manager() OVERRIDE;
Expand All @@ -67,6 +68,7 @@ class ShellExtensionSystem : public ExtensionSystem {
// Data to be accessed on the IO thread. Must outlive process_manager_.
scoped_refptr<InfoMap> info_map_;

scoped_ptr<RuntimeData> runtime_data_;
scoped_ptr<LazyBackgroundTaskQueue> lazy_background_task_queue_;
scoped_ptr<EventRouter> event_router_;
scoped_ptr<ProcessManager> process_manager_;
Expand Down
2 changes: 2 additions & 0 deletions apps/shell/shell_extensions_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "extensions/browser/app_sorting.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry_factory.h"

using content::BrowserContext;

Expand Down Expand Up @@ -127,6 +128,7 @@ std::vector<BrowserContextKeyedServiceFactory*>
ShellExtensionsBrowserClient::GetExtensionSystemDependencies() {
std::vector<BrowserContextKeyedServiceFactory*> depends_on;
depends_on.push_back(ExtensionPrefsFactory::GetInstance());
depends_on.push_back(ExtensionRegistryFactory::GetInstance());
return depends_on;
}

Expand Down
16 changes: 9 additions & 7 deletions chrome/browser/automation/automation_provider_observers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "content/public/common/process_type.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest.h"
Expand Down Expand Up @@ -571,10 +572,10 @@ void ExtensionUninstallObserver::Observe(
}

ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver(
extensions::ProcessManager* manager, ExtensionService* service,
AutomationProvider* automation, IPC::Message* reply_message)
: manager_(manager),
service_(service),
extensions::ExtensionSystem* extension_system,
AutomationProvider* automation,
IPC::Message* reply_message)
: extension_system_(extension_system),
automation_(automation->AsWeakPtr()),
reply_message_(reply_message),
extension_(NULL) {
Expand Down Expand Up @@ -609,7 +610,8 @@ void ExtensionReadyNotificationObserver::Observe(
case content::NOTIFICATION_LOAD_STOP:
// Only continue on with this method if our extension has been loaded
// and all the extension views have stopped loading.
if (!extension_ || !DidExtensionViewsStopLoading(manager_))
if (!extension_ ||
!DidExtensionViewsStopLoading(extension_system_->process_manager()))
return;
break;
case chrome::NOTIFICATION_EXTENSION_LOADED: {
Expand All @@ -621,13 +623,13 @@ void ExtensionReadyNotificationObserver::Observe(
!extensions::Manifest::IsUnpackedLocation(location))
return;
extension_ = loaded_extension;
if (!DidExtensionViewsStopLoading(manager_))
if (!DidExtensionViewsStopLoading(extension_system_->process_manager()))
return;
// For some reason, the background extension view is not yet
// created at this point so just checking whether all extension views
// are loaded is not sufficient. If background page is not ready,
// we wait for NOTIFICATION_LOAD_STOP.
if (!service_->IsBackgroundPageReady(extension_))
if (!extension_system_->runtime_data()->IsBackgroundPageReady(extension_))
return;
break;
}
Expand Down
13 changes: 6 additions & 7 deletions chrome/browser/automation/automation_provider_observers.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

class AutomationProvider;
class Browser;
class ExtensionService;
class Notification;
class Profile;
class SavePackage;
Expand All @@ -76,6 +75,7 @@ class WebContents;

namespace extensions {
class Extension;
class ExtensionSystem;
class ProcessManager;
}

Expand Down Expand Up @@ -327,10 +327,10 @@ class ExtensionReadyNotificationObserver
: public content::NotificationObserver {
public:
// Creates an observer that replies using the JSON automation interface.
ExtensionReadyNotificationObserver(extensions::ProcessManager* manager,
ExtensionService* service,
AutomationProvider* automation,
IPC::Message* reply_message);
ExtensionReadyNotificationObserver(
extensions::ExtensionSystem* extension_system,
AutomationProvider* automation,
IPC::Message* reply_message);
virtual ~ExtensionReadyNotificationObserver();

// Overridden from content::NotificationObserver:
Expand All @@ -342,8 +342,7 @@ class ExtensionReadyNotificationObserver
void Init();

content::NotificationRegistrar registrar_;
extensions::ProcessManager* manager_;
ExtensionService* service_;
extensions::ExtensionSystem* extension_system_;
base::WeakPtr<AutomationProvider> automation_;
scoped_ptr<IPC::Message> reply_message_;
const extensions::Extension* extension_;
Expand Down
26 changes: 11 additions & 15 deletions chrome/browser/automation/testing_automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3446,15 +3446,13 @@ void TestingAutomationProvider::InstallExtension(
}
args->GetBoolean("from_webstore", &from_webstore);

ExtensionService* service = extensions::ExtensionSystem::Get(
browser->profile())->extension_service();
extensions::ProcessManager* manager =
extensions::ExtensionSystem::Get(browser->profile())->process_manager();
if (service && manager) {
extensions::ExtensionSystem* system =
extensions::ExtensionSystem::Get(browser->profile());
ExtensionService* service = system->extension_service();
if (service) {
// The observer will delete itself when done.
new ExtensionReadyNotificationObserver(
manager,
service,
system,
this,
reply_message);

Expand All @@ -3480,7 +3478,7 @@ void TestingAutomationProvider::InstallExtension(
}
} else {
AutomationJSONReply(this, reply_message).SendError(
"Extensions service/process manager is not available");
"Extensions service is not available");
}
}

Expand Down Expand Up @@ -3660,21 +3658,19 @@ void TestingAutomationProvider::SetExtensionStateById(
return;
}

ExtensionService* service = extensions::ExtensionSystem::Get(
browser->profile())->extension_service();
extensions::ProcessManager* manager =
extensions::ExtensionSystem::Get(browser->profile())->process_manager();
extensions::ExtensionSystem* system =
extensions::ExtensionSystem::Get(browser->profile());
ExtensionService* service = system->extension_service();
if (!service) {
AutomationJSONReply(this, reply_message)
.SendError("No extensions service or process manager.");
.SendError("No extensions service.");
return;
}

if (enable) {
if (!service->IsExtensionEnabled(extension->id())) {
new ExtensionReadyNotificationObserver(
manager,
service,
system,
this,
reply_message);
service->EnableExtension(extension->id());
Expand Down
17 changes: 10 additions & 7 deletions chrome/browser/extensions/api/web_request/web_request_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
#include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h"
#include "chrome/browser/extensions/extension_renderer_state.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_warning_service.h"
#include "chrome/browser/extensions/extension_warning_set.h"
Expand All @@ -49,7 +48,9 @@
#include "content/public/browser/user_metrics.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/event_filtering_info.h"
#include "extensions/common/extension.h"
Expand Down Expand Up @@ -2361,17 +2362,19 @@ bool WebRequestHandlerBehaviorChangedFunction::RunImpl() {

void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) {
Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
if (!profile || !profile->GetExtensionService())
if (!profile)
return;

bool adblock = false;
bool adblock_plus = false;
bool other = false;
const extensions::ExtensionSet* extensions =
profile->GetExtensionService()->extensions();
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if (profile->GetExtensionService()->HasUsedWebRequest(it->get())) {
const extensions::ExtensionSet& extensions =
extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
extensions::RuntimeData* runtime_data =
extensions::ExtensionSystem::Get(profile)->runtime_data();
for (extensions::ExtensionSet::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
if (runtime_data->HasUsedWebRequest(it->get())) {
if ((*it)->name().find("Adblock Plus") != std::string::npos) {
adblock_plus = true;
} else if ((*it)->name().find("AdBlock") != std::string::npos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/web_request/web_request_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_warning_set.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/runtime_data.h"
#include "net/base/net_log.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
Expand Down Expand Up @@ -1264,9 +1264,11 @@ void NotifyWebRequestAPIUsed(
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return;

if (profile->GetExtensionService()->HasUsedWebRequest(extension.get()))
extensions::RuntimeData* runtime_data =
extensions::ExtensionSystem::Get(profile)->runtime_data();
if (runtime_data->HasUsedWebRequest(extension.get()))
return;
profile->GetExtensionService()->SetHasUsedWebRequest(extension.get(), true);
runtime_data->SetHasUsedWebRequest(extension.get(), true);

content::BrowserContext* browser_context = profile;
for (content::RenderProcessHost::iterator it =
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/extensions/extension_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "extensions/browser/extension_error.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h"
Expand Down Expand Up @@ -323,9 +324,9 @@ void ExtensionHost::DocumentAvailableInMainFrame() {

void ExtensionHost::OnDocumentAvailable() {
DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
ExtensionService* service = GetExtensionService();
if (service)
service->SetBackgroundPageReady(extension_);
ExtensionSystem::GetForBrowserContext(browser_context_)
->runtime_data()
->SetBackgroundPageReady(extension_, true);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::Source<const Extension>(extension_),
Expand Down
Loading

0 comments on commit 45f5b7d

Please sign in to comment.