Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
| diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
| index b6cf1660dd3c0d2da3edb0c5f8d8b9270a5b7257..eb2a971daacafed53e3230e074c346fc98930ee5 100644 |
| --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
| +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
| @@ -35,8 +35,9 @@ using device::BluetoothSocket; |
| namespace { |
| -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(); |
| } |
| } // namespace |
| @@ -78,12 +79,12 @@ namespace Write = extensions::api::bluetooth::Write; |
| namespace extensions { |
| // static |
| -BluetoothAPI* BluetoothAPI::Get(Profile* profile) { |
| - return BluetoothAPIFactory::GetForProfile(profile); |
| +BluetoothAPI* BluetoothAPI::Get(content::BrowserContext* context) { |
| + return BluetoothAPIFactory::GetForBrowserContext(context); |
| } |
| -BluetoothAPI::BluetoothAPI(Profile* profile) : profile_(profile) { |
| - ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| +BluetoothAPI::BluetoothAPI(Profile* profile) : browser_context_(profile) { |
| + ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( |
| this, bluetooth::OnAdapterStateChanged::kEventName); |
| } |
| @@ -92,13 +93,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) { |
| @@ -133,7 +136,7 @@ bool BluetoothAddProfileFunction::RunImpl() { |
| uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); |
| - if (GetEventRouter(GetProfile())->HasProfile(uuid_)) { |
| + if (GetEventRouter(context())->HasProfile(uuid_)) { |
|
James Cook
2014/02/26 17:57:21
Not for this CL, but I think the API code would be
Ken Rockot(use gerrit already)
2014/02/26 18:20:44
I agree with browser_context. As it turns out, a r
|
| SetError(kProfileAlreadyRegistered); |
| return false; |
| } |
| @@ -181,7 +184,7 @@ void BluetoothAddProfileFunction::OnProfileRegistered( |
| return; |
| } |
| - if (GetEventRouter(GetProfile())->HasProfile(uuid_)) { |
| + if (GetEventRouter(context())->HasProfile(uuid_)) { |
| bluetooth_profile->Unregister(); |
| SetError(kProfileAlreadyRegistered); |
| SendResponse(false); |
| @@ -190,11 +193,11 @@ void BluetoothAddProfileFunction::OnProfileRegistered( |
| bluetooth_profile->SetConnectionCallback( |
| base::Bind(&ExtensionBluetoothEventRouter::DispatchConnectionEvent, |
| - base::Unretained(GetEventRouter(GetProfile())), |
| + base::Unretained(GetEventRouter(context())), |
| extension_id(), |
| uuid_)); |
| - GetEventRouter(GetProfile())->AddProfile( |
| - uuid_, extension_id(), bluetooth_profile); |
| + GetEventRouter(context()) |
| + ->AddProfile(uuid_, extension_id(), bluetooth_profile); |
| SendResponse(true); |
| } |
| @@ -210,12 +213,12 @@ bool BluetoothRemoveProfileFunction::RunImpl() { |
| std::string uuid = |
| device::bluetooth_utils::CanonicalUuid(params->profile.uuid); |
| - if (!GetEventRouter(GetProfile())->HasProfile(uuid)) { |
| + if (!GetEventRouter(context())->HasProfile(uuid)) { |
| SetError(kProfileNotFound); |
| return false; |
| } |
| - GetEventRouter(GetProfile())->RemoveProfile(uuid); |
| + GetEventRouter(context())->RemoveProfile(uuid); |
| return true; |
| } |
| @@ -266,7 +269,7 @@ void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( |
| const BluetoothDevice& device) { |
| bluetooth::Device extension_device; |
| bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); |
| - GetEventRouter(GetProfile())->DispatchDeviceEvent( |
| + GetEventRouter(context())->DispatchDeviceEvent( |
| extensions::event_names::kBluetoothOnDeviceSearchResult, |
| extension_device); |
| @@ -281,9 +284,8 @@ void BluetoothGetDevicesFunction::FinishDeviceSearch() { |
| scoped_ptr<extensions::Event> event(new extensions::Event( |
| extensions::event_names::kBluetoothOnDeviceSearchFinished, args.Pass())); |
| - extensions::ExtensionSystem::Get(GetProfile()) |
| - ->event_router() |
| - ->BroadcastEvent(event.Pass()); |
| + extensions::ExtensionSystem::Get(context())->event_router()->BroadcastEvent( |
| + event.Pass()); |
| SendResponse(true); |
| } |
| @@ -399,7 +401,7 @@ bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { |
| options.profile.uuid); |
| BluetoothProfile* bluetooth_profile = |
| - GetEventRouter(GetProfile())->GetProfile(uuid); |
| + GetEventRouter(context())->GetProfile(uuid); |
| if (!bluetooth_profile) { |
| SetError(kProfileNotFound); |
| SendResponse(false); |
| @@ -418,7 +420,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(context())->ReleaseSocket(options.socket.id); |
| } |
| BluetoothReadFunction::BluetoothReadFunction() : success_(false) {} |
| @@ -429,7 +431,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(context())->GetSocket(options.socket.id); |
| if (socket_.get() == NULL) { |
| SetError(kSocketNotFoundError); |
| return false; |
| @@ -477,7 +479,7 @@ bool BluetoothWriteFunction::Prepare() { |
| int socket_id; |
| EXTENSION_FUNCTION_VALIDATE(socket->GetInteger("id", &socket_id)); |
| - socket_ = GetEventRouter(GetProfile())->GetSocket(socket_id); |
| + socket_ = GetEventRouter(context())->GetSocket(socket_id); |
| if (socket_.get() == NULL) { |
| SetError(kSocketNotFoundError); |
| return false; |
| @@ -623,20 +625,20 @@ void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
| void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
| SetError(kStartDiscoveryFailed); |
| - GetEventRouter(GetProfile())->SetResponsibleForDiscovery(false); |
| + GetEventRouter(context())->SetResponsibleForDiscovery(false); |
| SendResponse(false); |
| - GetEventRouter(GetProfile())->OnListenerRemoved(); |
| + GetEventRouter(context())->OnListenerRemoved(); |
| } |
| bool BluetoothStartDiscoveryFunction::DoWork( |
| scoped_refptr<BluetoothAdapter> adapter) { |
| - GetEventRouter(GetProfile())->SetSendDiscoveryEvents(true); |
| + GetEventRouter(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(context())->IsResponsibleForDiscovery()) { |
| + GetEventRouter(context())->SetResponsibleForDiscovery(true); |
| + GetEventRouter(context())->OnListenerAdded(); |
| adapter->StartDiscovering( |
| base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
| base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
| @@ -647,20 +649,20 @@ bool BluetoothStartDiscoveryFunction::DoWork( |
| void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
| SendResponse(true); |
| - GetEventRouter(GetProfile())->OnListenerRemoved(); |
| + GetEventRouter(context())->OnListenerRemoved(); |
| } |
| void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
| SetError(kStopDiscoveryFailed); |
| - GetEventRouter(GetProfile())->SetResponsibleForDiscovery(true); |
| + GetEventRouter(context())->SetResponsibleForDiscovery(true); |
| SendResponse(false); |
| - GetEventRouter(GetProfile())->OnListenerRemoved(); |
| + GetEventRouter(context())->OnListenerRemoved(); |
| } |
| bool BluetoothStopDiscoveryFunction::DoWork( |
| scoped_refptr<BluetoothAdapter> adapter) { |
| - GetEventRouter(GetProfile())->SetSendDiscoveryEvents(false); |
| - if (GetEventRouter(GetProfile())->IsResponsibleForDiscovery()) { |
| + GetEventRouter(context())->SetSendDiscoveryEvents(false); |
| + if (GetEventRouter(context())->IsResponsibleForDiscovery()) { |
| adapter->StopDiscovering( |
| base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |