Convert ExtensionFunctionDispatcher from Profile to BrowserContext

Part of the AppShell extensions system refactor project.

BUG=309909
TEST=browser_tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238431 0039d316-1c4b-4281-b951-d872f2087c98
parent a4869cda
...@@ -54,7 +54,7 @@ TestNotifyPassFunction::~TestNotifyPassFunction() {} ...@@ -54,7 +54,7 @@ TestNotifyPassFunction::~TestNotifyPassFunction() {}
bool TestNotifyPassFunction::RunImpl() { bool TestNotifyPassFunction::RunImpl() {
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_TEST_PASSED, chrome::NOTIFICATION_EXTENSION_TEST_PASSED,
content::Source<Profile>(dispatcher()->profile()), content::Source<content::BrowserContext>(dispatcher()->browser_context()),
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
return true; return true;
} }
...@@ -66,7 +66,7 @@ bool TestNotifyFailFunction::RunImpl() { ...@@ -66,7 +66,7 @@ bool TestNotifyFailFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(params.get()); EXTENSION_FUNCTION_VALIDATE(params.get());
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_TEST_FAILED, chrome::NOTIFICATION_EXTENSION_TEST_FAILED,
content::Source<Profile>(dispatcher()->profile()), content::Source<content::BrowserContext>(dispatcher()->browser_context()),
content::Details<std::string>(&params->message)); content::Details<std::string>(&params->message));
return true; return true;
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/extension_web_ui.h" #include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h" #include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "chrome/common/extensions/extension_messages.h" #include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_set.h" #include "chrome/common/extensions/extension_set.h"
...@@ -42,6 +41,7 @@ ...@@ -42,6 +41,7 @@
using extensions::Extension; using extensions::Extension;
using extensions::ExtensionAPI; using extensions::ExtensionAPI;
using extensions::ExtensionSystem;
using extensions::Feature; using extensions::Feature;
using content::RenderViewHost; using content::RenderViewHost;
...@@ -50,7 +50,7 @@ namespace { ...@@ -50,7 +50,7 @@ namespace {
void LogSuccess(const std::string& extension_id, void LogSuccess(const std::string& extension_id,
const std::string& api_name, const std::string& api_name,
scoped_ptr<base::ListValue> args, scoped_ptr<base::ListValue> args,
Profile* profile) { content::BrowserContext* browser_context) {
// The ActivityLog can only be accessed from the main (UI) thread. If we're // The ActivityLog can only be accessed from the main (UI) thread. If we're
// running on the wrong thread, re-dispatch from the main thread. // running on the wrong thread, re-dispatch from the main thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
...@@ -60,10 +60,10 @@ void LogSuccess(const std::string& extension_id, ...@@ -60,10 +60,10 @@ void LogSuccess(const std::string& extension_id,
extension_id, extension_id,
api_name, api_name,
base::Passed(&args), base::Passed(&args),
profile)); browser_context));
} else { } else {
extensions::ActivityLog* activity_log = extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(browser_context);
scoped_refptr<extensions::Action> action = scoped_refptr<extensions::Action> action =
new extensions::Action(extension_id, new extensions::Action(extension_id,
base::Time::Now(), base::Time::Now(),
...@@ -235,14 +235,13 @@ void ExtensionFunctionDispatcher::ResetFunctions() { ...@@ -235,14 +235,13 @@ void ExtensionFunctionDispatcher::ResetFunctions() {
// static // static
void ExtensionFunctionDispatcher::DispatchOnIOThread( void ExtensionFunctionDispatcher::DispatchOnIOThread(
extensions::InfoMap* extension_info_map, extensions::InfoMap* extension_info_map,
void* profile, void* browser_context,
int render_process_id, int render_process_id,
base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, base::WeakPtr<ChromeRenderMessageFilter> ipc_sender,
int routing_id, int routing_id,
const ExtensionHostMsg_Request_Params& params) { const ExtensionHostMsg_Request_Params& params) {
const Extension* extension = const Extension* extension =
extension_info_map->extensions().GetByID(params.extension_id); extension_info_map->extensions().GetByID(params.extension_id);
Profile* profile_cast = static_cast<Profile*>(profile);
ExtensionFunction::ResponseCallback callback( ExtensionFunction::ResponseCallback callback(
base::Bind(&IOThreadResponseCallback, ipc_sender, routing_id, base::Bind(&IOThreadResponseCallback, ipc_sender, routing_id,
...@@ -252,7 +251,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -252,7 +251,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
CreateExtensionFunction(params, extension, render_process_id, CreateExtensionFunction(params, extension, render_process_id,
extension_info_map->process_map(), extension_info_map->process_map(),
g_global_io_data.Get().api.get(), g_global_io_data.Get().api.get(),
profile, callback)); browser_context, callback));
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) if (!function.get())
...@@ -281,7 +280,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -281,7 +280,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
LogSuccess(extension->id(), LogSuccess(extension->id(),
params.name, params.name,
args.Pass(), args.Pass(),
profile_cast); static_cast<content::BrowserContext*>(browser_context));
function->Run(); function->Run();
} else { } else {
function->OnQuotaExceeded(violation_error); function->OnQuotaExceeded(violation_error);
...@@ -291,7 +290,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -291,7 +290,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
Delegate* delegate) Delegate* delegate)
: profile_(Profile::FromBrowserContext(browser_context)), : browser_context_(browser_context),
delegate_(delegate) { delegate_(delegate) {
} }
...@@ -322,11 +321,11 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -322,11 +321,11 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
const ExtensionFunction::ResponseCallback& callback) { const ExtensionFunction::ResponseCallback& callback) {
// TODO(yzshen): There is some shared logic between this method and // TODO(yzshen): There is some shared logic between this method and
// DispatchOnIOThread(). It is nice to deduplicate. // DispatchOnIOThread(). It is nice to deduplicate.
ExtensionService* service = profile()->GetExtensionService(); ExtensionSystem* extension_system =
extensions::ProcessManager* process_manager = ExtensionSystem::GetForBrowserContext(browser_context_);
extensions::ExtensionSystem::Get(profile())->process_manager(); ExtensionService* service = extension_system->extension_service();
extensions::ProcessMap* process_map = service->process_map(); extensions::ProcessMap* process_map = service->process_map();
if (!service || !process_map) if (!process_map)
return; return;
const Extension* extension = service->extensions()->GetByID( const Extension* extension = service->extensions()->GetByID(
...@@ -335,11 +334,13 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -335,11 +334,13 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
extension = service->extensions()->GetHostedAppByURL(params.source_url); extension = service->extensions()->GetHostedAppByURL(params.source_url);
scoped_refptr<ExtensionFunction> function( scoped_refptr<ExtensionFunction> function(
CreateExtensionFunction(params, extension, CreateExtensionFunction(params,
extension,
render_view_host->GetProcess()->GetID(), render_view_host->GetProcess()->GetID(),
*(service->process_map()), *process_map,
extensions::ExtensionAPI::GetSharedInstance(), extensions::ExtensionAPI::GetSharedInstance(),
profile(), callback)); browser_context_,
callback));
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) if (!function.get())
...@@ -353,7 +354,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -353,7 +354,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
} }
function_ui->SetRenderViewHost(render_view_host); function_ui->SetRenderViewHost(render_view_host);
function_ui->set_dispatcher(AsWeakPtr()); function_ui->set_dispatcher(AsWeakPtr());
function_ui->set_context(profile_); function_ui->set_context(browser_context_);
function->set_include_incognito(extension_util::CanCrossIncognito(extension, function->set_include_incognito(extension_util::CanCrossIncognito(extension,
service)); service));
...@@ -368,7 +369,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -368,7 +369,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
if (violation_error.empty()) { if (violation_error.empty()) {
// See crbug.com/39178. // See crbug.com/39178.
ExternalProtocolHandler::PermitLaunchUrl(); ExternalProtocolHandler::PermitLaunchUrl();
LogSuccess(extension->id(), params.name, args.Pass(), profile()); LogSuccess(extension->id(), params.name, args.Pass(), browser_context_);
function->Run(); function->Run();
} else { } else {
function->OnQuotaExceeded(violation_error); function->OnQuotaExceeded(violation_error);
...@@ -385,12 +386,12 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -385,12 +386,12 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
// now, largely for simplicity's sake. This is OK because currently, only // now, largely for simplicity's sake. This is OK because currently, only
// the webRequest API uses IOThreadExtensionFunction, and that API is not // the webRequest API uses IOThreadExtensionFunction, and that API is not
// compatible with lazy background pages. // compatible with lazy background pages.
process_manager->IncrementLazyKeepaliveCount(extension); extension_system->process_manager()->IncrementLazyKeepaliveCount(extension);
} }
void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
const Extension* extension) { const Extension* extension) {
extensions::ExtensionSystem::Get(profile())->process_manager()-> ExtensionSystem::GetForBrowserContext(browser_context_)->process_manager()->
DecrementLazyKeepaliveCount(extension); DecrementLazyKeepaliveCount(extension);
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "url/gurl.h" #include "url/gurl.h"
class ChromeRenderMessageFilter; class ChromeRenderMessageFilter;
class Profile;
struct ExtensionHostMsg_Request_Params; struct ExtensionHostMsg_Request_Params;
namespace content { namespace content {
...@@ -119,8 +118,8 @@ class ExtensionFunctionDispatcher ...@@ -119,8 +118,8 @@ class ExtensionFunctionDispatcher
// a response (if any) to the extension. // a response (if any) to the extension.
void OnExtensionFunctionCompleted(const extensions::Extension* extension); void OnExtensionFunctionCompleted(const extensions::Extension* extension);
// The profile that this dispatcher is associated with. // The BrowserContext that this dispatcher is associated with.
Profile* profile() { return profile_; } content::BrowserContext* browser_context() { return browser_context_; }
private: private:
// For a given RenderViewHost instance, UIThreadResponseCallbackWrapper // For a given RenderViewHost instance, UIThreadResponseCallbackWrapper
...@@ -157,7 +156,7 @@ class ExtensionFunctionDispatcher ...@@ -157,7 +156,7 @@ class ExtensionFunctionDispatcher
static void SendAccessDenied( static void SendAccessDenied(
const ExtensionFunction::ResponseCallback& callback); const ExtensionFunction::ResponseCallback& callback);
Profile* profile_; content::BrowserContext* browser_context_;
Delegate* delegate_; Delegate* delegate_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment