Commit b8d8ec5d authored by Andre Le's avatar Andre Le Committed by Commit Bot

[CrOS PhoneHub] Request connection if needed when open bubble.

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: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823342}
parent f2814903
...@@ -149,6 +149,9 @@ void PhoneHubTray::ShowBubble(bool show_by_click) { ...@@ -149,6 +149,9 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
if (bubble_) if (bubble_)
return; return;
// Attempts a connection to the phone if needed.
ui_controller_->MaybeRequestConnection();
TrayBubbleView::InitParams init_params; TrayBubbleView::InitParams init_params;
init_params.delegate = this; init_params.delegate = this;
init_params.parent_window = GetBubbleWindowContainer(); init_params.parent_window = GetBubbleWindowContainer();
......
...@@ -349,17 +349,23 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) { ...@@ -349,17 +349,23 @@ TEST_F(PhoneHubTrayTest, ClickButtonsOnDisconnectedView) {
GetFeatureStatusProvider()->SetStatus( GetFeatureStatusProvider()->SetStatus(
chromeos::phonehub::FeatureStatus::kEnabledButDisconnected); 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(); ClickTrayButton();
EXPECT_TRUE(phone_hub_tray_->is_active()); 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_TRUE(content_view());
EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID()); EXPECT_EQ(PhoneHubViewID::kDisconnectedView, content_view()->GetID());
// Simulates a click on the "Refresh" button. // Simulates a click on the "Refresh" button.
EXPECT_EQ(0u, GetConnectionScheduler()->num_schedule_connection_now_calls());
ClickOnAndWait(disconnected_refresh_button()); ClickOnAndWait(disconnected_refresh_button());
// Clicking "Refresh" button should schedule a connection attempt. // 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 // Clicking "Learn More" button should open the corresponding help center
// article in a browser tab. // article in a browser tab.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/system/phonehub/phone_connected_view.h" #include "ash/system/phonehub/phone_connected_view.h"
#include "ash/system/phonehub/phone_hub_content_view.h" #include "ash/system/phonehub/phone_hub_content_view.h"
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/components/phonehub/connection_scheduler.h"
#include "chromeos/components/phonehub/phone_hub_manager.h" #include "chromeos/components/phonehub/phone_hub_manager.h"
using FeatureStatus = chromeos::phonehub::FeatureStatus; using FeatureStatus = chromeos::phonehub::FeatureStatus;
...@@ -76,6 +77,17 @@ std::unique_ptr<PhoneHubContentView> PhoneHubUiController::CreateContentView( ...@@ -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) { void PhoneHubUiController::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer); observer_list_.AddObserver(observer);
} }
......
...@@ -71,6 +71,10 @@ class ASH_EXPORT PhoneHubUiController ...@@ -71,6 +71,10 @@ class ASH_EXPORT PhoneHubUiController
std::unique_ptr<views::View> CreateStatusHeaderView( std::unique_ptr<views::View> CreateStatusHeaderView(
PhoneStatusView::Delegate* delegate); PhoneStatusView::Delegate* delegate);
// Request a connection to the phone if there is no current connection and
// PhoneHub is set up.
void MaybeRequestConnection();
// Observer functions. // Observer functions.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
......
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