OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bluetooth/bluetooth_chooser_bubble_delegate.h" | 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" | 8 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "components/bubble/bubble_controller.h" | 10 #include "components/bubble/bubble_controller.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
13 BluetoothChooserBubbleDelegate::BluetoothChooserBubbleDelegate( | 13 BluetoothChooserBubbleController::BluetoothChooserBubbleController( |
14 content::RenderFrameHost* owner) | 14 content::RenderFrameHost* owner) |
15 : ChooserBubbleDelegate(owner), bluetooth_chooser_(nullptr) {} | 15 : ChooserBubbleController(owner), bluetooth_chooser_(nullptr) {} |
16 | 16 |
17 BluetoothChooserBubbleDelegate::~BluetoothChooserBubbleDelegate() { | 17 BluetoothChooserBubbleController::~BluetoothChooserBubbleController() { |
18 if (bluetooth_chooser_) | 18 if (bluetooth_chooser_) |
19 bluetooth_chooser_->set_bluetooth_chooser_bubble_delegate(nullptr); | 19 bluetooth_chooser_->set_bluetooth_chooser_bubble_controller(nullptr); |
20 } | 20 } |
21 | 21 |
22 size_t BluetoothChooserBubbleDelegate::NumOptions() const { | 22 size_t BluetoothChooserBubbleController::NumOptions() const { |
23 return device_names_and_ids_.size(); | 23 return device_names_and_ids_.size(); |
24 } | 24 } |
25 | 25 |
26 const base::string16& BluetoothChooserBubbleDelegate::GetOption( | 26 const base::string16& BluetoothChooserBubbleController::GetOption( |
27 size_t index) const { | 27 size_t index) const { |
28 DCHECK_LT(index, device_names_and_ids_.size()); | 28 DCHECK_LT(index, device_names_and_ids_.size()); |
29 return device_names_and_ids_[index].first; | 29 return device_names_and_ids_[index].first; |
30 } | 30 } |
31 | 31 |
32 void BluetoothChooserBubbleDelegate::Select(size_t index) { | 32 void BluetoothChooserBubbleController::Select(size_t index) { |
33 DCHECK_LT(index, device_names_and_ids_.size()); | 33 DCHECK_LT(index, device_names_and_ids_.size()); |
34 if (bluetooth_chooser_) { | 34 if (bluetooth_chooser_) { |
35 bluetooth_chooser_->CallEventHandler( | 35 bluetooth_chooser_->CallEventHandler( |
36 content::BluetoothChooser::Event::SELECTED, | 36 content::BluetoothChooser::Event::SELECTED, |
37 device_names_and_ids_[index].second); | 37 device_names_and_ids_[index].second); |
38 } | 38 } |
39 | 39 |
40 if (bubble_controller_) | 40 if (bubble_reference_) |
41 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); | 41 bubble_reference_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); |
42 } | 42 } |
43 | 43 |
44 void BluetoothChooserBubbleDelegate::Cancel() { | 44 void BluetoothChooserBubbleController::Cancel() { |
45 if (bluetooth_chooser_) { | 45 if (bluetooth_chooser_) { |
46 bluetooth_chooser_->CallEventHandler( | 46 bluetooth_chooser_->CallEventHandler( |
47 content::BluetoothChooser::Event::CANCELLED, std::string()); | 47 content::BluetoothChooser::Event::CANCELLED, std::string()); |
48 } | 48 } |
49 | 49 |
50 if (bubble_controller_) | 50 if (bubble_reference_) |
51 bubble_controller_->CloseBubble(BUBBLE_CLOSE_CANCELED); | 51 bubble_reference_->CloseBubble(BUBBLE_CLOSE_CANCELED); |
52 } | 52 } |
53 | 53 |
54 void BluetoothChooserBubbleDelegate::Close() { | 54 void BluetoothChooserBubbleController::Close() { |
55 if (bluetooth_chooser_) { | 55 if (bluetooth_chooser_) { |
56 bluetooth_chooser_->CallEventHandler( | 56 bluetooth_chooser_->CallEventHandler( |
57 content::BluetoothChooser::Event::CANCELLED, std::string()); | 57 content::BluetoothChooser::Event::CANCELLED, std::string()); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 GURL BluetoothChooserBubbleDelegate::GetHelpCenterUrl() const { | 61 GURL BluetoothChooserBubbleController::GetHelpCenterUrl() const { |
62 return GURL(chrome::kChooserBluetoothOverviewURL); | 62 return GURL(chrome::kChooserBluetoothOverviewURL); |
63 } | 63 } |
64 | 64 |
65 void BluetoothChooserBubbleDelegate::AddDevice( | 65 void BluetoothChooserBubbleController::AddDevice( |
66 const std::string& device_id, | 66 const std::string& device_id, |
67 const base::string16& device_name) { | 67 const base::string16& device_name) { |
68 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); | 68 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); |
69 if (observer()) | 69 if (observer()) |
70 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); | 70 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); |
71 } | 71 } |
72 | 72 |
73 void BluetoothChooserBubbleDelegate::RemoveDevice( | 73 void BluetoothChooserBubbleController::RemoveDevice( |
74 const std::string& device_id) { | 74 const std::string& device_id) { |
75 for (auto it = device_names_and_ids_.begin(); | 75 for (auto it = device_names_and_ids_.begin(); |
76 it != device_names_and_ids_.end(); ++it) { | 76 it != device_names_and_ids_.end(); ++it) { |
77 if (it->second == device_id) { | 77 if (it->second == device_id) { |
78 size_t index = it - device_names_and_ids_.begin(); | 78 size_t index = it - device_names_and_ids_.begin(); |
79 device_names_and_ids_.erase(it); | 79 device_names_and_ids_.erase(it); |
80 if (observer()) | 80 if (observer()) |
81 observer()->OnOptionRemoved(index); | 81 observer()->OnOptionRemoved(index); |
82 return; | 82 return; |
83 } | 83 } |
84 } | 84 } |
85 } | 85 } |
OLD | NEW |