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

Side by Side Diff: chrome/browser/ui/ash/tray_bluetooth_helper.cc

Issue 2753313002: cros: Init SystemTrayDelegate earlier to break bluetooth init dependency (Closed)
Patch Set: fix test Created 3 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ash/tray_bluetooth_helper.h" 5 #include "chrome/browser/ui/ash/tray_bluetooth_helper.h"
6 6
7 #include "ash/common/system/tray/system_tray_delegate.h"
7 #include "ash/common/system/tray/system_tray_notifier.h" 8 #include "ash/common/system/tray/system_tray_notifier.h"
8 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
12 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h" 13 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
13 #include "chrome/browser/ui/ash/system_tray_client.h" 14 #include "chrome/browser/ui/ash/system_tray_client.h"
14 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
15 #include "device/bluetooth/bluetooth_adapter.h" 15 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_adapter_factory.h" 16 #include "device/bluetooth/bluetooth_adapter_factory.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_discovery_session.h" 18 #include "device/bluetooth/bluetooth_discovery_session.h"
19 19
20 using chromeos::BluetoothPairingDialog; 20 using chromeos::BluetoothPairingDialog;
21 21
22 namespace { 22 namespace {
23 23
24 void BluetoothSetDiscoveringError() { 24 void BluetoothSetDiscoveringError() {
25 LOG(ERROR) << "BluetoothSetDiscovering failed."; 25 LOG(ERROR) << "BluetoothSetDiscovering failed.";
26 } 26 }
27 27
28 void BluetoothDeviceConnectError( 28 void BluetoothDeviceConnectError(
29 device::BluetoothDevice::ConnectErrorCode error_code) {} 29 device::BluetoothDevice::ConnectErrorCode error_code) {}
30 30
31 ash::SystemTrayNotifier* GetSystemTrayNotifier() { 31 ash::SystemTrayNotifier* GetSystemTrayNotifier() {
32 return ash::WmShell::Get()->system_tray_notifier(); 32 return ash::WmShell::Get()->system_tray_notifier();
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 TrayBluetoothHelper::TrayBluetoothHelper( 37 TrayBluetoothHelper::TrayBluetoothHelper() : weak_ptr_factory_(this) {}
38 chromeos::SystemTrayDelegateChromeOS* system_tray_delegate)
39 : system_tray_delegate_(system_tray_delegate), weak_ptr_factory_(this) {}
40 38
41 TrayBluetoothHelper::~TrayBluetoothHelper() { 39 TrayBluetoothHelper::~TrayBluetoothHelper() {
42 if (adapter_) 40 if (adapter_)
43 adapter_->RemoveObserver(this); 41 adapter_->RemoveObserver(this);
44 } 42 }
45 43
46 void TrayBluetoothHelper::Initialize() { 44 void TrayBluetoothHelper::Initialize() {
47 device::BluetoothAdapterFactory::GetAdapter( 45 device::BluetoothAdapterFactory::GetAdapter(
48 base::Bind(&TrayBluetoothHelper::InitializeOnAdapterReady, 46 base::Bind(&TrayBluetoothHelper::InitializeOnAdapterReady,
49 weak_ptr_factory_.GetWeakPtr())); 47 weak_ptr_factory_.GetWeakPtr()));
50 } 48 }
51 49
52 void TrayBluetoothHelper::InitializeOnAdapterReady( 50 void TrayBluetoothHelper::InitializeOnAdapterReady(
53 scoped_refptr<device::BluetoothAdapter> adapter) { 51 scoped_refptr<device::BluetoothAdapter> adapter) {
54 adapter_ = adapter; 52 adapter_ = adapter;
55 CHECK(adapter_); 53 CHECK(adapter_);
56 adapter_->AddObserver(this); 54 adapter_->AddObserver(this);
57
58 // May be null in tests.
59 if (system_tray_delegate_)
60 system_tray_delegate_->InitializeOnAdapterReady();
61 } 55 }
62 56
63 void TrayBluetoothHelper::GetAvailableDevices( 57 void TrayBluetoothHelper::GetAvailableDevices(
64 std::vector<ash::BluetoothDeviceInfo>* list) { 58 std::vector<ash::BluetoothDeviceInfo>* list) {
65 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 59 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
66 for (device::BluetoothDevice* device : devices) { 60 for (device::BluetoothDevice* device : devices) {
67 ash::BluetoothDeviceInfo info; 61 ash::BluetoothDeviceInfo info;
68 info.address = device->GetAddress(); 62 info.address = device->GetAddress();
69 info.display_name = device->GetNameForDisplay(); 63 info.display_name = device->GetNameForDisplay();
70 info.connected = device->IsConnected(); 64 info.connected = device->IsConnected();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { 178 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
185 // If the discovery session was returned after a request to stop discovery 179 // If the discovery session was returned after a request to stop discovery
186 // (e.g. the user dismissed the Bluetooth detailed view before the call 180 // (e.g. the user dismissed the Bluetooth detailed view before the call
187 // returned), don't claim the discovery session and let it clean up. 181 // returned), don't claim the discovery session and let it clean up.
188 if (!should_run_discovery_) 182 if (!should_run_discovery_)
189 return; 183 return;
190 VLOG(1) << "Claiming new Bluetooth device discovery session."; 184 VLOG(1) << "Claiming new Bluetooth device discovery session.";
191 discovery_session_ = std::move(discovery_session); 185 discovery_session_ = std::move(discovery_session);
192 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged(); 186 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
193 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/tray_bluetooth_helper.h ('k') | chrome/browser/ui/ash/tray_bluetooth_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698