OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" |
| 6 |
| 7 #include "chrome/browser/net/referrer.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 12 #include "chrome/common/url_constants.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 Browser* GetBrowser() { |
| 18 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
| 19 ProfileManager::GetActiveUserProfile()); |
| 20 DCHECK(browser_displayer.browser()); |
| 21 return browser_displayer.browser(); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 BluetoothChooserController::BluetoothChooserController( |
| 27 content::RenderFrameHost* owner, |
| 28 const content::BluetoothChooser::EventHandler& event_handler) |
| 29 : ChooserController(owner), event_handler_(event_handler) {} |
| 30 |
| 31 BluetoothChooserController::~BluetoothChooserController() {} |
| 32 |
| 33 size_t BluetoothChooserController::NumOptions() const { |
| 34 return device_names_and_ids_.size(); |
| 35 } |
| 36 |
| 37 const base::string16& BluetoothChooserController::GetOption( |
| 38 size_t index) const { |
| 39 DCHECK_LT(index, device_names_and_ids_.size()); |
| 40 return device_names_and_ids_[index].first; |
| 41 } |
| 42 |
| 43 void BluetoothChooserController::Select(size_t index) { |
| 44 DCHECK_LT(index, device_names_and_ids_.size()); |
| 45 event_handler_.Run(content::BluetoothChooser::Event::SELECTED, |
| 46 device_names_and_ids_[index].second); |
| 47 } |
| 48 |
| 49 void BluetoothChooserController::Cancel() { |
| 50 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 51 std::string()); |
| 52 } |
| 53 |
| 54 void BluetoothChooserController::Close() { |
| 55 event_handler_.Run(content::BluetoothChooser::Event::CANCELLED, |
| 56 std::string()); |
| 57 } |
| 58 |
| 59 void BluetoothChooserController::OpenHelpCenterUrl() const { |
| 60 GetBrowser()->OpenURL(content::OpenURLParams( |
| 61 GURL(chrome::kChooserBluetoothOverviewURL), content::Referrer(), |
| 62 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 63 false /* is_renderer_initialized */)); |
| 64 } |
| 65 |
| 66 void BluetoothChooserController::AddDevice(const std::string& device_id, |
| 67 const base::string16& device_name) { |
| 68 device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); |
| 69 if (observer()) |
| 70 observer()->OnOptionAdded(device_names_and_ids_.size() - 1); |
| 71 } |
| 72 |
| 73 void BluetoothChooserController::RemoveDevice(const std::string& device_id) { |
| 74 for (auto it = device_names_and_ids_.begin(); |
| 75 it != device_names_and_ids_.end(); ++it) { |
| 76 if (it->second == device_id) { |
| 77 size_t index = it - device_names_and_ids_.begin(); |
| 78 device_names_and_ids_.erase(it); |
| 79 if (observer()) |
| 80 observer()->OnOptionRemoved(index); |
| 81 return; |
| 82 } |
| 83 } |
| 84 } |
OLD | NEW |