Commit 718a42f9 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[SendTabToSelf] Polishing code

Fix nits to make code clearer.

Bug: 980277
Change-Id: I08c6f04fba7e78482f01fbd5ed5f6a0b1eb09a4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1706556Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680108}
parent 28c33259
...@@ -1256,19 +1256,18 @@ void RenderViewContextMenu::AppendLinkItems() { ...@@ -1256,19 +1256,18 @@ void RenderViewContextMenu::AppendLinkItems() {
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
if (send_tab_to_self::GetValidDeviceCount(GetBrowser()->profile()) == 1) { if (send_tab_to_self::GetValidDeviceCount(GetBrowser()->profile()) == 1) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
menu_model_.AddItem( menu_model_.AddItem(IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET,
IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET, l10n_util::GetStringFUTF16(
l10n_util::GetStringFUTF16( IDS_LINK_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
IDS_LINK_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, send_tab_to_self::GetSingleTargetDeviceName(
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( GetBrowser()->profile())));
GetBrowser()->profile()))));
#else #else
menu_model_.AddItemWithIcon( menu_model_.AddItemWithIcon(
IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET, IDC_CONTENT_LINK_SEND_TAB_TO_SELF_SINGLE_TARGET,
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_LINK_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, IDS_LINK_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( send_tab_to_self::GetSingleTargetDeviceName(
GetBrowser()->profile()))), GetBrowser()->profile())),
*send_tab_to_self::GetImageSkia()); *send_tab_to_self::GetImageSkia());
#endif #endif
send_tab_to_self::RecordSendTabToSelfClickResult( send_tab_to_self::RecordSendTabToSelfClickResult(
...@@ -1491,19 +1490,18 @@ void RenderViewContextMenu::AppendPageItems() { ...@@ -1491,19 +1490,18 @@ void RenderViewContextMenu::AppendPageItems() {
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
if (send_tab_to_self::GetValidDeviceCount(GetBrowser()->profile()) == 1) { if (send_tab_to_self::GetValidDeviceCount(GetBrowser()->profile()) == 1) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
menu_model_.AddItem( menu_model_.AddItem(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
IDC_SEND_TAB_TO_SELF_SINGLE_TARGET, l10n_util::GetStringFUTF16(
l10n_util::GetStringFUTF16( IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, send_tab_to_self::GetSingleTargetDeviceName(
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( GetBrowser()->profile())));
GetBrowser()->profile()))));
#else #else
menu_model_.AddItemWithIcon( menu_model_.AddItemWithIcon(
IDC_SEND_TAB_TO_SELF_SINGLE_TARGET, IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( send_tab_to_self::GetSingleTargetDeviceName(
GetBrowser()->profile()))), GetBrowser()->profile())),
*send_tab_to_self::GetImageSkia()); *send_tab_to_self::GetImageSkia());
#endif #endif
send_tab_to_self::RecordSendTabToSelfClickResult( send_tab_to_self::RecordSendTabToSelfClickResult(
......
...@@ -71,8 +71,6 @@ class RenderViewContextMenu : public RenderViewContextMenuBase { ...@@ -71,8 +71,6 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
bool is_checked); bool is_checked);
// Range of command IDs to use for the items in the send tab to self submenu. // Range of command IDs to use for the items in the send tab to self submenu.
static const int kMinSendTabToSelfSubMenuCommandId =
send_tab_to_self::SendTabToSelfSubMenuModel::kMinCommandId;
static const int kMaxSendTabToSelfSubMenuCommandId = static const int kMaxSendTabToSelfSubMenuCommandId =
send_tab_to_self::SendTabToSelfSubMenuModel::kMaxCommandId; send_tab_to_self::SendTabToSelfSubMenuModel::kMaxCommandId;
......
...@@ -64,8 +64,8 @@ void CreateNewEntry(content::WebContents* tab, ...@@ -64,8 +64,8 @@ void CreateNewEntry(content::WebContents* tab,
void ShareToSingleTarget(content::WebContents* tab, const GURL& link_url) { void ShareToSingleTarget(content::WebContents* tab, const GURL& link_url) {
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
DCHECK(GetValidDeviceCount(profile) == 1); DCHECK_EQ(GetValidDeviceCount(profile), 1u);
std::vector<TargetDeviceInfo> devices = const std::vector<TargetDeviceInfo>& devices =
SendTabToSelfSyncServiceFactory::GetForProfile(profile) SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetSendTabToSelfModel() ->GetSendTabToSelfModel()
->GetTargetDeviceInfoSortedList(); ->GetTargetDeviceInfoSortedList();
...@@ -94,24 +94,25 @@ void RecordSendTabToSelfDeviceCount(const std::string& entry_point, ...@@ -94,24 +94,25 @@ void RecordSendTabToSelfDeviceCount(const std::string& entry_point,
device_count); device_count);
} }
int GetValidDeviceCount(Profile* profile) { size_t GetValidDeviceCount(Profile* profile) {
SendTabToSelfSyncService* service = SendTabToSelfSyncService* service =
SendTabToSelfSyncServiceFactory::GetForProfile(profile); SendTabToSelfSyncServiceFactory::GetForProfile(profile);
DCHECK(service); DCHECK(service);
SendTabToSelfModel* model = service->GetSendTabToSelfModel(); SendTabToSelfModel* model = service->GetSendTabToSelfModel();
DCHECK(model); DCHECK(model);
std::vector<TargetDeviceInfo> devices = const std::vector<TargetDeviceInfo>& devices =
model->GetTargetDeviceInfoSortedList(); model->GetTargetDeviceInfoSortedList();
return devices.size(); return devices.size();
} }
std::string GetSingleTargetDeviceName(Profile* profile) { base::string16 GetSingleTargetDeviceName(Profile* profile) {
DCHECK(GetValidDeviceCount(profile) == 1); DCHECK_EQ(GetValidDeviceCount(profile), 1u);
return SendTabToSelfSyncServiceFactory::GetForProfile(profile) return base::UTF8ToUTF16(
->GetSendTabToSelfModel() SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetTargetDeviceInfoSortedList() ->GetSendTabToSelfModel()
.begin() ->GetTargetDeviceInfoSortedList()
->device_name; .begin()
->device_name);
} }
} // namespace send_tab_to_self } // namespace send_tab_to_self
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define CHROME_BROWSER_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_DESKTOP_UTIL_H_ #define CHROME_BROWSER_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_DESKTOP_UTIL_H_
#include <string> #include <string>
#include "base/strings/string16.h"
#include "url/gurl.h" #include "url/gurl.h"
class GURL; class GURL;
...@@ -63,11 +65,11 @@ void RecordSendTabToSelfDeviceCount(const std::string& entry_point, ...@@ -63,11 +65,11 @@ void RecordSendTabToSelfDeviceCount(const std::string& entry_point,
const int& device_count); const int& device_count);
// Gets the count of valid device number. // Gets the count of valid device number.
int GetValidDeviceCount(Profile* profile); size_t GetValidDeviceCount(Profile* profile);
// Gets the name of the single valid device. Will be called when // Gets the name of the single valid device. Will be called when
// GetValidDeviceCount() == 1. // GetValidDeviceCount() == 1.
std::string GetSingleTargetDeviceName(Profile* profile); base::string16 GetSingleTargetDeviceName(Profile* profile);
} // namespace send_tab_to_self } // namespace send_tab_to_self
......
...@@ -62,8 +62,8 @@ base::string16 SendTabToSelfBubbleController::GetWindowTitle() const { ...@@ -62,8 +62,8 @@ base::string16 SendTabToSelfBubbleController::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_CONTEXT_MENU_SEND_TAB_TO_SELF); return l10n_util::GetStringUTF16(IDS_CONTEXT_MENU_SEND_TAB_TO_SELF);
} }
std::vector<TargetDeviceInfo> SendTabToSelfBubbleController::GetValidDevices() const std::vector<TargetDeviceInfo>&
const { SendTabToSelfBubbleController::GetValidDevices() const {
return valid_devices_; return valid_devices_;
} }
...@@ -91,7 +91,7 @@ SendTabToSelfBubbleController::SendTabToSelfBubbleController() = default; ...@@ -91,7 +91,7 @@ SendTabToSelfBubbleController::SendTabToSelfBubbleController() = default;
SendTabToSelfBubbleController::SendTabToSelfBubbleController( SendTabToSelfBubbleController::SendTabToSelfBubbleController(
content::WebContents* web_contents) content::WebContents* web_contents)
: web_contents_(web_contents) { : web_contents_(web_contents) {
this->FetchDeviceInfo(); FetchDeviceInfo();
} }
void SendTabToSelfBubbleController::FetchDeviceInfo() { void SendTabToSelfBubbleController::FetchDeviceInfo() {
......
...@@ -40,7 +40,7 @@ class SendTabToSelfBubbleController ...@@ -40,7 +40,7 @@ class SendTabToSelfBubbleController
// Returns the title of send tab to self bubble. // Returns the title of send tab to self bubble.
base::string16 GetWindowTitle() const; base::string16 GetWindowTitle() const;
// Returns the valid devices info map. // Returns the valid devices info map.
std::vector<TargetDeviceInfo> GetValidDevices() const; const std::vector<TargetDeviceInfo>& GetValidDevices() const;
// Returns current profile. // Returns current profile.
Profile* GetProfile() const; Profile* GetProfile() const;
......
...@@ -11,6 +11,8 @@ namespace send_tab_to_self { ...@@ -11,6 +11,8 @@ namespace send_tab_to_self {
// This object is responsible for its own lifetime. // This object is responsible for its own lifetime.
class SendTabToSelfBubbleView { class SendTabToSelfBubbleView {
public: public:
virtual ~SendTabToSelfBubbleView() = default;
// Called to close the bubble and prevent future callbacks into the // Called to close the bubble and prevent future callbacks into the
// controller. // controller.
virtual void Hide() = 0; virtual void Hide() = 0;
......
...@@ -41,7 +41,7 @@ static_assert( ...@@ -41,7 +41,7 @@ static_assert(
// Returns true if the command id identifies a non-link contextual menu item. // Returns true if the command id identifies a non-link contextual menu item.
bool IsShareTabCommandId(int command_id) { bool IsShareTabCommandId(int command_id) {
return (command_id >= kShareTabCommandId && command_id < kShareLinkCommandId); return command_id >= kShareTabCommandId && command_id < kShareLinkCommandId;
} }
// Returns true if the command id identifies a link contextual menu item. // Returns true if the command id identifies a link contextual menu item.
...@@ -53,7 +53,8 @@ bool IsShareLinkCommandId(int command_id) { ...@@ -53,7 +53,8 @@ bool IsShareLinkCommandId(int command_id) {
int CommandIdToVectorIndex(int command_id) { int CommandIdToVectorIndex(int command_id) {
if (IsShareTabCommandId(command_id)) { if (IsShareTabCommandId(command_id)) {
return command_id - kShareTabCommandId; return command_id - kShareTabCommandId;
} else if (IsShareLinkCommandId(command_id)) { }
if (IsShareLinkCommandId(command_id)) {
return command_id - kShareLinkCommandId; return command_id - kShareLinkCommandId;
} }
return -1; return -1;
...@@ -85,6 +86,11 @@ struct SendTabToSelfSubMenuModel::ValidDeviceItem { ...@@ -85,6 +86,11 @@ struct SendTabToSelfSubMenuModel::ValidDeviceItem {
std::string cache_guid; std::string cache_guid;
}; };
SendTabToSelfSubMenuModel::SendTabToSelfSubMenuModel(
content::WebContents* tab,
SendTabToSelfMenuType menu_type)
: SendTabToSelfSubMenuModel(tab, menu_type, GURL()) {}
SendTabToSelfSubMenuModel::SendTabToSelfSubMenuModel( SendTabToSelfSubMenuModel::SendTabToSelfSubMenuModel(
content::WebContents* tab, content::WebContents* tab,
SendTabToSelfMenuType menu_type, SendTabToSelfMenuType menu_type,
...@@ -155,14 +161,8 @@ void SendTabToSelfSubMenuModel::BuildDeviceItem(const std::string& device_name, ...@@ -155,14 +161,8 @@ void SendTabToSelfSubMenuModel::BuildDeviceItem(const std::string& device_name,
const std::string& cache_guid, const std::string& cache_guid,
int index) { int index) {
ValidDeviceItem item(device_name, cache_guid); ValidDeviceItem item(device_name, cache_guid);
int command_id; int command_id =
if (menu_type_ == kLink) { (menu_type_ == kTab) ? kShareTabCommandId : kShareLinkCommandId + index;
// Generates command ids for sharing a link.
command_id = index + kShareLinkCommandId;
} else {
// Generates command ids for sharing a tab.
command_id = index + kShareTabCommandId;
}
InsertItemAt(index, command_id, base::UTF8ToUTF16(device_name)); InsertItemAt(index, command_id, base::UTF8ToUTF16(device_name));
valid_device_items_.push_back(item); valid_device_items_.push_back(item);
} }
......
...@@ -32,9 +32,11 @@ class SendTabToSelfSubMenuModel : public ui::SimpleMenuModel, ...@@ -32,9 +32,11 @@ class SendTabToSelfSubMenuModel : public ui::SimpleMenuModel,
struct ValidDeviceItem; struct ValidDeviceItem;
SendTabToSelfSubMenuModel(content::WebContents* tab,
SendTabToSelfMenuType menu_type);
SendTabToSelfSubMenuModel(content::WebContents* tab, SendTabToSelfSubMenuModel(content::WebContents* tab,
SendTabToSelfMenuType menu_type, SendTabToSelfMenuType menu_type,
const GURL& link_url = GURL()); const GURL& link_url);
~SendTabToSelfSubMenuModel() override; ~SendTabToSelfSubMenuModel() override;
// Overridden from ui::SimpleMenuModel::Delegate: // Overridden from ui::SimpleMenuModel::Delegate:
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_desktop_util.h" #include "chrome/browser/send_tab_to_self/send_tab_to_self_desktop_util.h"
...@@ -94,16 +93,15 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { ...@@ -94,16 +93,15 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) {
AddItem(TabStripModel::CommandSendTabToSelfSingleTarget, AddItem(TabStripModel::CommandSendTabToSelfSingleTarget,
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( send_tab_to_self::GetSingleTargetDeviceName(
tab_strip->profile())))); tab_strip->profile())));
#else #else
AddItemWithIcon( AddItemWithIcon(TabStripModel::CommandSendTabToSelfSingleTarget,
TabStripModel::CommandSendTabToSelfSingleTarget, l10n_util::GetStringFUTF16(
l10n_util::GetStringFUTF16( IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, (send_tab_to_self::GetSingleTargetDeviceName(
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( tab_strip->profile()))),
tab_strip->profile()))), *send_tab_to_self::GetImageSkia());
*send_tab_to_self::GetImageSkia());
#endif #endif
send_tab_to_self::RecordSendTabToSelfClickResult( send_tab_to_self::RecordSendTabToSelfClickResult(
send_tab_to_self::kTabMenu, send_tab_to_self::kTabMenu,
......
...@@ -1041,10 +1041,7 @@ inline bool LocationBarView::UpdateSendTabToSelfIcon() { ...@@ -1041,10 +1041,7 @@ inline bool LocationBarView::UpdateSendTabToSelfIcon() {
PageActionIconView* icon = PageActionIconView* icon =
this->omnibox_page_action_icon_container_view()->GetPageActionIconView( this->omnibox_page_action_icon_container_view()->GetPageActionIconView(
PageActionIconType::kSendTabToSelf); PageActionIconType::kSendTabToSelf);
if (icon) { return icon && icon->Update();
return icon->Update();
}
return false;
} }
void LocationBarView::SaveStateToContents(WebContents* contents) { void LocationBarView::SaveStateToContents(WebContents* contents) {
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.h" #include "chrome/browser/command_updater.h"
...@@ -1773,8 +1772,8 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { ...@@ -1773,8 +1772,8 @@ void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {
index, IDC_SEND_TAB_TO_SELF_SINGLE_TARGET, index, IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET, IDS_CONTEXT_MENU_SEND_TAB_TO_SELF_SINGLE_TARGET,
base::UTF8ToUTF16(send_tab_to_self::GetSingleTargetDeviceName( send_tab_to_self::GetSingleTargetDeviceName(
location_bar_view_->profile())))); location_bar_view_->profile())));
send_tab_to_self::RecordSendTabToSelfClickResult( send_tab_to_self::RecordSendTabToSelfClickResult(
send_tab_to_self::kOmniboxMenu, send_tab_to_self::kOmniboxMenu,
SendTabToSelfClickResult::kShowDeviceList); SendTabToSelfClickResult::kShowDeviceList);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <string> #include <string>
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
......
...@@ -24,8 +24,8 @@ class SendTabToSelfBubbleDeviceButton : public HoverButton { ...@@ -24,8 +24,8 @@ class SendTabToSelfBubbleDeviceButton : public HoverButton {
int button_tag); int button_tag);
~SendTabToSelfBubbleDeviceButton() override; ~SendTabToSelfBubbleDeviceButton() override;
const std::string device_name() const { return device_name_; } const std::string& device_name() const { return device_name_; }
const std::string device_guid() const { return device_guid_; } const std::string& device_guid() const { return device_guid_; }
sync_pb::SyncEnums::DeviceType device_type() const { return device_type_; } sync_pb::SyncEnums::DeviceType device_type() const { return device_type_; }
private: private:
......
...@@ -25,6 +25,17 @@ ...@@ -25,6 +25,17 @@
namespace send_tab_to_self { namespace send_tab_to_self {
namespace {
// The valid device button height.
constexpr int kDeviceButtonHeight = 56;
// Maximum number of buttons that are shown without scroll. If the device
// number is larger than kMaximumButtons, the bubble content will be
// scrollable.
constexpr int kMaximumButtons = 5;
} // namespace
SendTabToSelfBubbleViewImpl::SendTabToSelfBubbleViewImpl( SendTabToSelfBubbleViewImpl::SendTabToSelfBubbleViewImpl(
views::View* anchor_view, views::View* anchor_view,
const gfx::Point& anchor_point, const gfx::Point& anchor_point,
...@@ -71,10 +82,7 @@ bool SendTabToSelfBubbleViewImpl::Close() { ...@@ -71,10 +82,7 @@ bool SendTabToSelfBubbleViewImpl::Close() {
void SendTabToSelfBubbleViewImpl::ButtonPressed(views::Button* sender, void SendTabToSelfBubbleViewImpl::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
base::PostTaskWithTraits( DevicePressed(sender->tag());
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&SendTabToSelfBubbleViewImpl::DevicePressed,
weak_factory_.GetWeakPtr(), sender->tag()));
} }
gfx::Size SendTabToSelfBubbleViewImpl::CalculatePreferredSize() const { gfx::Size SendTabToSelfBubbleViewImpl::CalculatePreferredSize() const {
...@@ -129,7 +137,7 @@ void SendTabToSelfBubbleViewImpl::CreateScrollView() { ...@@ -129,7 +137,7 @@ void SendTabToSelfBubbleViewImpl::CreateScrollView() {
} }
void SendTabToSelfBubbleViewImpl::PopulateScrollView( void SendTabToSelfBubbleViewImpl::PopulateScrollView(
const std::vector<TargetDeviceInfo> devices) { const std::vector<TargetDeviceInfo>& devices) {
device_buttons_.clear(); device_buttons_.clear();
auto device_list_view = std::make_unique<views::View>(); auto device_list_view = std::make_unique<views::View>();
device_list_view->SetLayoutManager(std::make_unique<views::BoxLayout>( device_list_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
...@@ -152,8 +160,7 @@ void SendTabToSelfBubbleViewImpl::DevicePressed(size_t index) { ...@@ -152,8 +160,7 @@ void SendTabToSelfBubbleViewImpl::DevicePressed(size_t index) {
if (!controller_) { if (!controller_) {
return; return;
} }
SendTabToSelfBubbleDeviceButton* device_button = SendTabToSelfBubbleDeviceButton* device_button = device_buttons_[index].get();
device_buttons_.at(index).get();
controller_->OnDeviceSelected(device_button->device_name(), controller_->OnDeviceSelected(device_button->device_name(),
device_button->device_guid()); device_button->device_guid());
Hide(); Hide();
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef CHROME_BROWSER_UI_VIEWS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BUBBLE_VIEW_IMPL_H_ #ifndef CHROME_BROWSER_UI_VIEWS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BUBBLE_VIEW_IMPL_H_
#define CHROME_BROWSER_UI_VIEWS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BUBBLE_VIEW_IMPL_H_ #define CHROME_BROWSER_UI_VIEWS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_BUBBLE_VIEW_IMPL_H_
#include <map>
#include <memory> #include <memory>
#include <string>
#include <vector> #include <vector>
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -21,7 +23,7 @@ class Canvas; ...@@ -21,7 +23,7 @@ class Canvas;
namespace content { namespace content {
class WebContents; class WebContents;
} } // namespace content
namespace send_tab_to_self { namespace send_tab_to_self {
...@@ -35,13 +37,6 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView, ...@@ -35,13 +37,6 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView,
public views::ButtonListener, public views::ButtonListener,
public LocationBarBubbleDelegateView { public LocationBarBubbleDelegateView {
public: public:
// The valid device button height.
static constexpr int kDeviceButtonHeight = 56;
// Maximum number of buttons that are shown without scroll. If the device
// number is larger than kMaximumButtons, the bubble content will be
// scrollable.
static constexpr int kMaximumButtons = 5;
// Bubble will be anchored to |anchor_view|. // Bubble will be anchored to |anchor_view|.
SendTabToSelfBubbleViewImpl(views::View* anchor_view, SendTabToSelfBubbleViewImpl(views::View* anchor_view,
const gfx::Point& anchor_point, const gfx::Point& anchor_point,
...@@ -88,7 +83,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView, ...@@ -88,7 +83,7 @@ class SendTabToSelfBubbleViewImpl : public SendTabToSelfBubbleView,
void CreateScrollView(); void CreateScrollView();
// Populates the scroll view containing valid devices. // Populates the scroll view containing valid devices.
void PopulateScrollView(const std::vector<TargetDeviceInfo> devices); void PopulateScrollView(const std::vector<TargetDeviceInfo>& devices);
// Handles the action when a target device has been pressed. // Handles the action when a target device has been pressed.
void DevicePressed(size_t index); void DevicePressed(size_t index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment