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