summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 15:06:45 +0000
committerrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 15:06:45 +0000
commit659be688fc57bccd965cb8f7a7e6b3f7f248b9a7 (patch)
tree1ebb50ab7b35f2ae7620d90fb9ebb47347f75e3f
parent065b657bd16bca7115b20774a154808184848045 (diff)
downloadchromium_src-659be688fc57bccd965cb8f7a7e6b3f7f248b9a7.zip
chromium_src-659be688fc57bccd965cb8f7a7e6b3f7f248b9a7.tar.gz
chromium_src-659be688fc57bccd965cb8f7a7e6b3f7f248b9a7.tar.bz2
Pull AsyncApiFunction out of src/chrome
AsyncApiFunction now inherits UIThreadExtensionFunction directly, rather than depending on ChromeAsyncExtensionFunction. It's also been moved from chrome/browser/extensions/api/api_function.{h,cc} to extensions/browser/api/async_api_function.{h,cc}. With the exception of notifications API functions, anything which previously depended on AsyncApiFunction's inheritance of ChromeAsyncExtensionFunction was doing so only for GetProfile. In all cases, GetProfile() has been replaced with ExtensionFunction::browser_context() (renamed from context()). Finally, ApiFunction has been removed since it was identical to ChromeAsyncExtensionFunction. BUG=346949 TBR=dmazzoni@chromium.org,mfoltz@chromium.org,fgorski@chromium.org,courage@chromium.org,dewittj@chromium.org,rpaquay@chromium.org,kalman@chromium.org Review URL: https://codereview.chromium.org/177003015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254113 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.cc59
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_api.h15
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc24
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h8
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc21
-rw-r--r--chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h4
-rw-r--r--chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h4
-rw-r--r--chrome/browser/extensions/api/cast_channel/cast_channel_api.cc5
-rw-r--r--chrome/browser/extensions/api/cast_channel/cast_channel_api.h3
-rw-r--r--chrome/browser/extensions/api/diagnostics/diagnostics_api.h2
-rw-r--r--chrome/browser/extensions/api/dial/dial_api.cc4
-rw-r--r--chrome/browser/extensions/api/dial/dial_api.h2
-rw-r--r--chrome/browser/extensions/api/dial/dial_api_factory.cc5
-rw-r--r--chrome/browser/extensions/api/dial/dial_api_factory.h5
-rw-r--r--chrome/browser/extensions/api/dial/dial_apitest.cc3
-rw-r--r--chrome/browser/extensions/api/gcm/gcm_api.cc4
-rw-r--r--chrome/browser/extensions/api/hid/hid_api.cc4
-rw-r--r--chrome/browser/extensions/api/hid/hid_api.h2
-rw-r--r--chrome/browser/extensions/api/identity/identity_apitest.cc2
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_api.cc4
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_api.h4
-rw-r--r--chrome/browser/extensions/api/serial/serial_api.cc6
-rw-r--r--chrome/browser/extensions/api/serial/serial_api.h6
-rw-r--r--chrome/browser/extensions/api/socket/socket_api.cc3
-rw-r--r--chrome/browser/extensions/api/socket/socket_api.h12
-rw-r--r--chrome/browser/extensions/api/socket/socket_api_unittest.cc7
-rw-r--r--chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc5
-rw-r--r--chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api_unittest.cc10
-rw-r--r--chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h2
-rw-r--r--chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.cc7
-rw-r--r--chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api_unittest.cc19
-rw-r--r--chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h2
-rw-r--r--chrome/browser/extensions/api/sockets_udp/sockets_udp_api.cc5
-rw-r--r--chrome/browser/extensions/api/sockets_udp/sockets_udp_api_unittest.cc10
-rw-r--r--chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h2
-rw-r--r--chrome/browser/extensions/api/storage/storage_api.cc2
-rw-r--r--chrome/browser/extensions/api/usb/usb_api.cc3
-rw-r--r--chrome/browser/extensions/api/usb/usb_api.h2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
-rw-r--r--chrome/browser/extensions/extension_function_test_utils.cc2
-rw-r--r--chrome/chrome_browser_extensions.gypi2
-rw-r--r--extensions/browser/api/async_api_function.cc (renamed from chrome/browser/extensions/api/api_function.cc)39
-rw-r--r--extensions/browser/api/async_api_function.h (renamed from chrome/browser/extensions/api/api_function.h)21
-rw-r--r--extensions/browser/extension_function.h6
-rw-r--r--extensions/extensions.gyp2
45 files changed, 177 insertions, 184 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
index 42a51a3..ac0b774 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -11,7 +11,6 @@
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
#include "chrome/browser/extensions/event_names.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/bluetooth.h"
#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h"
#include "content/public/browser/browser_thread.h"
@@ -93,8 +92,8 @@ BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) {
}
BluetoothAPI::BluetoothAPI(BrowserContext* context)
- : profile_(Profile::FromBrowserContext(context)) {
- ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
+ : browser_context_(context) {
+ ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver(
this, bluetooth::OnAdapterStateChanged::kEventName);
}
@@ -103,13 +102,15 @@ BluetoothAPI::~BluetoothAPI() {
ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() {
if (!bluetooth_event_router_)
- bluetooth_event_router_.reset(new ExtensionBluetoothEventRouter(profile_));
+ bluetooth_event_router_.reset(
+ new ExtensionBluetoothEventRouter(browser_context_));
return bluetooth_event_router_.get();
}
void BluetoothAPI::Shutdown() {
- ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+ ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver(
+ this);
}
void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) {
@@ -144,7 +145,7 @@ bool BluetoothAddProfileFunction::RunImpl() {
uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid);
- if (GetEventRouter(GetProfile())->HasProfile(uuid_)) {
+ if (GetEventRouter(browser_context())->HasProfile(uuid_)) {
SetError(kProfileAlreadyRegistered);
return false;
}
@@ -192,7 +193,7 @@ void BluetoothAddProfileFunction::OnProfileRegistered(
return;
}
- if (GetEventRouter(GetProfile())->HasProfile(uuid_)) {
+ if (GetEventRouter(browser_context())->HasProfile(uuid_)) {
bluetooth_profile->Unregister();
SetError(kProfileAlreadyRegistered);
SendResponse(false);
@@ -201,11 +202,11 @@ void BluetoothAddProfileFunction::OnProfileRegistered(
bluetooth_profile->SetConnectionCallback(
base::Bind(&ExtensionBluetoothEventRouter::DispatchConnectionEvent,
- base::Unretained(GetEventRouter(GetProfile())),
+ base::Unretained(GetEventRouter(browser_context())),
extension_id(),
uuid_));
- GetEventRouter(GetProfile())->AddProfile(
- uuid_, extension_id(), bluetooth_profile);
+ GetEventRouter(browser_context())
+ ->AddProfile(uuid_, extension_id(), bluetooth_profile);
SendResponse(true);
}
@@ -221,12 +222,12 @@ bool BluetoothRemoveProfileFunction::RunImpl() {
std::string uuid =
device::bluetooth_utils::CanonicalUuid(params->profile.uuid);
- if (!GetEventRouter(GetProfile())->HasProfile(uuid)) {
+ if (!GetEventRouter(browser_context())->HasProfile(uuid)) {
SetError(kProfileNotFound);
return false;
}
- GetEventRouter(GetProfile())->RemoveProfile(uuid);
+ GetEventRouter(browser_context())->RemoveProfile(uuid);
return true;
}
@@ -277,7 +278,7 @@ void BluetoothGetDevicesFunction::DispatchDeviceSearchResult(
const BluetoothDevice& device) {
bluetooth::Device extension_device;
bluetooth::BluetoothDeviceToApiDevice(device, &extension_device);
- GetEventRouter(GetProfile())->DispatchDeviceEvent(
+ GetEventRouter(browser_context())->DispatchDeviceEvent(
extensions::event_names::kBluetoothOnDeviceSearchResult,
extension_device);
@@ -292,7 +293,7 @@ void BluetoothGetDevicesFunction::FinishDeviceSearch() {
scoped_ptr<extensions::Event> event(new extensions::Event(
extensions::event_names::kBluetoothOnDeviceSearchFinished, args.Pass()));
- extensions::ExtensionSystem::Get(GetProfile())
+ extensions::ExtensionSystem::Get(browser_context())
->event_router()
->BroadcastEvent(event.Pass());
@@ -410,7 +411,7 @@ bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) {
options.profile.uuid);
BluetoothProfile* bluetooth_profile =
- GetEventRouter(GetProfile())->GetProfile(uuid);
+ GetEventRouter(browser_context())->GetProfile(uuid);
if (!bluetooth_profile) {
SetError(kProfileNotFound);
SendResponse(false);
@@ -429,7 +430,7 @@ bool BluetoothDisconnectFunction::RunImpl() {
scoped_ptr<Disconnect::Params> params(Disconnect::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
const bluetooth::DisconnectOptions& options = params->options;
- return GetEventRouter(GetProfile())->ReleaseSocket(options.socket.id);
+ return GetEventRouter(browser_context())->ReleaseSocket(options.socket.id);
}
BluetoothReadFunction::BluetoothReadFunction() : success_(false) {}
@@ -440,7 +441,7 @@ bool BluetoothReadFunction::Prepare() {
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
const bluetooth::ReadOptions& options = params->options;
- socket_ = GetEventRouter(GetProfile())->GetSocket(options.socket.id);
+ socket_ = GetEventRouter(browser_context())->GetSocket(options.socket.id);
if (socket_.get() == NULL) {
SetError(kSocketNotFoundError);
return false;
@@ -488,7 +489,7 @@ bool BluetoothWriteFunction::Prepare() {
int socket_id;
EXTENSION_FUNCTION_VALIDATE(socket->GetInteger("id", &socket_id));
- socket_ = GetEventRouter(GetProfile())->GetSocket(socket_id);
+ socket_ = GetEventRouter(browser_context())->GetSocket(socket_id);
if (socket_.get() == NULL) {
SetError(kSocketNotFoundError);
return false;
@@ -634,20 +635,20 @@ void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
void BluetoothStartDiscoveryFunction::OnErrorCallback() {
SetError(kStartDiscoveryFailed);
- GetEventRouter(GetProfile())->SetResponsibleForDiscovery(false);
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(false);
SendResponse(false);
- GetEventRouter(GetProfile())->OnListenerRemoved();
+ GetEventRouter(browser_context())->OnListenerRemoved();
}
bool BluetoothStartDiscoveryFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) {
- GetEventRouter(GetProfile())->SetSendDiscoveryEvents(true);
+ GetEventRouter(browser_context())->SetSendDiscoveryEvents(true);
// If this profile is already discovering devices, there should be nothing
// else to do.
- if (!GetEventRouter(GetProfile())->IsResponsibleForDiscovery()) {
- GetEventRouter(GetProfile())->SetResponsibleForDiscovery(true);
- GetEventRouter(GetProfile())->OnListenerAdded();
+ if (!GetEventRouter(browser_context())->IsResponsibleForDiscovery()) {
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(true);
+ GetEventRouter(browser_context())->OnListenerAdded();
adapter->StartDiscovering(
base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
@@ -658,20 +659,20 @@ bool BluetoothStartDiscoveryFunction::DoWork(
void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
SendResponse(true);
- GetEventRouter(GetProfile())->OnListenerRemoved();
+ GetEventRouter(browser_context())->OnListenerRemoved();
}
void BluetoothStopDiscoveryFunction::OnErrorCallback() {
SetError(kStopDiscoveryFailed);
- GetEventRouter(GetProfile())->SetResponsibleForDiscovery(true);
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(true);
SendResponse(false);
- GetEventRouter(GetProfile())->OnListenerRemoved();
+ GetEventRouter(browser_context())->OnListenerRemoved();
}
bool BluetoothStopDiscoveryFunction::DoWork(
scoped_refptr<BluetoothAdapter> adapter) {
- GetEventRouter(GetProfile())->SetSendDiscoveryEvents(false);
- if (GetEventRouter(GetProfile())->IsResponsibleForDiscovery()) {
+ GetEventRouter(browser_context())->SetSendDiscoveryEvents(false);
+ if (GetEventRouter(browser_context())->IsResponsibleForDiscovery()) {
adapter->StopDiscovering(
base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
index e7b37ae..552b7dc 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h
@@ -9,12 +9,17 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h"
#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
#include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_profile.h"
+#include "extensions/browser/api/async_api_function.h"
#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_function.h"
+
+namespace content {
+class BrowserContext;
+}
namespace device {
@@ -57,7 +62,7 @@ class BluetoothAPI : public ProfileKeyedAPI, public EventRouter::Observer {
static const bool kServiceRedirectedInIncognito = true;
static const bool kServiceIsNULLWhileTesting = true;
- Profile* profile_;
+ content::BrowserContext* browser_context_;
// Created lazily on first access.
scoped_ptr<ExtensionBluetoothEventRouter> bluetooth_event_router_;
@@ -65,7 +70,7 @@ class BluetoothAPI : public ProfileKeyedAPI, public EventRouter::Observer {
namespace api {
-class BluetoothAddProfileFunction : public ChromeAsyncExtensionFunction {
+class BluetoothAddProfileFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.addProfile", BLUETOOTH_ADDPROFILE)
@@ -85,7 +90,7 @@ class BluetoothAddProfileFunction : public ChromeAsyncExtensionFunction {
std::string uuid_;
};
-class BluetoothRemoveProfileFunction : public ChromeSyncExtensionFunction {
+class BluetoothRemoveProfileFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.removeProfile",
BLUETOOTH_REMOVEPROFILE)
@@ -169,7 +174,7 @@ class BluetoothConnectFunction : public BluetoothExtensionFunction {
void OnErrorCallback();
};
-class BluetoothDisconnectFunction : public ChromeSyncExtensionFunction {
+class BluetoothDisconnectFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.disconnect", BLUETOOTH_DISCONNECT)
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
index d0126f8..908a792 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h"
#include "chrome/browser/extensions/event_names.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/bluetooth.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
@@ -44,17 +43,19 @@ struct ExtensionBluetoothProfileRecord {
device::BluetoothProfile* profile;
};
-ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile)
+ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(
+ content::BrowserContext* context)
: send_discovery_events_(false),
responsible_for_discovery_(false),
- profile_(profile),
+ browser_context_(context),
adapter_(NULL),
num_event_listeners_(0),
next_socket_id_(1),
weak_ptr_factory_(this) {
- DCHECK(profile_);
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::Source<Profile>(profile_));
+ DCHECK(browser_context_);
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::Source<content::BrowserContext>(browser_context_));
}
ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() {
@@ -189,7 +190,8 @@ void ExtensionBluetoothEventRouter::DispatchDeviceEvent(
scoped_ptr<base::ListValue> args(new base::ListValue());
args->Append(device.ToValue().release());
scoped_ptr<Event> event(new Event(event_name, args.Pass()));
- ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass());
+ ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent(
+ event.Pass());
}
void ExtensionBluetoothEventRouter::DispatchConnectionEvent(
@@ -210,8 +212,9 @@ void ExtensionBluetoothEventRouter::DispatchConnectionEvent(
args->Append(result_socket.ToValue().release());
scoped_ptr<Event> event(new Event(
bluetooth::OnConnection::kEventName, args.Pass()));
- ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
- extension_id, event.Pass());
+ ExtensionSystem::Get(browser_context_)
+ ->event_router()
+ ->DispatchEventToExtension(extension_id, event.Pass());
}
void ExtensionBluetoothEventRouter::AdapterPresentChanged(
@@ -300,7 +303,8 @@ void ExtensionBluetoothEventRouter::DispatchAdapterStateEvent() {
scoped_ptr<Event> event(new Event(
bluetooth::OnAdapterStateChanged::kEventName,
args.Pass()));
- ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass());
+ ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent(
+ event.Pass());
}
void ExtensionBluetoothEventRouter::CleanUpForExtension(
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h
index eb23825..d6361ad 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h
@@ -17,7 +17,9 @@
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_socket.h"
-class Profile;
+namespace content {
+class BrowserContext;
+}
namespace device {
@@ -36,7 +38,7 @@ class ExtensionBluetoothEventRouter
: public device::BluetoothAdapter::Observer,
public content::NotificationObserver {
public:
- explicit ExtensionBluetoothEventRouter(Profile* profile);
+ explicit ExtensionBluetoothEventRouter(content::BrowserContext* context);
virtual ~ExtensionBluetoothEventRouter();
// Returns true if adapter_ has been initialized for testing or bluetooth
@@ -135,7 +137,7 @@ class ExtensionBluetoothEventRouter
bool send_discovery_events_;
bool responsible_for_discovery_;
- Profile* profile_;
+ content::BrowserContext* browser_context_;
scoped_refptr<device::BluetoothAdapter> adapter_;
int num_event_listeners_;
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc
index f3f6073..caad620 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc
@@ -7,7 +7,6 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
-#include "chrome/browser/profiles/profile.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
@@ -16,18 +15,18 @@ namespace {
const char kPlatformNotSupported[] =
"This operation is not supported on your platform";
-extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) {
- return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router();
+extensions::ExtensionBluetoothEventRouter* GetEventRouter(
+ content::BrowserContext* context) {
+ return extensions::BluetoothAPI::Get(context)->bluetooth_event_router();
}
-bool IsBluetoothSupported(Profile* profile) {
- return GetEventRouter(profile)->IsBluetoothSupported();
+bool IsBluetoothSupported(content::BrowserContext* context) {
+ return GetEventRouter(context)->IsBluetoothSupported();
}
-void GetAdapter(
- const device::BluetoothAdapterFactory::AdapterCallback callback,
- Profile* profile) {
- GetEventRouter(profile)->GetAdapter(callback);
+void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback,
+ content::BrowserContext* context) {
+ GetEventRouter(context)->GetAdapter(callback);
}
} // namespace
@@ -43,12 +42,12 @@ BluetoothExtensionFunction::~BluetoothExtensionFunction() {
}
bool BluetoothExtensionFunction::RunImpl() {
- if (!IsBluetoothSupported(GetProfile())) {
+ if (!IsBluetoothSupported(browser_context())) {
SetError(kPlatformNotSupported);
return false;
}
GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this),
- GetProfile());
+ browser_context());
return true;
}
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h
index 44812db..fd2f3cc 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h
@@ -7,7 +7,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "extensions/browser/extension_function.h"
namespace device {
@@ -22,7 +22,7 @@ namespace api {
// Base class for bluetooth extension functions. This class initializes
// bluetooth adapter and calls DoWork() implemented by individual bluetooth
// extension functions.
-class BluetoothExtensionFunction : public ChromeAsyncExtensionFunction {
+class BluetoothExtensionFunction : public UIThreadExtensionFunction {
public:
BluetoothExtensionFunction();
diff --git a/chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h b/chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h
index 7c9853b..9690e68 100644
--- a/chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h
+++ b/chrome/browser/extensions/api/braille_display_private/braille_display_private_api.h
@@ -6,12 +6,14 @@
#define CHROME_BROWSER_EXTENSIONS_API_BRAILLE_DISPLAY_PRIVATE_BRAILLE_DISPLAY_PRIVATE_API_H_
#include "base/scoped_observer.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
#include "chrome/common/extensions/api/braille_display_private.h"
+#include "extensions/browser/api/async_api_function.h"
#include "extensions/browser/event_router.h"
+class Profile;
+
namespace extensions {
namespace api {
namespace braille_display_private {
diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
index cb707ac..d6bc303 100644
--- a/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
+++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/cast_channel/cast_socket.h"
#include "chrome/browser/net/chrome_net_log.h"
-#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
@@ -113,7 +112,7 @@ CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
bool CastChannelAsyncApiFunction::PrePrepare() {
- manager_ = ApiResourceManager<CastSocket>::Get(GetProfile());
+ manager_ = ApiResourceManager<CastSocket>::Get(browser_context());
return true;
}
@@ -183,7 +182,7 @@ CastChannelOpenFunction::CastChannelOpenFunction()
CastChannelOpenFunction::~CastChannelOpenFunction() { }
bool CastChannelOpenFunction::PrePrepare() {
- api_ = CastChannelAPI::Get(GetProfile());
+ api_ = CastChannelAPI::Get(browser_context());
return CastChannelAsyncApiFunction::PrePrepare();
}
diff --git a/chrome/browser/extensions/api/cast_channel/cast_channel_api.h b/chrome/browser/extensions/api/cast_channel/cast_channel_api.h
index ac832b5..313c556 100644
--- a/chrome/browser/extensions/api/cast_channel/cast_channel_api.h
+++ b/chrome/browser/extensions/api/cast_channel/cast_channel_api.h
@@ -8,12 +8,11 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/cast_channel/cast_socket.h"
#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
#include "chrome/common/extensions/api/cast_channel.h"
-#include "extensions/browser/extension_function.h"
+#include "extensions/browser/api/async_api_function.h"
class GURL;
class CastChannelAPITest;
diff --git a/chrome/browser/extensions/api/diagnostics/diagnostics_api.h b/chrome/browser/extensions/api/diagnostics/diagnostics_api.h
index 6397c71..e088f3c 100644
--- a/chrome/browser/extensions/api/diagnostics/diagnostics_api.h
+++ b/chrome/browser/extensions/api/diagnostics/diagnostics_api.h
@@ -8,8 +8,8 @@
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/common/extensions/api/diagnostics.h"
+#include "extensions/browser/api/async_api_function.h"
namespace extensions {
diff --git a/chrome/browser/extensions/api/dial/dial_api.cc b/chrome/browser/extensions/api/dial/dial_api.cc
index 5339c16..d33b4cf 100644
--- a/chrome/browser/extensions/api/dial/dial_api.cc
+++ b/chrome/browser/extensions/api/dial/dial_api.cc
@@ -153,8 +153,8 @@ DialDiscoverNowFunction::DialDiscoverNowFunction()
bool DialDiscoverNowFunction::Prepare() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(GetProfile());
- dial_ = DialAPIFactory::GetForProfile(GetProfile()).get();
+ DCHECK(browser_context());
+ dial_ = DialAPIFactory::GetForBrowserContext(browser_context()).get();
return true;
}
diff --git a/chrome/browser/extensions/api/dial/dial_api.h b/chrome/browser/extensions/api/dial/dial_api.h
index d1481ca..7e07c22 100644
--- a/chrome/browser/extensions/api/dial/dial_api.h
+++ b/chrome/browser/extensions/api/dial/dial_api.h
@@ -7,10 +7,10 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/dial/dial_device_data.h"
#include "chrome/browser/extensions/api/dial/dial_registry.h"
#include "components/browser_context_keyed_service/refcounted_browser_context_keyed_service.h"
+#include "extensions/browser/api/async_api_function.h"
#include "extensions/browser/event_router.h"
namespace extensions {
diff --git a/chrome/browser/extensions/api/dial/dial_api_factory.cc b/chrome/browser/extensions/api/dial/dial_api_factory.cc
index 4b5b99e..193d57d 100644
--- a/chrome/browser/extensions/api/dial/dial_api_factory.cc
+++ b/chrome/browser/extensions/api/dial/dial_api_factory.cc
@@ -12,9 +12,10 @@
namespace extensions {
// static
-scoped_refptr<DialAPI> DialAPIFactory::GetForProfile(Profile* profile) {
+scoped_refptr<DialAPI> DialAPIFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
return static_cast<DialAPI*>(
- GetInstance()->GetServiceForBrowserContext(profile, true).get());
+ GetInstance()->GetServiceForBrowserContext(context, true).get());
}
// static
diff --git a/chrome/browser/extensions/api/dial/dial_api_factory.h b/chrome/browser/extensions/api/dial/dial_api_factory.h
index 39a25cd..f5fb18e 100644
--- a/chrome/browser/extensions/api/dial/dial_api_factory.h
+++ b/chrome/browser/extensions/api/dial/dial_api_factory.h
@@ -8,15 +8,14 @@
#include "base/memory/singleton.h"
#include "components/browser_context_keyed_service/refcounted_browser_context_keyed_service_factory.h"
-class Profile;
-
namespace extensions {
class DialAPI;
class DialAPIFactory : public RefcountedBrowserContextKeyedServiceFactory {
public:
- static scoped_refptr<DialAPI> GetForProfile(Profile* profile);
+ static scoped_refptr<DialAPI> GetForBrowserContext(
+ content::BrowserContext* context);
static DialAPIFactory* GetInstance();
diff --git a/chrome/browser/extensions/api/dial/dial_apitest.cc b/chrome/browser/extensions/api/dial/dial_apitest.cc
index 56b4746..eea812e 100644
--- a/chrome/browser/extensions/api/dial/dial_apitest.cc
+++ b/chrome/browser/extensions/api/dial/dial_apitest.cc
@@ -46,7 +46,8 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, MAYBE_DeviceListEvents) {
// Send three device list updates.
scoped_refptr<extensions::DialAPI> api =
- extensions::DialAPIFactory::GetInstance()->GetForProfile(profile());
+ extensions::DialAPIFactory::GetInstance()->GetForBrowserContext(
+ profile());
ASSERT_TRUE(api.get());
extensions::DialRegistry::DeviceList devices;
diff --git a/chrome/browser/extensions/api/gcm/gcm_api.cc b/chrome/browser/extensions/api/gcm/gcm_api.cc
index ca57f8a..6e3cebb 100644
--- a/chrome/browser/extensions/api/gcm/gcm_api.cc
+++ b/chrome/browser/extensions/api/gcm/gcm_api.cc
@@ -97,7 +97,7 @@ bool GcmApiFunction::RunImpl() {
}
bool GcmApiFunction::IsGcmApiEnabled() const {
- Profile* profile = Profile::FromBrowserContext(context());
+ Profile* profile = Profile::FromBrowserContext(browser_context());
// GCM is not supported in incognito mode.
if (profile->IsOffTheRecord())
@@ -109,7 +109,7 @@ bool GcmApiFunction::IsGcmApiEnabled() const {
gcm::GCMProfileService* GcmApiFunction::GCMProfileService() const {
return gcm::GCMProfileServiceFactory::GetForProfile(
- Profile::FromBrowserContext(context()));
+ Profile::FromBrowserContext(browser_context()));
}
GcmRegisterFunction::GcmRegisterFunction() {}
diff --git a/chrome/browser/extensions/api/hid/hid_api.cc b/chrome/browser/extensions/api/hid/hid_api.cc
index 8850868..a2a14a4 100644
--- a/chrome/browser/extensions/api/hid/hid_api.cc
+++ b/chrome/browser/extensions/api/hid/hid_api.cc
@@ -47,10 +47,10 @@ HidAsyncApiFunction::HidAsyncApiFunction()
HidAsyncApiFunction::~HidAsyncApiFunction() {}
bool HidAsyncApiFunction::PrePrepare() {
- device_manager_ = HidDeviceManager::Get(context());
+ device_manager_ = HidDeviceManager::Get(browser_context());
DCHECK(device_manager_);
connection_manager_ =
- ApiResourceManager<HidConnectionResource>::Get(context());
+ ApiResourceManager<HidConnectionResource>::Get(browser_context());
DCHECK(connection_manager_);
set_work_thread_id(content::BrowserThread::FILE);
return true;
diff --git a/chrome/browser/extensions/api/hid/hid_api.h b/chrome/browser/extensions/api/hid/hid_api.h
index 008dcf2..41a3be1 100644
--- a/chrome/browser/extensions/api/hid/hid_api.h
+++ b/chrome/browser/extensions/api/hid/hid_api.h
@@ -9,12 +9,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/hid/hid_connection_resource.h"
#include "chrome/browser/extensions/api/hid/hid_device_manager.h"
#include "chrome/browser/extensions/extension_function_histogram_value.h"
#include "chrome/common/extensions/api/hid.h"
+#include "extensions/browser/api/async_api_function.h"
namespace net {
diff --git a/chrome/browser/extensions/api/identity/identity_apitest.cc b/chrome/browser/extensions/api/identity/identity_apitest.cc
index 617db1c..2d7a39b 100644
--- a/chrome/browser/extensions/api/identity/identity_apitest.cc
+++ b/chrome/browser/extensions/api/identity/identity_apitest.cc
@@ -107,7 +107,7 @@ class AsyncExtensionBrowserTest : public ExtensionBrowserTest {
function->set_extension(empty_extension.get());
}
- function->set_context(browser()->profile());
+ function->set_browser_context(browser()->profile());
function->set_has_callback(true);
function->Run();
}
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc
index 30c935e..362b63c 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -127,7 +127,7 @@ std::string StripScopeFromIdentifier(const std::string& extension_id,
class NotificationsApiDelegate : public NotificationDelegate {
public:
- NotificationsApiDelegate(ApiFunction* api_function,
+ NotificationsApiDelegate(ChromeAsyncExtensionFunction* api_function,
Profile* profile,
const std::string& extension_id,
const std::string& id)
@@ -208,7 +208,7 @@ class NotificationsApiDelegate : public NotificationDelegate {
return args.Pass();
}
- scoped_refptr<ApiFunction> api_function_;
+ scoped_refptr<ChromeAsyncExtensionFunction> api_function_;
Profile* profile_;
const std::string extension_id_;
const std::string id_;
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.h b/chrome/browser/extensions/api/notifications/notifications_api.h
index 58e0440..02fee4b 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.h
+++ b/chrome/browser/extensions/api/notifications/notifications_api.h
@@ -8,7 +8,7 @@
#include <string>
#include "base/memory/ref_counted.h"
-#include "chrome/browser/extensions/api/api_function.h"
+#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/common/extensions/api/notifications.h"
#include "extensions/browser/extension_function.h"
#include "ui/message_center/notification_types.h"
@@ -17,7 +17,7 @@ class Notification;
namespace extensions {
-class NotificationsApiFunction : public ApiFunction {
+class NotificationsApiFunction : public ChromeAsyncExtensionFunction {
public:
// Whether the current extension and channel allow the API. Public for
// testing.
diff --git a/chrome/browser/extensions/api/serial/serial_api.cc b/chrome/browser/extensions/api/serial/serial_api.cc
index 694d051..a9ab198 100644
--- a/chrome/browser/extensions/api/serial/serial_api.cc
+++ b/chrome/browser/extensions/api/serial/serial_api.cc
@@ -57,7 +57,7 @@ SerialAsyncApiFunction::SerialAsyncApiFunction()
SerialAsyncApiFunction::~SerialAsyncApiFunction() {}
bool SerialAsyncApiFunction::PrePrepare() {
- manager_ = ApiResourceManager<SerialConnection>::Get(GetProfile());
+ manager_ = ApiResourceManager<SerialConnection>::Get(browser_context());
DCHECK(manager_);
return true;
}
@@ -135,7 +135,7 @@ bool SerialConnectFunction::Prepare() {
if (options->stop_bits == serial::STOP_BITS_NONE)
options->stop_bits = kDefaultStopBits;
- serial_event_dispatcher_ = SerialEventDispatcher::Get(GetProfile());
+ serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context());
DCHECK(serial_event_dispatcher_);
return true;
@@ -298,7 +298,7 @@ bool SerialSetPausedFunction::Prepare() {
params_ = serial::SetPaused::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- serial_event_dispatcher_ = SerialEventDispatcher::Get(GetProfile());
+ serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context());
DCHECK(serial_event_dispatcher_);
return true;
}
diff --git a/chrome/browser/extensions/api/serial/serial_api.h b/chrome/browser/extensions/api/serial/serial_api.h
index f541c41..d05834d 100644
--- a/chrome/browser/extensions/api/serial/serial_api.h
+++ b/chrome/browser/extensions/api/serial/serial_api.h
@@ -8,9 +8,9 @@
#include <string>
#include "base/memory/ref_counted.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/common/extensions/api/serial.h"
+#include "extensions/browser/api/async_api_function.h"
namespace extensions {
@@ -74,12 +74,12 @@ class SerialConnectFunction : public SerialAsyncApiFunction {
scoped_ptr<serial::Connect::Params> params_;
- // SerialEventDispatcher is owned by a Profile.
+ // SerialEventDispatcher is owned by a BrowserContext.
SerialEventDispatcher* serial_event_dispatcher_;
// This connection is created within SerialConnectFunction.
// From there it is either destroyed in OnConnected (upon failure)
- // or its ownership is transferred to the profile's.
+ // or its ownership is transferred to the
// ApiResourceManager<SerialConnection>.
SerialConnection* connection_;
};
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index 293a385..1453cf9 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
#include "chrome/browser/extensions/api/socket/udp_socket.h"
#include "chrome/browser/io_thread.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/permissions/socket_permission.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
@@ -56,7 +55,7 @@ SocketAsyncApiFunction::~SocketAsyncApiFunction() {
bool SocketAsyncApiFunction::PrePrepare() {
manager_ = CreateSocketResourceManager();
- return manager_->SetProfile(GetProfile());
+ return manager_->SetBrowserContext(browser_context());
}
bool SocketAsyncApiFunction::Respond() {
diff --git a/chrome/browser/extensions/api/socket/socket_api.h b/chrome/browser/extensions/api/socket/socket_api.h
index c52bf6d..dc2856e 100644
--- a/chrome/browser/extensions/api/socket/socket_api.h
+++ b/chrome/browser/extensions/api/socket/socket_api.h
@@ -7,9 +7,9 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/common/extensions/api/socket.h"
+#include "extensions/browser/api/async_api_function.h"
#include "extensions/browser/extension_function.h"
#include "net/base/address_list.h"
#include "net/dns/host_resolver.h"
@@ -19,6 +19,10 @@
class IOThread;
+namespace content {
+class BrowserContext;
+}
+
namespace net {
class IOBuffer;
}
@@ -35,7 +39,7 @@ class SocketResourceManagerInterface {
public:
virtual ~SocketResourceManagerInterface() {}
- virtual bool SetProfile(Profile* profile) = 0;
+ virtual bool SetBrowserContext(content::BrowserContext* context) = 0;
virtual int Add(Socket *socket) = 0;
virtual Socket* Get(const std::string& extension_id,
int api_resource_id) = 0;
@@ -54,8 +58,8 @@ class SocketResourceManager : public SocketResourceManagerInterface {
: manager_(NULL) {
}
- virtual bool SetProfile(Profile* profile) OVERRIDE {
- manager_ = ApiResourceManager<T>::Get(profile);
+ virtual bool SetBrowserContext(content::BrowserContext* context) OVERRIDE {
+ manager_ = ApiResourceManager<T>::Get(context);
DCHECK(manager_) << "There is no socket manager. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
diff --git a/chrome/browser/extensions/api/socket/socket_api_unittest.cc b/chrome/browser/extensions/api/socket/socket_api_unittest.cc
index d83497e..086aecb 100644
--- a/chrome/browser/extensions/api/socket/socket_api_unittest.cc
+++ b/chrome/browser/extensions/api/socket/socket_api_unittest.cc
@@ -4,7 +4,6 @@
#include "base/values.h"
#include "chrome/browser/browser_process_impl.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/socket_api.h"
@@ -18,11 +17,11 @@
namespace extensions {
BrowserContextKeyedService* ApiResourceManagerTestFactory(
- content::BrowserContext* profile) {
+ content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
- return ApiResourceManager<Socket>::CreateApiResourceManagerForTest(
- static_cast<Profile*>(profile), id);
+ return ApiResourceManager<Socket>::CreateApiResourceManagerForTest(context,
+ id);
}
class SocketUnitTest : public ExtensionApiUnittest {
diff --git a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
index 2d1dd17..9fdff0f 100644
--- a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
+++ b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
#include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/sockets/sockets_manifest_data.h"
#include "content/public/common/socket_permission_request.h"
#include "net/base/net_errors.h"
@@ -159,7 +158,7 @@ bool SocketsTcpSetPausedFunction::Prepare() {
params_ = api::sockets_tcp::SetPaused::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -244,7 +243,7 @@ bool SocketsTcpConnectFunction::Prepare() {
params_ = sockets_tcp::Connect::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
diff --git a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api_unittest.cc b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api_unittest.cc
index 8a5a755..2a809fd 100644
--- a/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api_unittest.cc
+++ b/chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api_unittest.cc
@@ -4,7 +4,6 @@
#include "base/values.h"
#include "chrome/browser/browser_process_impl.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
@@ -19,13 +18,12 @@
namespace extensions {
namespace api {
-static
-BrowserContextKeyedService* ApiResourceManagerTestFactory(
- content::BrowserContext* profile) {
+static BrowserContextKeyedService* ApiResourceManagerTestFactory(
+ content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
- return ApiResourceManager<ResumableTCPSocket>::
- CreateApiResourceManagerForTest(static_cast<Profile*>(profile), id);
+ return ApiResourceManager<
+ ResumableTCPSocket>::CreateApiResourceManagerForTest(context, id);
}
class SocketsTcpUnitTest : public ExtensionApiUnittest {
diff --git a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
index 573b8e1..742e2cf 100644
--- a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
@@ -8,6 +8,8 @@
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
+class Profile;
+
namespace extensions {
struct Event;
class ResumableTCPSocket;
diff --git a/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.cc b/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.cc
index 8b98d6c..174f9a1 100644
--- a/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.cc
+++ b/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
#include "chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/sockets/sockets_manifest_data.h"
#include "chrome/common/extensions/permissions/socket_permission.h"
#include "content/public/common/socket_permission_request.h"
@@ -130,7 +129,8 @@ bool SocketsTcpServerSetPausedFunction::Prepare() {
params_ = api::sockets_tcp_server::SetPaused::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = TCPServerSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ =
+ TCPServerSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -165,7 +165,8 @@ bool SocketsTcpServerListenFunction::Prepare() {
params_ = api::sockets_tcp_server::Listen::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = TCPServerSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ =
+ TCPServerSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
diff --git a/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api_unittest.cc b/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api_unittest.cc
index b81f41a..45285aa 100644
--- a/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api_unittest.cc
+++ b/chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api_unittest.cc
@@ -4,7 +4,6 @@
#include "base/values.h"
#include "chrome/browser/browser_process_impl.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
@@ -19,22 +18,20 @@
namespace extensions {
namespace api {
-static
-BrowserContextKeyedService* ApiResourceManagerTestFactory(
- content::BrowserContext* profile) {
+static BrowserContextKeyedService* ApiResourceManagerTestFactory(
+ content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
- return ApiResourceManager<ResumableTCPSocket>::
- CreateApiResourceManagerForTest(static_cast<Profile*>(profile), id);
+ return ApiResourceManager<
+ ResumableTCPSocket>::CreateApiResourceManagerForTest(context, id);
}
-static
-BrowserContextKeyedService* ApiResourceManagerTestServerFactory(
- content::BrowserContext* profile) {
+static BrowserContextKeyedService* ApiResourceManagerTestServerFactory(
+ content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
- return ApiResourceManager<ResumableTCPServerSocket>::
- CreateApiResourceManagerForTest(static_cast<Profile*>(profile), id);
+ return ApiResourceManager<
+ ResumableTCPServerSocket>::CreateApiResourceManagerForTest(context, id);
}
class SocketsTcpServerUnitTest : public ExtensionApiUnittest {
diff --git a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
index 68eca9e..9094bce 100644
--- a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
@@ -9,6 +9,8 @@
#include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
#include "chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.h"
+class Profile;
+
namespace extensions {
struct Event;
class ResumableTCPSocket;
diff --git a/chrome/browser/extensions/api/sockets_udp/sockets_udp_api.cc b/chrome/browser/extensions/api/sockets_udp/sockets_udp_api.cc
index 2e6f290..a710d0c 100644
--- a/chrome/browser/extensions/api/sockets_udp/sockets_udp_api.cc
+++ b/chrome/browser/extensions/api/sockets_udp/sockets_udp_api.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/extensions/api/socket/udp_socket.h"
#include "chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/sockets/sockets_manifest_data.h"
#include "content/public/common/socket_permission_request.h"
#include "net/base/net_errors.h"
@@ -141,7 +140,7 @@ bool SocketsUdpSetPausedFunction::Prepare() {
params_ = api::sockets_udp::SetPaused::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -177,7 +176,7 @@ bool SocketsUdpBindFunction::Prepare() {
params_ = sockets_udp::Bind::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
- socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(GetProfile());
+ socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context());
DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
diff --git a/chrome/browser/extensions/api/sockets_udp/sockets_udp_api_unittest.cc b/chrome/browser/extensions/api/sockets_udp/sockets_udp_api_unittest.cc
index fa1944f..476cb2f 100644
--- a/chrome/browser/extensions/api/sockets_udp/sockets_udp_api_unittest.cc
+++ b/chrome/browser/extensions/api/sockets_udp/sockets_udp_api_unittest.cc
@@ -4,7 +4,6 @@
#include "base/values.h"
#include "chrome/browser/browser_process_impl.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/udp_socket.h"
@@ -22,13 +21,12 @@ namespace utils = extension_function_test_utils;
namespace extensions {
namespace api {
-static
-BrowserContextKeyedService* ApiResourceManagerTestFactory(
- content::BrowserContext* profile) {
+static BrowserContextKeyedService* ApiResourceManagerTestFactory(
+ content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
- return ApiResourceManager<ResumableUDPSocket>::
- CreateApiResourceManagerForTest(static_cast<Profile*>(profile), id);
+ return ApiResourceManager<
+ ResumableUDPSocket>::CreateApiResourceManagerForTest(context, id);
}
class SocketsUdpUnitTest : public ExtensionApiUnittest {
diff --git a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
index 63baf84..c16f327 100644
--- a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
@@ -8,6 +8,8 @@
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/sockets_udp/sockets_udp_api.h"
+class Profile;
+
namespace extensions {
struct Event;
class ResumableUDPSocket;
diff --git a/chrome/browser/extensions/api/storage/storage_api.cc b/chrome/browser/extensions/api/storage/storage_api.cc
index 7b059c8..81bef66 100644
--- a/chrome/browser/extensions/api/storage/storage_api.cc
+++ b/chrome/browser/extensions/api/storage/storage_api.cc
@@ -47,7 +47,7 @@ bool SettingsFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(
settings_namespace_ != settings_namespace::INVALID);
- SettingsFrontend* frontend = SettingsFrontend::Get(context());
+ SettingsFrontend* frontend = SettingsFrontend::Get(browser_context());
if (!frontend->IsStorageEnabled(settings_namespace_)) {
error_ = base::StringPrintf(
"\"%s\" is not available in this instance of Chrome",
diff --git a/chrome/browser/extensions/api/usb/usb_api.cc b/chrome/browser/extensions/api/usb/usb_api.cc
index 84474e4..4d2e46e 100644
--- a/chrome/browser/extensions/api/usb/usb_api.cc
+++ b/chrome/browser/extensions/api/usb/usb_api.cc
@@ -10,7 +10,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "chrome/browser/extensions/api/usb/usb_device_resource.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/browser/usb/usb_service.h"
#include "chrome/common/extensions/api/usb.h"
@@ -396,7 +395,7 @@ UsbAsyncApiFunction::~UsbAsyncApiFunction() {
}
bool UsbAsyncApiFunction::PrePrepare() {
- manager_ = ApiResourceManager<UsbDeviceResource>::Get(GetProfile());
+ manager_ = ApiResourceManager<UsbDeviceResource>::Get(browser_context());
set_work_thread_id(BrowserThread::FILE);
return manager_ != NULL;
}
diff --git a/chrome/browser/extensions/api/usb/usb_api.h b/chrome/browser/extensions/api/usb/usb_api.h
index 69ce0cf..261f7dc 100644
--- a/chrome/browser/extensions/api/usb/usb_api.h
+++ b/chrome/browser/extensions/api/usb/usb_api.h
@@ -10,11 +10,11 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/extensions/api/api_function.h"
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/usb/usb_device.h"
#include "chrome/browser/usb/usb_device_handle.h"
#include "chrome/common/extensions/api/usb.h"
+#include "extensions/browser/api/async_api_function.h"
#include "net/base/io_buffer.h"
class UsbDevice;
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 112b5f4..a4afd74 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -371,7 +371,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallbackInternal(
function_ui->SetRenderFrameHost(render_frame_host);
}
function_ui->set_dispatcher(AsWeakPtr());
- function_ui->set_context(browser_context_);
+ function_ui->set_browser_context(browser_context_);
function->set_include_incognito(
ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito(
extension, browser_context_));
diff --git a/chrome/browser/extensions/extension_function_test_utils.cc b/chrome/browser/extensions/extension_function_test_utils.cc
index df91ad0..5907467 100644
--- a/chrome/browser/extensions/extension_function_test_utils.cc
+++ b/chrome/browser/extensions/extension_function_test_utils.cc
@@ -255,7 +255,7 @@ bool RunFunction(UIThreadExtensionFunction* function,
browser->profile(), &dispatcher_delegate);
function->set_dispatcher(dispatcher.AsWeakPtr());
- function->set_context(browser->profile());
+ function->set_browser_context(browser->profile());
function->set_include_incognito(flags & INCLUDE_INCOGNITO);
function->Run();
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index 6d2f75f..cbcc831 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -112,8 +112,6 @@
'browser/extensions/activity_log/web_request_constants.h',
'browser/extensions/api/activity_log_private/activity_log_private_api.cc',
'browser/extensions/api/activity_log_private/activity_log_private_api.h',
- 'browser/extensions/api/api_function.cc',
- 'browser/extensions/api/api_function.h',
'browser/extensions/api/api_resource.cc',
'browser/extensions/api/api_resource.h',
'browser/extensions/api/api_resource_manager.h',
diff --git a/chrome/browser/extensions/api/api_function.cc b/extensions/browser/api/async_api_function.cc
index 54bf8e3..2ed484d 100644
--- a/chrome/browser/extensions/api/api_function.cc
+++ b/extensions/browser/api/async_api_function.cc
@@ -1,30 +1,20 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/api_function.h"
+#include "extensions/browser/api/async_api_function.h"
#include "base/bind.h"
-#include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_system.h"
using content::BrowserThread;
namespace extensions {
-ApiFunction::ApiFunction() {
-}
-
-ApiFunction::~ApiFunction() {
-}
-
// AsyncApiFunction
-AsyncApiFunction::AsyncApiFunction()
- : work_thread_id_(BrowserThread::IO) {
-}
+AsyncApiFunction::AsyncApiFunction() : work_thread_id_(BrowserThread::IO) {}
-AsyncApiFunction::~AsyncApiFunction() {
-}
+AsyncApiFunction::~AsyncApiFunction() {}
bool AsyncApiFunction::RunImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -33,18 +23,16 @@ bool AsyncApiFunction::RunImpl() {
return false;
}
bool rv = BrowserThread::PostTask(
- work_thread_id_, FROM_HERE,
+ work_thread_id_,
+ FROM_HERE,
base::Bind(&AsyncApiFunction::WorkOnWorkThread, this));
DCHECK(rv);
return true;
}
-bool AsyncApiFunction::PrePrepare() {
- return true;
-}
+bool AsyncApiFunction::PrePrepare() { return true; }
-void AsyncApiFunction::Work() {
-}
+void AsyncApiFunction::Work() {}
void AsyncApiFunction::AsyncWorkStart() {
Work();
@@ -54,7 +42,8 @@ void AsyncApiFunction::AsyncWorkStart() {
void AsyncApiFunction::AsyncWorkCompleted() {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
+ BrowserThread::UI,
+ FROM_HERE,
base::Bind(&AsyncApiFunction::RespondOnUIThread, this));
DCHECK(rv);
} else {
@@ -64,10 +53,10 @@ void AsyncApiFunction::AsyncWorkCompleted() {
void AsyncApiFunction::WorkOnWorkThread() {
DCHECK(BrowserThread::CurrentlyOn(work_thread_id_));
- DLOG_IF(ERROR, (work_thread_id_ == BrowserThread::UI)) <<
- "You have specified that AsyncApiFunction::Work() should happen on "
- "the UI thread. This nullifies the point of this class. Either "
- "specify a different thread or derive from a different class.";
+ DLOG_IF(ERROR, (work_thread_id_ == BrowserThread::UI))
+ << "You have specified that AsyncApiFunction::Work() should happen on "
+ "the UI thread. This nullifies the point of this class. Either "
+ "specify a different thread or derive from a different class.";
AsyncWorkStart();
}
diff --git a/chrome/browser/extensions/api/api_function.h b/extensions/browser/api/async_api_function.h
index 5fb32a9..dd4b500 100644
--- a/chrome/browser/extensions/api/api_function.h
+++ b/extensions/browser/api/async_api_function.h
@@ -1,27 +1,18 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_
-#define CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_
+#ifndef EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_
+#define EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_
-#include "chrome/browser/extensions/chrome_extension_function.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/extension_function.h"
namespace extensions {
-// Base class for API functions. TODO(miket): there isn't much here anymore
-// since the removal of ApiResourceEventRouter. Should we promote all its
-// subclasses to UIThreadExtensionFunctions?
-class ApiFunction : public ChromeAsyncExtensionFunction {
- protected:
- ApiFunction();
- virtual ~ApiFunction();
-};
-
// AsyncApiFunction provides convenient thread management for APIs that need to
// do essentially all their work on a thread other than the UI thread.
-class AsyncApiFunction : public ApiFunction {
+class AsyncApiFunction : public UIThreadExtensionFunction {
protected:
AsyncApiFunction();
virtual ~AsyncApiFunction();
@@ -66,4 +57,4 @@ class AsyncApiFunction : public ApiFunction {
} // namespace extensions
-#endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_
+#endif // EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_
diff --git a/extensions/browser/extension_function.h b/extensions/browser/extension_function.h
index 099dff1..b0af0ae 100644
--- a/extensions/browser/extension_function.h
+++ b/extensions/browser/extension_function.h
@@ -302,8 +302,10 @@ class UIThreadExtensionFunction : public ExtensionFunction {
// Set the browser context which contains the extension that has originated
// this function call.
- void set_context(content::BrowserContext* context) { context_ = context; }
- content::BrowserContext* context() const { return context_; }
+ void set_browser_context(content::BrowserContext* context) {
+ context_ = context;
+ }
+ content::BrowserContext* browser_context() const { return context_; }
void SetRenderViewHost(content::RenderViewHost* render_view_host);
content::RenderViewHost* render_view_host() const {
diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp
index 1045e53..0770de6 100644
--- a/extensions/extensions.gyp
+++ b/extensions/extensions.gyp
@@ -167,6 +167,8 @@
'sources': [
'browser/admin_policy.cc',
'browser/admin_policy.h',
+ 'browser/api/async_api_function.cc',
+ 'browser/api/async_api_function.h',
'browser/api_activity_monitor.h',
'browser/app_sorting.h',
'browser/blacklist_state.h',