Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing styles and tess. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" 14 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
15 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" 15 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_dbus.h"
16 #include "chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h"
16 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
17 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 22
22 namespace { 23 namespace {
23 24
24 // |UpdateDeviceCallback| takes a variable length list as an argument. The 25 // |UpdateDeviceCallback| takes a variable length list as an argument. The
25 // value stored in each list element is indicated by the following constants. 26 // value stored in each list element is indicated by the following constants.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 { "bluetoothDisconnectFailed", 117 { "bluetoothDisconnectFailed",
117 IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT_FAILED }, 118 IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT_FAILED },
118 { "bluetoothForgetFailed", 119 { "bluetoothForgetFailed",
119 IDS_OPTIONS_SETTINGS_BLUETOOTH_FORGET_FAILED }}; 120 IDS_OPTIONS_SETTINGS_BLUETOOTH_FORGET_FAILED }};
120 121
121 RegisterStrings(localized_strings, resources, arraysize(resources)); 122 RegisterStrings(localized_strings, resources, arraysize(resources));
122 } 123 }
123 124
124 // TODO(kevers): Reorder methods to match ordering in the header file. 125 // TODO(kevers): Reorder methods to match ordering in the header file.
125 126
126 void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter, 127 void BluetoothOptionsHandler::AdapterPresentChanged(
127 bool present) { 128 BluetoothAdapter* adapter, bool present) {
128 DCHECK(adapter == adapter_.get()); 129 DCHECK(adapter == adapter_.get());
129 if (present) { 130 if (present) {
130 web_ui()->CallJavascriptFunction( 131 web_ui()->CallJavascriptFunction(
131 "options.BrowserOptions.showBluetoothSettings"); 132 "options.BrowserOptions.showBluetoothSettings");
132 133
133 // Update the checkbox and visibility based on the powered state of the 134 // Update the checkbox and visibility based on the powered state of the
134 // new adapter. 135 // new adapter.
135 AdapterPoweredChanged(adapter_.get(), adapter_->IsPowered()); 136 AdapterPoweredChanged(adapter_.get(), adapter_->IsPowered());
136 } else { 137 } else {
137 web_ui()->CallJavascriptFunction( 138 web_ui()->CallJavascriptFunction(
138 "options.BrowserOptions.hideBluetoothSettings"); 139 "options.BrowserOptions.hideBluetoothSettings");
139 } 140 }
140 } 141 }
141 142
142 void BluetoothOptionsHandler::AdapterPoweredChanged(BluetoothAdapter* adapter, 143 void BluetoothOptionsHandler::AdapterPoweredChanged(
143 bool powered) { 144 BluetoothAdapter* adapter, bool powered) {
144 DCHECK(adapter == adapter_.get()); 145 DCHECK(adapter == adapter_.get());
145 base::FundamentalValue checked(powered); 146 base::FundamentalValue checked(powered);
146 web_ui()->CallJavascriptFunction( 147 web_ui()->CallJavascriptFunction(
147 "options.BrowserOptions.setBluetoothState", checked); 148 "options.BrowserOptions.setBluetoothState", checked);
148 } 149 }
149 150
151 void BluetoothOptionsHandler::AdapterDiscoveringChanged(
152 BluetoothAdapter* adapter, bool discovering) {
153 }
154
keybuk 2012/09/13 23:57:30 Why has this empty method been added?
youngki 2012/09/17 21:53:02 Removed.
150 void BluetoothOptionsHandler::RegisterMessages() { 155 void BluetoothOptionsHandler::RegisterMessages() {
151 web_ui()->RegisterMessageCallback("bluetoothEnableChange", 156 web_ui()->RegisterMessageCallback("bluetoothEnableChange",
152 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback, 157 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback,
153 base::Unretained(this))); 158 base::Unretained(this)));
154 web_ui()->RegisterMessageCallback("findBluetoothDevices", 159 web_ui()->RegisterMessageCallback("findBluetoothDevices",
155 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback, 160 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback,
156 base::Unretained(this))); 161 base::Unretained(this)));
157 web_ui()->RegisterMessageCallback("updateBluetoothDevice", 162 web_ui()->RegisterMessageCallback("updateBluetoothDevice",
158 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback, 163 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback,
159 base::Unretained(this))); 164 base::Unretained(this)));
160 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery", 165 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery",
161 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback, 166 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback,
162 base::Unretained(this))); 167 base::Unretained(this)));
163 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices", 168 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices",
164 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback, 169 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback,
165 base::Unretained(this))); 170 base::Unretained(this)));
166 } 171 }
167 172
168 void BluetoothOptionsHandler::InitializeHandler() { 173 void BluetoothOptionsHandler::InitializeHandler() {
169 adapter_ = BluetoothAdapter::DefaultAdapter(); 174 adapter_ = BluetoothAdapterDBus::DefaultAdapter();
170 adapter_->AddObserver(this); 175 adapter_->AddObserver(this);
171 } 176 }
172 177
173 void BluetoothOptionsHandler::InitializePage() { 178 void BluetoothOptionsHandler::InitializePage() {
174 // Show or hide the bluetooth settings and update the checkbox based 179 // Show or hide the bluetooth settings and update the checkbox based
175 // on the current present/powered state. 180 // on the current present/powered state.
176 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent()); 181 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent());
177 // Automatically start device discovery if the "Add Bluetooth Device" 182 // Automatically start device discovery if the "Add Bluetooth Device"
178 // overlay is visible. 183 // overlay is visible.
179 web_ui()->CallJavascriptFunction( 184 web_ui()->CallJavascriptFunction(
(...skipping 28 matching lines...) Expand all
208 void BluetoothOptionsHandler::FindDevicesError() { 213 void BluetoothOptionsHandler::FindDevicesError() {
209 DVLOG(1) << "Failed to start discovery."; 214 DVLOG(1) << "Failed to start discovery.";
210 ReportError("bluetoothStartDiscoveryFailed", std::string()); 215 ReportError("bluetoothStartDiscoveryFailed", std::string());
211 } 216 }
212 217
213 void BluetoothOptionsHandler::UpdateDeviceCallback( 218 void BluetoothOptionsHandler::UpdateDeviceCallback(
214 const ListValue* args) { 219 const ListValue* args) {
215 std::string address; 220 std::string address;
216 args->GetString(kUpdateDeviceAddressIndex, &address); 221 args->GetString(kUpdateDeviceAddressIndex, &address);
217 222
218 BluetoothDevice* device = adapter_->GetDevice(address); 223 BluetoothDeviceDBus* device = static_cast<BluetoothDeviceDBus *>(
224 adapter_->GetDevice(address));
keybuk 2012/09/13 23:57:30 Why does this need a static_cast? This interface n
youngki 2012/09/17 21:53:02 Done.
219 if (!device) 225 if (!device)
220 return; 226 return;
221 227
222 std::string command; 228 std::string command;
223 args->GetString(kUpdateDeviceCommandIndex, &command); 229 args->GetString(kUpdateDeviceCommandIndex, &command);
224 230
225 if (command == kConnectCommand) { 231 if (command == kConnectCommand) {
226 int size = args->GetSize(); 232 int size = args->GetSize();
227 if (size > kUpdateDeviceAuthTokenIndex) { 233 if (size > kUpdateDeviceAuthTokenIndex) {
228 // PIN code or Passkey entry during the pairing process. 234 // PIN code or Passkey entry during the pairing process.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 void BluetoothOptionsHandler::GetPairedDevicesCallback( 330 void BluetoothOptionsHandler::GetPairedDevicesCallback(
325 const ListValue* args) { 331 const ListValue* args) {
326 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 332 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
327 333
328 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); 334 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin();
329 iter != devices.end(); ++iter) 335 iter != devices.end(); ++iter)
330 SendDeviceNotification(*iter, NULL); 336 SendDeviceNotification(*iter, NULL);
331 } 337 }
332 338
333 void BluetoothOptionsHandler::SendDeviceNotification( 339 void BluetoothOptionsHandler::SendDeviceNotification(
334 const BluetoothDevice* device, 340 const BluetoothDevice* device, base::DictionaryValue* params) {
335 base::DictionaryValue* params) {
336 base::DictionaryValue js_properties; 341 base::DictionaryValue js_properties;
337 js_properties.SetString("name", device->GetName()); 342 js_properties.SetString("name", device->GetName());
338 js_properties.SetString("address", device->address()); 343 js_properties.SetString("address", device->address());
339 js_properties.SetBoolean("paired", device->IsPaired()); 344 js_properties.SetBoolean("paired", device->IsPaired());
340 js_properties.SetBoolean("bonded", device->IsBonded()); 345 js_properties.SetBoolean("bonded", device->IsBonded());
341 js_properties.SetBoolean("connected", device->IsConnected()); 346 js_properties.SetBoolean("connected", device->IsConnected());
342 if (params) { 347 if (params) {
343 js_properties.MergeDictionary(params); 348 js_properties.MergeDictionary(params);
344 } 349 }
345 web_ui()->CallJavascriptFunction( 350 web_ui()->CallJavascriptFunction(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 DCHECK(device); 424 DCHECK(device);
420 425
421 base::StringValue address(device->address()); 426 base::StringValue address(device->address());
422 web_ui()->CallJavascriptFunction( 427 web_ui()->CallJavascriptFunction(
423 "options.BrowserOptions.removeBluetoothDevice", 428 "options.BrowserOptions.removeBluetoothDevice",
424 address); 429 address);
425 } 430 }
426 431
427 } // namespace options 432 } // namespace options
428 } // namespace chromeos 433 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698