Skip to content

Commit

Permalink
[CrOS PhoneHub] Request connection if needed when open bubble.
Browse files Browse the repository at this point in the history
If there is no current connection, request a new connection when the UI is opened.


Bug: 1106937,1126208
Fixed: 1141600

Change-Id: I20563f0c6d1ef3f191be38d3e4cfa20e6ab2bdd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2504069
Commit-Queue: Andre Le <leandre@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Tim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823342}
  • Loading branch information
Andre Le authored and Commit Bot committed Nov 2, 2020
1 parent f281490 commit b8d8ec5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ash/system/phonehub/phone_hub_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
if (bubble_)
return;

// Attempts a connection to the phone if needed.
ui_controller_->MaybeRequestConnection();

TrayBubbleView::InitParams init_params;
init_params.delegate = this;
init_params.parent_window = GetBubbleWindowContainer();
Expand Down
10 changes: 8 additions & 2 deletions ash/system/phonehub/phone_hub_tray_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,23 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) {
GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledButDisconnected);

EXPECT_EQ(0u, GetConnectionScheduler()->num_schedule_connection_now_calls());

// In error state, clicking the tray button should schedule a connection
// attempt.
ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active());
EXPECT_EQ(1u, GetConnectionScheduler()->num_schedule_connection_now_calls());

// Make sure the testing environment is in disconnected view.
EXPECT_TRUE(content_view());
EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());

// Simulates a click on the "Refresh" button.
EXPECT_EQ(0u, GetConnectionScheduler()->num_schedule_connection_now_calls());
ClickOnAndWait(disconnected_refresh_button());

// Clicking "Refresh" button should schedule a connection attempt.
EXPECT_EQ(1u, GetConnectionScheduler()->num_schedule_connection_now_calls());
EXPECT_EQ(2u, GetConnectionScheduler()->num_schedule_connection_now_calls());

// Clicking "Learn More" button should open the corresponding help center
// article in a browser tab.
Expand Down
12 changes: 12 additions & 0 deletions ash/system/phonehub/phone_hub_ui_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ash/system/phonehub/phone_connected_view.h"
#include "ash/system/phonehub/phone_hub_content_view.h"
#include "base/logging.h"
#include "chromeos/components/phonehub/connection_scheduler.h"
#include "chromeos/components/phonehub/phone_hub_manager.h"

using FeatureStatus = chromeos::phonehub::FeatureStatus;
Expand Down Expand Up @@ -76,6 +77,17 @@ std::unique_ptr<PhoneHubContentView> PhoneHubUiController::CreateContentView(
}
}

void PhoneHubUiController::MaybeRequestConnection() {
if (!phone_hub_manager_)
return;

auto feature_status =
phone_hub_manager_->GetFeatureStatusProvider()->GetStatus();

if (feature_status == FeatureStatus::kEnabledButDisconnected)
phone_hub_manager_->GetConnectionScheduler()->ScheduleConnectionNow();
}

void PhoneHubUiController::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
Expand Down
4 changes: 4 additions & 0 deletions ash/system/phonehub/phone_hub_ui_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class ASH_EXPORT PhoneHubUiController
std::unique_ptr<views::View> CreateStatusHeaderView(
PhoneStatusView::Delegate* delegate);

// Request a connection to the phone if there is no current connection and
// PhoneHub is set up.
void MaybeRequestConnection();

// Observer functions.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
Expand Down

0 comments on commit b8d8ec5

Please sign in to comment.