From a2ad62074ea877b0440571c074fe49352e49aa4f Mon Sep 17 00:00:00 2001 From: juncai Date: Fri, 26 Feb 2016 13:56:55 -0800 Subject: Change ChooserBubbleDelegate class name to ChooserBubbleController This patch changed ChooserBubbleDelegate class name to ChooserBubbleController since it better reflects the class's responsibilities and clarifies the roles of the class. BUG=492204, 588933 Review URL: https://codereview.chromium.org/1724183005 Cr-Commit-Position: refs/heads/master@{#377989} --- .../bluetooth_chooser_bubble_controller.cc | 85 ++++++++++++++++++++++ .../bluetooth_chooser_bubble_controller.h | 57 +++++++++++++++ .../bluetooth/bluetooth_chooser_bubble_delegate.cc | 85 ---------------------- .../bluetooth/bluetooth_chooser_bubble_delegate.h | 57 --------------- .../ui/bluetooth/bluetooth_chooser_desktop.cc | 16 ++-- .../ui/bluetooth/bluetooth_chooser_desktop.h | 10 +-- 6 files changed, 155 insertions(+), 155 deletions(-) create mode 100644 chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.cc create mode 100644 chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h delete mode 100644 chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.cc delete mode 100644 chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h (limited to 'chrome/browser/ui/bluetooth') diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.cc new file mode 100644 index 0000000..9e9e280 --- /dev/null +++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.cc @@ -0,0 +1,85 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h" + +#include "base/stl_util.h" +#include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" +#include "chrome/common/url_constants.h" +#include "components/bubble/bubble_controller.h" +#include "url/gurl.h" + +BluetoothChooserBubbleController::BluetoothChooserBubbleController( + content::RenderFrameHost* owner) + : ChooserBubbleController(owner), bluetooth_chooser_(nullptr) {} + +BluetoothChooserBubbleController::~BluetoothChooserBubbleController() { + if (bluetooth_chooser_) + bluetooth_chooser_->set_bluetooth_chooser_bubble_controller(nullptr); +} + +size_t BluetoothChooserBubbleController::NumOptions() const { + return device_names_and_ids_.size(); +} + +const base::string16& BluetoothChooserBubbleController::GetOption( + size_t index) const { + DCHECK_LT(index, device_names_and_ids_.size()); + return device_names_and_ids_[index].first; +} + +void BluetoothChooserBubbleController::Select(size_t index) { + DCHECK_LT(index, device_names_and_ids_.size()); + if (bluetooth_chooser_) { + bluetooth_chooser_->CallEventHandler( + content::BluetoothChooser::Event::SELECTED, + device_names_and_ids_[index].second); + } + + if (bubble_reference_) + bubble_reference_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); +} + +void BluetoothChooserBubbleController::Cancel() { + if (bluetooth_chooser_) { + bluetooth_chooser_->CallEventHandler( + content::BluetoothChooser::Event::CANCELLED, std::string()); + } + + if (bubble_reference_) + bubble_reference_->CloseBubble(BUBBLE_CLOSE_CANCELED); +} + +void BluetoothChooserBubbleController::Close() { + if (bluetooth_chooser_) { + bluetooth_chooser_->CallEventHandler( + content::BluetoothChooser::Event::CANCELLED, std::string()); + } +} + +GURL BluetoothChooserBubbleController::GetHelpCenterUrl() const { + return GURL(chrome::kChooserBluetoothOverviewURL); +} + +void BluetoothChooserBubbleController::AddDevice( + const std::string& device_id, + const base::string16& device_name) { + device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); + if (observer()) + observer()->OnOptionAdded(device_names_and_ids_.size() - 1); +} + +void BluetoothChooserBubbleController::RemoveDevice( + const std::string& device_id) { + for (auto it = device_names_and_ids_.begin(); + it != device_names_and_ids_.end(); ++it) { + if (it->second == device_id) { + size_t index = it - device_names_and_ids_.begin(); + device_names_and_ids_.erase(it); + if (observer()) + observer()->OnOptionRemoved(index); + return; + } + } +} diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h new file mode 100644 index 0000000..f619e13 --- /dev/null +++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h @@ -0,0 +1,57 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_CONTROLLER_H_ +#define CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_CONTROLLER_H_ + +#include + +#include "base/macros.h" +#include "chrome/browser/ui/website_settings/chooser_bubble_controller.h" +#include "components/bubble/bubble_reference.h" + +class BluetoothChooserDesktop; + +// BluetoothChooserBubbleController is a chooser that presents a list of +// Bluetooth device names, which come from |bluetooth_chooser_desktop_|. +// It can be used by WebBluetooth API to get the user's permission to +// access a Bluetooth device. +class BluetoothChooserBubbleController : public ChooserBubbleController { + public: + explicit BluetoothChooserBubbleController(content::RenderFrameHost* owner); + ~BluetoothChooserBubbleController() override; + + // ChooserBubbleController: + size_t NumOptions() const override; + const base::string16& GetOption(size_t index) const override; + void Select(size_t index) override; + void Cancel() override; + void Close() override; + GURL GetHelpCenterUrl() const override; + + // Shows a new device in the chooser. + void AddDevice(const std::string& device_id, + const base::string16& device_name); + + // Tells the chooser that a device is no longer available. + void RemoveDevice(const std::string& device_id); + + void set_bluetooth_chooser(BluetoothChooserDesktop* bluetooth_chooser) { + bluetooth_chooser_ = bluetooth_chooser; + } + + void set_bubble_reference(BubbleReference bubble_reference) { + bubble_reference_ = bubble_reference; + } + + private: + // Each pair is a (device name, device id). + std::vector> device_names_and_ids_; + BluetoothChooserDesktop* bluetooth_chooser_; + BubbleReference bubble_reference_; + + DISALLOW_COPY_AND_ASSIGN(BluetoothChooserBubbleController); +}; + +#endif // CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_CONTROLLER_H_ diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.cc deleted file mode 100644 index 10ad62b..0000000 --- a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h" - -#include "base/stl_util.h" -#include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" -#include "chrome/common/url_constants.h" -#include "components/bubble/bubble_controller.h" -#include "url/gurl.h" - -BluetoothChooserBubbleDelegate::BluetoothChooserBubbleDelegate( - content::RenderFrameHost* owner) - : ChooserBubbleDelegate(owner), bluetooth_chooser_(nullptr) {} - -BluetoothChooserBubbleDelegate::~BluetoothChooserBubbleDelegate() { - if (bluetooth_chooser_) - bluetooth_chooser_->set_bluetooth_chooser_bubble_delegate(nullptr); -} - -size_t BluetoothChooserBubbleDelegate::NumOptions() const { - return device_names_and_ids_.size(); -} - -const base::string16& BluetoothChooserBubbleDelegate::GetOption( - size_t index) const { - DCHECK_LT(index, device_names_and_ids_.size()); - return device_names_and_ids_[index].first; -} - -void BluetoothChooserBubbleDelegate::Select(size_t index) { - DCHECK_LT(index, device_names_and_ids_.size()); - if (bluetooth_chooser_) { - bluetooth_chooser_->CallEventHandler( - content::BluetoothChooser::Event::SELECTED, - device_names_and_ids_[index].second); - } - - if (bubble_controller_) - bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); -} - -void BluetoothChooserBubbleDelegate::Cancel() { - if (bluetooth_chooser_) { - bluetooth_chooser_->CallEventHandler( - content::BluetoothChooser::Event::CANCELLED, std::string()); - } - - if (bubble_controller_) - bubble_controller_->CloseBubble(BUBBLE_CLOSE_CANCELED); -} - -void BluetoothChooserBubbleDelegate::Close() { - if (bluetooth_chooser_) { - bluetooth_chooser_->CallEventHandler( - content::BluetoothChooser::Event::CANCELLED, std::string()); - } -} - -GURL BluetoothChooserBubbleDelegate::GetHelpCenterUrl() const { - return GURL(chrome::kChooserBluetoothOverviewURL); -} - -void BluetoothChooserBubbleDelegate::AddDevice( - const std::string& device_id, - const base::string16& device_name) { - device_names_and_ids_.push_back(std::make_pair(device_name, device_id)); - if (observer()) - observer()->OnOptionAdded(device_names_and_ids_.size() - 1); -} - -void BluetoothChooserBubbleDelegate::RemoveDevice( - const std::string& device_id) { - for (auto it = device_names_and_ids_.begin(); - it != device_names_and_ids_.end(); ++it) { - if (it->second == device_id) { - size_t index = it - device_names_and_ids_.begin(); - device_names_and_ids_.erase(it); - if (observer()) - observer()->OnOptionRemoved(index); - return; - } - } -} diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h b/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h deleted file mode 100644 index 26d2455..0000000 --- a/chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_DELEGATE_H_ -#define CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_DELEGATE_H_ - -#include - -#include "base/macros.h" -#include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" -#include "components/bubble/bubble_reference.h" - -class BluetoothChooserDesktop; - -// BluetoothChooserBubbleDelegate is a chooser that presents a list of -// Bluetooth device names, which come from |bluetooth_chooser_desktop_|. -// It can be used by WebBluetooth API to get the user's permission to -// access a Bluetooth device. -class BluetoothChooserBubbleDelegate : public ChooserBubbleDelegate { - public: - explicit BluetoothChooserBubbleDelegate(content::RenderFrameHost* owner); - ~BluetoothChooserBubbleDelegate() override; - - // ChooserBubbleDelegate: - size_t NumOptions() const override; - const base::string16& GetOption(size_t index) const override; - void Select(size_t index) override; - void Cancel() override; - void Close() override; - GURL GetHelpCenterUrl() const override; - - // Shows a new device in the chooser. - void AddDevice(const std::string& device_id, - const base::string16& device_name); - - // Tells the chooser that a device is no longer available. - void RemoveDevice(const std::string& device_id); - - void set_bluetooth_chooser(BluetoothChooserDesktop* bluetooth_chooser) { - bluetooth_chooser_ = bluetooth_chooser; - } - - void set_bubble_controller(BubbleReference bubble_controller) { - bubble_controller_ = bubble_controller; - } - - private: - // Each pair is a (device name, device id). - std::vector> device_names_and_ids_; - BluetoothChooserDesktop* bluetooth_chooser_; - BubbleReference bubble_controller_; - - DISALLOW_COPY_AND_ASSIGN(BluetoothChooserBubbleDelegate); -}; - -#endif // CHROME_BROWSER_UI_BLUETOOTH_BLUETOOTH_CHOOSER_BUBBLE_DELEGATE_H_ diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.cc index 91bc638..b014048 100644 --- a/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.cc +++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.cc @@ -4,16 +4,16 @@ #include "chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h" -#include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_delegate.h" +#include "chrome/browser/ui/bluetooth/bluetooth_chooser_bubble_controller.h" BluetoothChooserDesktop::BluetoothChooserDesktop( const content::BluetoothChooser::EventHandler& event_handler) : event_handler_(event_handler), - bluetooth_chooser_bubble_delegate_(nullptr) {} + bluetooth_chooser_bubble_controller_(nullptr) {} BluetoothChooserDesktop::~BluetoothChooserDesktop() { - if (bluetooth_chooser_bubble_delegate_) - bluetooth_chooser_bubble_delegate_->set_bluetooth_chooser(nullptr); + if (bluetooth_chooser_bubble_controller_) + bluetooth_chooser_bubble_controller_->set_bluetooth_chooser(nullptr); } void BluetoothChooserDesktop::SetAdapterPresence(AdapterPresence presence) {} @@ -22,13 +22,13 @@ void BluetoothChooserDesktop::ShowDiscoveryState(DiscoveryState state) {} void BluetoothChooserDesktop::AddDevice(const std::string& device_id, const base::string16& device_name) { - if (bluetooth_chooser_bubble_delegate_) - bluetooth_chooser_bubble_delegate_->AddDevice(device_id, device_name); + if (bluetooth_chooser_bubble_controller_) + bluetooth_chooser_bubble_controller_->AddDevice(device_id, device_name); } void BluetoothChooserDesktop::RemoveDevice(const std::string& device_id) { - if (bluetooth_chooser_bubble_delegate_) - bluetooth_chooser_bubble_delegate_->RemoveDevice(device_id); + if (bluetooth_chooser_bubble_controller_) + bluetooth_chooser_bubble_controller_->RemoveDevice(device_id); } void BluetoothChooserDesktop::CallEventHandler( diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h b/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h index 9809640..ccd2817 100644 --- a/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h +++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_desktop.h @@ -8,7 +8,7 @@ #include "base/macros.h" #include "content/public/browser/bluetooth_chooser.h" -class BluetoothChooserBubbleDelegate; +class BluetoothChooserBubbleController; // Represents a Bluetooth chooser to ask the user to select a Bluetooth // device from a list of options. This implementation is for desktop. @@ -26,9 +26,9 @@ class BluetoothChooserDesktop : public content::BluetoothChooser { const base::string16& device_name) override; void RemoveDevice(const std::string& device_id) override; - void set_bluetooth_chooser_bubble_delegate( - BluetoothChooserBubbleDelegate* bluetooth_chooser_bubble_delegate) { - bluetooth_chooser_bubble_delegate_ = bluetooth_chooser_bubble_delegate; + void set_bluetooth_chooser_bubble_controller( + BluetoothChooserBubbleController* bluetooth_chooser_bubble_controller) { + bluetooth_chooser_bubble_controller_ = bluetooth_chooser_bubble_controller; } // Use this function to call event_handler_. @@ -37,7 +37,7 @@ class BluetoothChooserDesktop : public content::BluetoothChooser { private: content::BluetoothChooser::EventHandler event_handler_; - BluetoothChooserBubbleDelegate* bluetooth_chooser_bubble_delegate_; + BluetoothChooserBubbleController* bluetooth_chooser_bubble_controller_; DISALLOW_COPY_AND_ASSIGN(BluetoothChooserDesktop); }; -- cgit v1.1