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

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

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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"
15 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h"
16 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
17 #include "content/public/browser/web_ui.h" 14 #include "content/public/browser/web_ui.h"
15 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_adapter_factory.h"
17 #include "device/bluetooth/bluetooth_device.h"
18 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 using bluetooth::BluetoothAdapter;
bryeung 2012/10/10 15:03:53 remove
youngki 2012/10/10 18:34:57 Done.
24
23 namespace { 25 namespace {
24 26
25 // |UpdateDeviceCallback| takes a variable length list as an argument. The 27 // |UpdateDeviceCallback| takes a variable length list as an argument. The
26 // value stored in each list element is indicated by the following constants. 28 // value stored in each list element is indicated by the following constants.
27 const int kUpdateDeviceAddressIndex = 0; 29 const int kUpdateDeviceAddressIndex = 0;
28 const int kUpdateDeviceCommandIndex = 1; 30 const int kUpdateDeviceCommandIndex = 1;
29 const int kUpdateDeviceAuthTokenIndex = 2; 31 const int kUpdateDeviceAuthTokenIndex = 2;
30 32
31 // |UpdateDeviceCallback| provides a command value of one of the following 33 // |UpdateDeviceCallback| provides a command value of one of the following
32 // constants that indicates what update it is providing to us. 34 // constants that indicates what update it is providing to us.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 { "bluetoothDisconnectFailed", 119 { "bluetoothDisconnectFailed",
118 IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT_FAILED }, 120 IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT_FAILED },
119 { "bluetoothForgetFailed", 121 { "bluetoothForgetFailed",
120 IDS_OPTIONS_SETTINGS_BLUETOOTH_FORGET_FAILED }}; 122 IDS_OPTIONS_SETTINGS_BLUETOOTH_FORGET_FAILED }};
121 123
122 RegisterStrings(localized_strings, resources, arraysize(resources)); 124 RegisterStrings(localized_strings, resources, arraysize(resources));
123 } 125 }
124 126
125 // TODO(kevers): Reorder methods to match ordering in the header file. 127 // TODO(kevers): Reorder methods to match ordering in the header file.
126 128
127 void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter, 129 void BluetoothOptionsHandler::AdapterPresentChanged(
128 bool present) { 130 bluetooth::BluetoothAdapter* adapter,
131 bool present) {
129 DCHECK(adapter == adapter_.get()); 132 DCHECK(adapter == adapter_.get());
130 if (present) { 133 if (present) {
131 web_ui()->CallJavascriptFunction( 134 web_ui()->CallJavascriptFunction(
132 "options.BrowserOptions.showBluetoothSettings"); 135 "options.BrowserOptions.showBluetoothSettings");
133 136
134 // Update the checkbox and visibility based on the powered state of the 137 // Update the checkbox and visibility based on the powered state of the
135 // new adapter. 138 // new adapter.
136 AdapterPoweredChanged(adapter_.get(), adapter_->IsPowered()); 139 AdapterPoweredChanged(adapter_.get(), adapter_->IsPowered());
137 } else { 140 } else {
138 web_ui()->CallJavascriptFunction( 141 web_ui()->CallJavascriptFunction(
139 "options.BrowserOptions.hideBluetoothSettings"); 142 "options.BrowserOptions.hideBluetoothSettings");
140 } 143 }
141 } 144 }
142 145
143 void BluetoothOptionsHandler::AdapterPoweredChanged(BluetoothAdapter* adapter, 146 void BluetoothOptionsHandler::AdapterPoweredChanged(
144 bool powered) { 147 bluetooth::BluetoothAdapter* adapter,
148 bool powered) {
145 DCHECK(adapter == adapter_.get()); 149 DCHECK(adapter == adapter_.get());
146 base::FundamentalValue checked(powered); 150 base::FundamentalValue checked(powered);
147 web_ui()->CallJavascriptFunction( 151 web_ui()->CallJavascriptFunction(
148 "options.BrowserOptions.setBluetoothState", checked); 152 "options.BrowserOptions.setBluetoothState", checked);
149 } 153 }
150 154
151 void BluetoothOptionsHandler::RegisterMessages() { 155 void BluetoothOptionsHandler::RegisterMessages() {
152 web_ui()->RegisterMessageCallback("bluetoothEnableChange", 156 web_ui()->RegisterMessageCallback("bluetoothEnableChange",
153 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback, 157 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback,
154 base::Unretained(this))); 158 base::Unretained(this)));
155 web_ui()->RegisterMessageCallback("findBluetoothDevices", 159 web_ui()->RegisterMessageCallback("findBluetoothDevices",
156 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback, 160 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback,
157 base::Unretained(this))); 161 base::Unretained(this)));
158 web_ui()->RegisterMessageCallback("updateBluetoothDevice", 162 web_ui()->RegisterMessageCallback("updateBluetoothDevice",
159 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback, 163 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback,
160 base::Unretained(this))); 164 base::Unretained(this)));
161 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery", 165 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery",
162 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback, 166 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback,
163 base::Unretained(this))); 167 base::Unretained(this)));
164 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices", 168 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices",
165 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback, 169 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback,
166 base::Unretained(this))); 170 base::Unretained(this)));
167 } 171 }
168 172
169 void BluetoothOptionsHandler::InitializeHandler() { 173 void BluetoothOptionsHandler::InitializeHandler() {
170 adapter_ = BluetoothAdapterFactory::DefaultAdapter(); 174 adapter_ = bluetooth::BluetoothAdapterFactory::DefaultAdapter();
175 DCHECK(adapter_.get());
171 adapter_->AddObserver(this); 176 adapter_->AddObserver(this);
172 } 177 }
173 178
174 void BluetoothOptionsHandler::InitializePage() { 179 void BluetoothOptionsHandler::InitializePage() {
175 // Show or hide the bluetooth settings and update the checkbox based 180 // Show or hide the bluetooth settings and update the checkbox based
176 // on the current present/powered state. 181 // on the current present/powered state.
177 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent()); 182 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent());
178 // Automatically start device discovery if the "Add Bluetooth Device" 183 // Automatically start device discovery if the "Add Bluetooth Device"
179 // overlay is visible. 184 // overlay is visible.
180 web_ui()->CallJavascriptFunction( 185 web_ui()->CallJavascriptFunction(
(...skipping 28 matching lines...) Expand all
209 void BluetoothOptionsHandler::FindDevicesError() { 214 void BluetoothOptionsHandler::FindDevicesError() {
210 DVLOG(1) << "Failed to start discovery."; 215 DVLOG(1) << "Failed to start discovery.";
211 ReportError("bluetoothStartDiscoveryFailed", std::string()); 216 ReportError("bluetoothStartDiscoveryFailed", std::string());
212 } 217 }
213 218
214 void BluetoothOptionsHandler::UpdateDeviceCallback( 219 void BluetoothOptionsHandler::UpdateDeviceCallback(
215 const ListValue* args) { 220 const ListValue* args) {
216 std::string address; 221 std::string address;
217 args->GetString(kUpdateDeviceAddressIndex, &address); 222 args->GetString(kUpdateDeviceAddressIndex, &address);
218 223
219 BluetoothDevice* device = adapter_->GetDevice(address); 224 bluetooth::BluetoothDevice* device = adapter_->GetDevice(address);
220 if (!device) 225 if (!device)
221 return; 226 return;
222 227
223 std::string command; 228 std::string command;
224 args->GetString(kUpdateDeviceCommandIndex, &command); 229 args->GetString(kUpdateDeviceCommandIndex, &command);
225 230
226 if (command == kConnectCommand) { 231 if (command == kConnectCommand) {
227 int size = args->GetSize(); 232 int size = args->GetSize();
228 if (size > kUpdateDeviceAuthTokenIndex) { 233 if (size > kUpdateDeviceAuthTokenIndex) {
229 // 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
325 void BluetoothOptionsHandler::GetPairedDevicesCallback( 330 void BluetoothOptionsHandler::GetPairedDevicesCallback(
326 const ListValue* args) { 331 const ListValue* args) {
327 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 332 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
328 333
329 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); 334 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin();
330 iter != devices.end(); ++iter) 335 iter != devices.end(); ++iter)
331 SendDeviceNotification(*iter, NULL); 336 SendDeviceNotification(*iter, NULL);
332 } 337 }
333 338
334 void BluetoothOptionsHandler::SendDeviceNotification( 339 void BluetoothOptionsHandler::SendDeviceNotification(
335 const BluetoothDevice* device, 340 const bluetooth::BluetoothDevice* device,
336 base::DictionaryValue* params) { 341 base::DictionaryValue* params) {
337 base::DictionaryValue js_properties; 342 base::DictionaryValue js_properties;
338 js_properties.SetString("name", device->GetName()); 343 js_properties.SetString("name", device->GetName());
339 js_properties.SetString("address", device->address()); 344 js_properties.SetString("address", device->address());
340 js_properties.SetBoolean("paired", device->IsPaired()); 345 js_properties.SetBoolean("paired", device->IsPaired());
341 js_properties.SetBoolean("bonded", device->IsBonded()); 346 js_properties.SetBoolean("bonded", device->IsBonded());
342 js_properties.SetBoolean("connected", device->IsConnected()); 347 js_properties.SetBoolean("connected", device->IsConnected());
343 if (params) { 348 if (params) {
344 js_properties.MergeDictionary(params); 349 js_properties.MergeDictionary(params);
345 } 350 }
346 web_ui()->CallJavascriptFunction( 351 web_ui()->CallJavascriptFunction(
347 "options.BrowserOptions.addBluetoothDevice", 352 "options.BrowserOptions.addBluetoothDevice",
348 js_properties); 353 js_properties);
349 } 354 }
350 355
351 void BluetoothOptionsHandler::RequestPinCode(BluetoothDevice* device) { 356 void BluetoothOptionsHandler::RequestPinCode(
357 bluetooth::BluetoothDevice* device) {
352 DictionaryValue params; 358 DictionaryValue params;
353 params.SetString("pairing", kEnterPinCode); 359 params.SetString("pairing", kEnterPinCode);
354 SendDeviceNotification(device, &params); 360 SendDeviceNotification(device, &params);
355 } 361 }
356 362
357 void BluetoothOptionsHandler::RequestPasskey(BluetoothDevice* device) { 363 void BluetoothOptionsHandler::RequestPasskey(
364 bluetooth::BluetoothDevice* device) {
358 DictionaryValue params; 365 DictionaryValue params;
359 params.SetString("pairing", kEnterPasskey); 366 params.SetString("pairing", kEnterPasskey);
360 SendDeviceNotification(device, &params); 367 SendDeviceNotification(device, &params);
361 } 368 }
362 369
363 void BluetoothOptionsHandler::DisplayPinCode(BluetoothDevice* device, 370 void BluetoothOptionsHandler::DisplayPinCode(
364 const std::string& pincode) { 371 bluetooth::BluetoothDevice* device,
372 const std::string& pincode) {
365 DictionaryValue params; 373 DictionaryValue params;
366 params.SetString("pairing", kRemotePinCode); 374 params.SetString("pairing", kRemotePinCode);
367 params.SetString("pincode", pincode); 375 params.SetString("pincode", pincode);
368 SendDeviceNotification(device, &params); 376 SendDeviceNotification(device, &params);
369 } 377 }
370 378
371 void BluetoothOptionsHandler::DisplayPasskey(BluetoothDevice* device, 379 void BluetoothOptionsHandler::DisplayPasskey(
372 uint32 passkey) { 380 bluetooth::BluetoothDevice* device,
381 uint32 passkey) {
373 DictionaryValue params; 382 DictionaryValue params;
374 params.SetString("pairing", kRemotePasskey); 383 params.SetString("pairing", kRemotePasskey);
375 params.SetInteger("passkey", passkey); 384 params.SetInteger("passkey", passkey);
376 SendDeviceNotification(device, &params); 385 SendDeviceNotification(device, &params);
377 } 386 }
378 387
379 void BluetoothOptionsHandler::ConfirmPasskey(BluetoothDevice* device, 388 void BluetoothOptionsHandler::ConfirmPasskey(
380 uint32 passkey) { 389 bluetooth::BluetoothDevice* device,
390 uint32 passkey) {
381 DictionaryValue params; 391 DictionaryValue params;
382 params.SetString("pairing", kConfirmPasskey); 392 params.SetString("pairing", kConfirmPasskey);
383 params.SetInteger("passkey", passkey); 393 params.SetInteger("passkey", passkey);
384 SendDeviceNotification(device, &params); 394 SendDeviceNotification(device, &params);
385 } 395 }
386 396
387 void BluetoothOptionsHandler::DismissDisplayOrConfirm() { 397 void BluetoothOptionsHandler::DismissDisplayOrConfirm() {
388 web_ui()->CallJavascriptFunction( 398 web_ui()->CallJavascriptFunction(
389 "options.BluetoothPairing.dismissDialog"); 399 "options.BluetoothPairing.dismissDialog");
390 } 400 }
391 401
392 void BluetoothOptionsHandler::ReportError( 402 void BluetoothOptionsHandler::ReportError(
393 const std::string& error, 403 const std::string& error,
394 const std::string& address) { 404 const std::string& address) {
395 base::DictionaryValue properties; 405 base::DictionaryValue properties;
396 properties.SetString("label", error); 406 properties.SetString("label", error);
397 properties.SetString("address", address); 407 properties.SetString("address", address);
398 web_ui()->CallJavascriptFunction( 408 web_ui()->CallJavascriptFunction(
399 "options.BluetoothPairing.showMessage", 409 "options.BluetoothPairing.showMessage",
400 properties); 410 properties);
401 } 411 }
402 412
403 void BluetoothOptionsHandler::DeviceAdded(BluetoothAdapter* adapter, 413 void BluetoothOptionsHandler::DeviceAdded(
404 BluetoothDevice* device) { 414 bluetooth::BluetoothAdapter* adapter,
415 bluetooth::BluetoothDevice* device) {
405 DCHECK(adapter == adapter_.get()); 416 DCHECK(adapter == adapter_.get());
406 DCHECK(device); 417 DCHECK(device);
407 SendDeviceNotification(device, NULL); 418 SendDeviceNotification(device, NULL);
408 } 419 }
409 420
410 void BluetoothOptionsHandler::DeviceChanged(BluetoothAdapter* adapter, 421 void BluetoothOptionsHandler::DeviceChanged(
411 BluetoothDevice* device) { 422 bluetooth::BluetoothAdapter* adapter,
423 bluetooth::BluetoothDevice* device) {
412 DCHECK(adapter == adapter_.get()); 424 DCHECK(adapter == adapter_.get());
413 DCHECK(device); 425 DCHECK(device);
414 SendDeviceNotification(device, NULL); 426 SendDeviceNotification(device, NULL);
415 } 427 }
416 428
417 void BluetoothOptionsHandler::DeviceRemoved(BluetoothAdapter* adapter, 429 void BluetoothOptionsHandler::DeviceRemoved(
418 BluetoothDevice* device) { 430 bluetooth::BluetoothAdapter* adapter,
431 bluetooth::BluetoothDevice* device) {
419 DCHECK(adapter == adapter_.get()); 432 DCHECK(adapter == adapter_.get());
420 DCHECK(device); 433 DCHECK(device);
421 434
422 base::StringValue address(device->address()); 435 base::StringValue address(device->address());
423 web_ui()->CallJavascriptFunction( 436 web_ui()->CallJavascriptFunction(
424 "options.BrowserOptions.removeBluetoothDevice", 437 "options.BrowserOptions.removeBluetoothDevice",
425 address); 438 address);
426 } 439 }
427 440
428 } // namespace options 441 } // namespace options
429 } // namespace chromeos 442 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698