OLD | NEW |
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/options2/chromeos/bluetooth_options_handler2.h
" | 5 #include "chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 11 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
12 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 12 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
13 #include "chrome/browser/chromeos/system/runtime_environment.h" | 13 #include "chrome/browser/chromeos/system/runtime_environment.h" |
14 #include "chrome/browser/ui/webui/options2/chromeos/system_settings_provider2.h" | 14 #include "chrome/browser/ui/webui/options2/chromeos/system_settings_provider2.h" |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
17 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 // |UpdateDeviceCallback| takes a variable length list as an argument. The | 23 // |UpdateDeviceCallback| takes a variable length list as an argument. The |
25 // value stored in each list element is indicated by the following constants. | 24 // value stored in each list element is indicated by the following constants. |
26 const int kUpdateDeviceAddressIndex = 0; | 25 const int kUpdateDeviceAddressIndex = 0; |
27 const int kUpdateDeviceCommandIndex = 1; | 26 const int kUpdateDeviceCommandIndex = 1; |
28 const int kUpdateDevicePasskeyIndex = 2; | 27 const int kUpdateDevicePasskeyIndex = 2; |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 namespace chromeos { | 31 namespace chromeos { |
33 namespace options2 { | 32 namespace options2 { |
34 | 33 |
35 BluetoothOptionsHandler::BluetoothOptionsHandler() { | 34 BluetoothOptionsHandler::BluetoothOptionsHandler() { |
36 } | 35 } |
37 | 36 |
38 BluetoothOptionsHandler::~BluetoothOptionsHandler() { | 37 BluetoothOptionsHandler::~BluetoothOptionsHandler() { |
39 if (!CommandLine::ForCurrentProcess() | |
40 ->HasSwitch(switches::kEnableBluetooth)) { | |
41 return; | |
42 } | |
43 | |
44 adapter_->RemoveObserver(this); | 38 adapter_->RemoveObserver(this); |
45 } | 39 } |
46 | 40 |
47 void BluetoothOptionsHandler::GetLocalizedValues( | 41 void BluetoothOptionsHandler::GetLocalizedValues( |
48 DictionaryValue* localized_strings) { | 42 DictionaryValue* localized_strings) { |
49 DCHECK(localized_strings); | 43 DCHECK(localized_strings); |
50 localized_strings->SetString("bluetooth", | 44 localized_strings->SetString("bluetooth", |
51 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); | 45 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); |
52 localized_strings->SetString("disableBluetooth", | 46 localized_strings->SetString("disableBluetooth", |
53 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISABLE)); | 47 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISABLE)); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery", | 159 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery", |
166 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback, | 160 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback, |
167 base::Unretained(this))); | 161 base::Unretained(this))); |
168 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices", | 162 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices", |
169 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback, | 163 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback, |
170 base::Unretained(this))); | 164 base::Unretained(this))); |
171 } | 165 } |
172 | 166 |
173 void BluetoothOptionsHandler::InitializeBluetoothStatusCallback( | 167 void BluetoothOptionsHandler::InitializeBluetoothStatusCallback( |
174 const ListValue* args) { | 168 const ListValue* args) { |
175 // Bluetooth support is a work in progress. Supress the feature unless | |
176 // explicitly enabled via a command line flag. | |
177 if (!CommandLine::ForCurrentProcess() | |
178 ->HasSwitch(switches::kEnableBluetooth)) { | |
179 return; | |
180 } | |
181 adapter_.reset(BluetoothAdapter::CreateDefaultAdapter()); | 169 adapter_.reset(BluetoothAdapter::CreateDefaultAdapter()); |
182 adapter_->AddObserver(this); | 170 adapter_->AddObserver(this); |
183 // Show or hide the bluetooth settings and update the checkbox based | 171 // Show or hide the bluetooth settings and update the checkbox based |
184 // on the current present/powered state. | 172 // on the current present/powered state. |
185 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent()); | 173 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent()); |
186 } | 174 } |
187 | 175 |
188 void BluetoothOptionsHandler::EnableChangeCallback( | 176 void BluetoothOptionsHandler::EnableChangeCallback( |
189 const ListValue* args) { | 177 const ListValue* args) { |
190 bool bluetooth_enabled; | 178 bool bluetooth_enabled; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 void BluetoothOptionsHandler::ErrorCallback() { | 337 void BluetoothOptionsHandler::ErrorCallback() { |
350 // TODO(keybuk): we don't get any form of error response from dbus:: | 338 // TODO(keybuk): we don't get any form of error response from dbus:: |
351 // yet, other than an error occurred. I'm going to fix that, then this | 339 // yet, other than an error occurred. I'm going to fix that, then this |
352 // gets replaced by genuine error information from the method which we | 340 // gets replaced by genuine error information from the method which we |
353 // can act on, rather than a debug log statement. | 341 // can act on, rather than a debug log statement. |
354 DVLOG(1) << "Failed."; | 342 DVLOG(1) << "Failed."; |
355 } | 343 } |
356 | 344 |
357 } // namespace options2 | 345 } // namespace options2 |
358 } // namespace chromeos | 346 } // namespace chromeos |
OLD | NEW |