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

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc

Issue 9693032: [uber page] Split up initialization of handlers from initialization of webui pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros compile fix, still issues Created 8 years, 9 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/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"
(...skipping 14 matching lines...) Expand all
25 // value stored in each list element is indicated by the following constants. 25 // value stored in each list element is indicated by the following constants.
26 const int kUpdateDeviceAddressIndex = 0; 26 const int kUpdateDeviceAddressIndex = 0;
27 const int kUpdateDeviceCommandIndex = 1; 27 const int kUpdateDeviceCommandIndex = 1;
28 const int kUpdateDevicePasskeyIndex = 2; 28 const int kUpdateDevicePasskeyIndex = 2;
29 29
30 } // namespace 30 } // namespace
31 31
32 namespace chromeos { 32 namespace chromeos {
33 namespace options2 { 33 namespace options2 {
34 34
35 BluetoothOptionsHandler::BluetoothOptionsHandler() { 35 BluetoothOptionsHandler::BluetoothOptionsHandler()
36 : bluetooth_enabled_(CommandLine::ForCurrentProcess()
37 ->HasSwitch(switches::kEnableBluetooth)) {
36 } 38 }
37 39
38 BluetoothOptionsHandler::~BluetoothOptionsHandler() { 40 BluetoothOptionsHandler::~BluetoothOptionsHandler() {
39 if (!CommandLine::ForCurrentProcess() 41 if (bluetooth_enabled_ && adapter_.get())
40 ->HasSwitch(switches::kEnableBluetooth)) { 42 adapter_->RemoveObserver(this);
41 return;
42 }
43
44 adapter_->RemoveObserver(this);
45 } 43 }
46 44
47 void BluetoothOptionsHandler::GetLocalizedValues( 45 void BluetoothOptionsHandler::GetLocalizedValues(
48 DictionaryValue* localized_strings) { 46 DictionaryValue* localized_strings) {
49 DCHECK(localized_strings); 47 DCHECK(localized_strings);
50 localized_strings->SetString("bluetooth", 48 localized_strings->SetString("bluetooth",
51 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); 49 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH));
52 localized_strings->SetString("disableBluetooth", 50 localized_strings->SetString("disableBluetooth",
53 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISABLE)); 51 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISABLE));
54 localized_strings->SetString("enableBluetooth", 52 localized_strings->SetString("enableBluetooth",
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 l10n_util::GetStringUTF16( 114 l10n_util::GetStringUTF16(
117 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED_INCORRECT_PIN)); 115 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED_INCORRECT_PIN));
118 localized_strings->SetString("bluetoothErrorTimeout", 116 localized_strings->SetString("bluetoothErrorTimeout",
119 l10n_util::GetStringUTF16( 117 l10n_util::GetStringUTF16(
120 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED_TIMEOUT)); 118 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED_TIMEOUT));
121 localized_strings->SetString("bluetoothErrorConnectionFailed", 119 localized_strings->SetString("bluetoothErrorConnectionFailed",
122 l10n_util::GetStringUTF16( 120 l10n_util::GetStringUTF16(
123 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED)); 121 IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTION_FAILED));
124 } 122 }
125 123
126 void BluetoothOptionsHandler::Initialize() { 124 void BluetoothOptionsHandler::InitializeHandler() {
127 // Bluetooth support is a work in progress. Supress the feature unless 125 // Bluetooth support is a work in progress. Supress the feature unless
128 // explicitly enabled via a command line flag. 126 // explicitly enabled via a command line flag.
129 if (!CommandLine::ForCurrentProcess() 127 if (bluetooth_enabled_) {
130 ->HasSwitch(switches::kEnableBluetooth)) { 128 adapter_.reset(BluetoothAdapter::CreateDefaultAdapter());
131 return; 129 adapter_->AddObserver(this);
132 } 130 }
131 }
133 132
134 adapter_.reset(BluetoothAdapter::CreateDefaultAdapter()); 133 void BluetoothOptionsHandler::InitializePage() {
135 adapter_->AddObserver(this); 134 // Show or hide the bluetooth settings and update the checkbox based on the
136 135 // current present/powered state.
137 // Show or hide the bluetooth settings and update the checkbox based 136 if (bluetooth_enabled_)
138 // on the current present/powered state. 137 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent());
139 AdapterPresentChanged(adapter_.get(), adapter_->IsPresent());
140 } 138 }
141 139
142 void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter, 140 void BluetoothOptionsHandler::AdapterPresentChanged(BluetoothAdapter* adapter,
143 bool present) { 141 bool present) {
144 DCHECK(adapter == adapter_.get()); 142 DCHECK(adapter == adapter_.get());
145 if (present) { 143 if (present) {
146 web_ui()->CallJavascriptFunction( 144 web_ui()->CallJavascriptFunction(
147 "options.BrowserOptions.showBluetoothSettings"); 145 "options.BrowserOptions.showBluetoothSettings");
148 146
149 // Update the checkbox and visibility based on the powered state of the 147 // Update the checkbox and visibility based on the powered state of the
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 void BluetoothOptionsHandler::ErrorCallback() { 344 void BluetoothOptionsHandler::ErrorCallback() {
347 // TODO(keybuk): we don't get any form of error response from dbus:: 345 // TODO(keybuk): we don't get any form of error response from dbus::
348 // yet, other than an error occurred. I'm going to fix that, then this 346 // yet, other than an error occurred. I'm going to fix that, then this
349 // gets replaced by genuine error information from the method which we 347 // gets replaced by genuine error information from the method which we
350 // can act on, rather than a debug log statement. 348 // can act on, rather than a debug log statement.
351 DVLOG(1) << "Failed."; 349 DVLOG(1) << "Failed.";
352 } 350 }
353 351
354 } // namespace options2 352 } // namespace options2
355 } // namespace chromeos 353 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698