Demojofy arc's default scale factor retrieval.
Mojo was used for mustash, but no longer necessary. This fixes the issue when docked mode. Arc should now always use the internal display to compute density. Bug: 1195586 Test: covered by unit test. manually tested on device. Change-Id: I5ac21c2a05ceccc8238ce291cc7a2f10e8eacc38 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2982259 Reviewed-by: Yusuke Sato <yusukes@chromium.org> Reviewed-by: Jun Mukai <mukai@chromium.org> Commit-Queue: Mitsuru Oshima <oshima@chromium.org> Cr-Commit-Position: refs/heads/master@{#896108}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
2bb682e85e
commit
5eeae9e1a8
ash/public/cpp
BUILD.gndefault_scale_factor_retriever.ccdefault_scale_factor_retriever.hdefault_scale_factor_retriever_unittest.cc
chrome/browser
ash
chromeos
components
@ -108,8 +108,6 @@ component("cpp") {
|
||||
"clipboard_history_controller.h",
|
||||
"clipboard_image_model_factory.cc",
|
||||
"clipboard_image_model_factory.h",
|
||||
"default_scale_factor_retriever.cc",
|
||||
"default_scale_factor_retriever.h",
|
||||
"desk_template.cc",
|
||||
"desk_template.h",
|
||||
"desks_helper.cc",
|
||||
@ -382,7 +380,6 @@ source_set("unit_tests") {
|
||||
"ambient/ambient_metrics_unittest.cc",
|
||||
"android_intent_helper_unittest.cc",
|
||||
"app_list/app_list_config_provider_unittest.cc",
|
||||
"default_scale_factor_retriever_unittest.cc",
|
||||
"file_icon_util_unittest.cc",
|
||||
"holding_space/holding_space_image_unittest.cc",
|
||||
"holding_space/holding_space_item_unittest.cc",
|
||||
|
@ -1,75 +0,0 @@
|
||||
// Copyright 2018 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 "ash/public/cpp/default_scale_factor_retriever.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "ui/display/display.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
DefaultScaleFactorRetriever::DefaultScaleFactorRetriever() {}
|
||||
|
||||
void DefaultScaleFactorRetriever::Start(
|
||||
mojo::PendingRemote<mojom::CrosDisplayConfigController>
|
||||
cros_display_config) {
|
||||
cros_display_config_.Bind(std::move(cros_display_config));
|
||||
auto callback = base::BindOnce(
|
||||
&DefaultScaleFactorRetriever::OnDefaultScaleFactorRetrieved,
|
||||
weak_ptr_factory_.GetWeakPtr());
|
||||
cros_display_config_->GetDisplayUnitInfoList(
|
||||
/*single_unified=*/false,
|
||||
base::BindOnce(
|
||||
[](GetDefaultScaleFactorCallback callback,
|
||||
std::vector<mojom::DisplayUnitInfoPtr> info_list) {
|
||||
// TODO(oshima): This does not return correct value in docked
|
||||
// mode.
|
||||
for (const mojom::DisplayUnitInfoPtr& info : info_list) {
|
||||
if (info->is_internal) {
|
||||
DCHECK(info->available_display_modes.size());
|
||||
std::move(callback).Run(
|
||||
info->available_display_modes[0]->device_scale_factor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::move(callback).Run(1.0f);
|
||||
},
|
||||
std::move(callback)));
|
||||
}
|
||||
|
||||
DefaultScaleFactorRetriever::~DefaultScaleFactorRetriever() = default;
|
||||
|
||||
void DefaultScaleFactorRetriever::GetDefaultScaleFactor(
|
||||
GetDefaultScaleFactorCallback callback) {
|
||||
if (display::Display::HasForceDeviceScaleFactor()) {
|
||||
return std::move(callback).Run(
|
||||
display::Display::GetForcedDeviceScaleFactor());
|
||||
}
|
||||
if (default_scale_factor_ > 0) {
|
||||
std::move(callback).Run(default_scale_factor_);
|
||||
return;
|
||||
}
|
||||
callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void DefaultScaleFactorRetriever::CancelCallback() {
|
||||
callback_.Reset();
|
||||
}
|
||||
|
||||
void DefaultScaleFactorRetriever::SetDefaultScaleFactorForTest(
|
||||
float scale_factor) {
|
||||
default_scale_factor_ = scale_factor;
|
||||
}
|
||||
|
||||
void DefaultScaleFactorRetriever::OnDefaultScaleFactorRetrieved(
|
||||
float scale_factor) {
|
||||
DCHECK_GT(scale_factor, 0.f);
|
||||
default_scale_factor_ = scale_factor;
|
||||
if (!callback_.is_null())
|
||||
std::move(callback_).Run(scale_factor);
|
||||
}
|
||||
|
||||
} // namespace ash
|
@ -1,59 +0,0 @@
|
||||
// Copyright 2018 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 ASH_PUBLIC_CPP_DEFAULT_SCALE_FACTOR_RETRIEVER_H_
|
||||
#define ASH_PUBLIC_CPP_DEFAULT_SCALE_FACTOR_RETRIEVER_H_
|
||||
|
||||
#include "ash/public/cpp/ash_public_export.h"
|
||||
#include "ash/public/mojom/cros_display_config.mojom.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
// A utility class to retrieve default scale factor from ash shell
|
||||
// asynchronously. It consists of two steps to minimize the
|
||||
// latency.
|
||||
// 1) Start querying by passing a CrosDisplayController.
|
||||
// 2) Pass callback which will be called when the default
|
||||
// scale factor is obtained.
|
||||
class ASH_PUBLIC_EXPORT DefaultScaleFactorRetriever {
|
||||
public:
|
||||
using GetDefaultScaleFactorCallback = base::OnceCallback<void(float)>;
|
||||
|
||||
DefaultScaleFactorRetriever();
|
||||
~DefaultScaleFactorRetriever();
|
||||
|
||||
// Start the query process.
|
||||
void Start(mojo::PendingRemote<mojom::CrosDisplayConfigController>
|
||||
cros_display_config);
|
||||
|
||||
// Get the default scale factor. The scale factor will be passed
|
||||
// as an argument to the |callback|. The callback may be call synchronously
|
||||
// if the scale factor is already available, or may be called
|
||||
// asynchronously if the query is still in progress.
|
||||
// This will automatically cancel the pending callback if any.
|
||||
void GetDefaultScaleFactor(GetDefaultScaleFactorCallback callback);
|
||||
|
||||
// Cancels pending callback if any.
|
||||
void CancelCallback();
|
||||
|
||||
void SetDefaultScaleFactorForTest(float scale_factor);
|
||||
|
||||
private:
|
||||
void OnDefaultScaleFactorRetrieved(float scale_factor);
|
||||
|
||||
float default_scale_factor_ = -1.f;
|
||||
mojo::Remote<mojom::CrosDisplayConfigController> cros_display_config_;
|
||||
GetDefaultScaleFactorCallback callback_;
|
||||
|
||||
// WeakPtrFactory to use callbacks.
|
||||
base::WeakPtrFactory<DefaultScaleFactorRetriever> weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_PUBLIC_CPP_DEFAULT_SCALE_FACTOR_RETRIEVER_H_
|
@ -1,146 +0,0 @@
|
||||
// Copyright 2018 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 "ash/public/cpp/default_scale_factor_retriever.h"
|
||||
|
||||
#include "ash/public/mojom/cros_display_config.mojom.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "mojo/public/cpp/bindings/receiver.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/display/display.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
namespace {
|
||||
|
||||
class TestCrosDisplayConfig : public ash::mojom::CrosDisplayConfigController {
|
||||
public:
|
||||
static constexpr int64_t kFakeDisplayId = 1;
|
||||
|
||||
TestCrosDisplayConfig() = default;
|
||||
|
||||
mojo::PendingRemote<ash::mojom::CrosDisplayConfigController>
|
||||
CreateRemoteAndBind() {
|
||||
return receiver_.BindNewPipeAndPassRemote();
|
||||
}
|
||||
|
||||
// ash::mojom::CrosDisplayConfigController:
|
||||
void AddObserver(
|
||||
mojo::PendingAssociatedRemote<ash::mojom::CrosDisplayConfigObserver>
|
||||
observer) override {}
|
||||
void GetDisplayLayoutInfo(GetDisplayLayoutInfoCallback callback) override {}
|
||||
void SetDisplayLayoutInfo(ash::mojom::DisplayLayoutInfoPtr info,
|
||||
SetDisplayLayoutInfoCallback callback) override {}
|
||||
void GetDisplayUnitInfoList(
|
||||
bool single_unified,
|
||||
GetDisplayUnitInfoListCallback callback) override {
|
||||
std::vector<ash::mojom::DisplayUnitInfoPtr> info_list;
|
||||
auto info = ash::mojom::DisplayUnitInfo::New();
|
||||
info->id = kFakeDisplayId;
|
||||
info->is_internal = true;
|
||||
auto mode = ash::mojom::DisplayMode::New();
|
||||
mode->device_scale_factor = 2.f;
|
||||
info->available_display_modes.emplace_back(std::move(mode));
|
||||
info_list.push_back(std::move(info));
|
||||
std::move(callback).Run(std::move(info_list));
|
||||
}
|
||||
void SetDisplayProperties(const std::string& id,
|
||||
ash::mojom::DisplayConfigPropertiesPtr properties,
|
||||
ash::mojom::DisplayConfigSource source,
|
||||
SetDisplayPropertiesCallback callback) override {}
|
||||
void SetUnifiedDesktopEnabled(bool enabled) override {}
|
||||
void OverscanCalibration(const std::string& display_id,
|
||||
ash::mojom::DisplayConfigOperation op,
|
||||
const absl::optional<gfx::Insets>& delta,
|
||||
OverscanCalibrationCallback callback) override {}
|
||||
void TouchCalibration(const std::string& display_id,
|
||||
ash::mojom::DisplayConfigOperation op,
|
||||
ash::mojom::TouchCalibrationPtr calibration,
|
||||
TouchCalibrationCallback callback) override {}
|
||||
void HighlightDisplay(int64_t id) override {}
|
||||
void DragDisplayDelta(int64_t id, int32_t delta_x, int32_t delta_y) override {
|
||||
}
|
||||
|
||||
private:
|
||||
mojo::Receiver<ash::mojom::CrosDisplayConfigController> receiver_{this};
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TestCrosDisplayConfig);
|
||||
};
|
||||
|
||||
class DefaultScaleFactorRetrieverTest : public testing::Test {
|
||||
public:
|
||||
DefaultScaleFactorRetrieverTest() = default;
|
||||
~DefaultScaleFactorRetrieverTest() override = default;
|
||||
|
||||
private:
|
||||
base::test::SingleThreadTaskEnvironment task_environment_;
|
||||
DISALLOW_COPY_AND_ASSIGN(DefaultScaleFactorRetrieverTest);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(DefaultScaleFactorRetrieverTest, Basic) {
|
||||
display::Display::SetInternalDisplayId(TestCrosDisplayConfig::kFakeDisplayId);
|
||||
auto display_config = std::make_unique<TestCrosDisplayConfig>();
|
||||
auto retriever = std::make_unique<DefaultScaleFactorRetriever>();
|
||||
|
||||
auto callback = [](float* result, float default_scale_factor) {
|
||||
result[0] = default_scale_factor;
|
||||
};
|
||||
float result1[1] = {0};
|
||||
retriever->Start(display_config->CreateRemoteAndBind());
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result1));
|
||||
float result2[1] = {0};
|
||||
// This will cancel the 1st callback.
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result2));
|
||||
|
||||
EXPECT_EQ(0.f, result1[0]);
|
||||
EXPECT_EQ(0.f, result2[0]);
|
||||
base::RunLoop().RunUntilIdle();
|
||||
EXPECT_EQ(0.f, result1[0]);
|
||||
EXPECT_EQ(2.f, result2[0]);
|
||||
|
||||
float result3[1] = {0};
|
||||
// This time, it should use the cached value.
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result3));
|
||||
EXPECT_EQ(2.f, result3[0]);
|
||||
|
||||
// For test.
|
||||
retriever->SetDefaultScaleFactorForTest(3.0f);
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result3));
|
||||
EXPECT_EQ(3.f, result3[0]);
|
||||
|
||||
display::Display::SetInternalDisplayId(display::kInvalidDisplayId);
|
||||
}
|
||||
|
||||
TEST_F(DefaultScaleFactorRetrieverTest, Cancel) {
|
||||
display::Display::SetInternalDisplayId(TestCrosDisplayConfig::kFakeDisplayId);
|
||||
auto display_config = std::make_unique<TestCrosDisplayConfig>();
|
||||
auto retriever = std::make_unique<DefaultScaleFactorRetriever>();
|
||||
|
||||
auto callback = [](float* result, float default_scale_factor) {
|
||||
result[0] = default_scale_factor;
|
||||
};
|
||||
float result[1] = {0};
|
||||
retriever->Start(display_config->CreateRemoteAndBind());
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result));
|
||||
retriever->CancelCallback();
|
||||
EXPECT_EQ(0.f, result[0]);
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(0.f, result[0]);
|
||||
|
||||
float result2[1] = {0};
|
||||
// This time, it should use the cached value.
|
||||
retriever->GetDefaultScaleFactor(base::BindOnce(callback, result2));
|
||||
|
||||
EXPECT_EQ(2.f, result2[0]);
|
||||
display::Display::SetInternalDisplayId(display::kInvalidDisplayId);
|
||||
}
|
||||
|
||||
} // namespace ash
|
@ -7,7 +7,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "ash/public/cpp/default_scale_factor_retriever.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/check_op.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -102,14 +101,13 @@ ArcServiceLauncher* g_arc_service_launcher = nullptr;
|
||||
|
||||
std::unique_ptr<ArcSessionManager> CreateArcSessionManager(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel,
|
||||
chromeos::SchedulerConfigurationManagerBase*
|
||||
scheduler_configuration_manager) {
|
||||
auto delegate = std::make_unique<AdbSideloadingAvailabilityDelegateImpl>();
|
||||
auto runner = std::make_unique<ArcSessionRunner>(base::BindRepeating(
|
||||
ArcSession::Create, arc_bridge_service, retriever, channel,
|
||||
scheduler_configuration_manager, delegate.get()));
|
||||
auto runner = std::make_unique<ArcSessionRunner>(
|
||||
base::BindRepeating(ArcSession::Create, arc_bridge_service, channel,
|
||||
scheduler_configuration_manager, delegate.get()));
|
||||
return std::make_unique<ArcSessionManager>(std::move(runner),
|
||||
std::move(delegate));
|
||||
}
|
||||
@ -122,7 +120,6 @@ ArcServiceLauncher::ArcServiceLauncher(
|
||||
: arc_service_manager_(std::make_unique<ArcServiceManager>()),
|
||||
arc_session_manager_(
|
||||
CreateArcSessionManager(arc_service_manager_->arc_bridge_service(),
|
||||
&default_scale_factor_retriever_,
|
||||
chrome::GetChannel(),
|
||||
scheduler_configuration_manager)),
|
||||
scheduler_configuration_manager_(scheduler_configuration_manager) {
|
||||
@ -145,10 +142,7 @@ ArcServiceLauncher* ArcServiceLauncher::Get() {
|
||||
return g_arc_service_launcher;
|
||||
}
|
||||
|
||||
void ArcServiceLauncher::Initialize(
|
||||
mojo::PendingRemote<ash::mojom::CrosDisplayConfigController>
|
||||
display_config) {
|
||||
default_scale_factor_retriever_.Start(std::move(display_config));
|
||||
void ArcServiceLauncher::Initialize() {
|
||||
arc_session_manager_->ExpandPropertyFilesAndReadSalt();
|
||||
}
|
||||
|
||||
@ -287,8 +281,7 @@ void ArcServiceLauncher::ResetForTesting() {
|
||||
// may be referred from existing KeyedService, so destoying it would cause
|
||||
// unexpected behavior, specifically on test teardown.
|
||||
arc_session_manager_ = CreateArcSessionManager(
|
||||
arc_service_manager_->arc_bridge_service(),
|
||||
&default_scale_factor_retriever_, chrome::GetChannel(),
|
||||
arc_service_manager_->arc_bridge_service(), chrome::GetChannel(),
|
||||
scheduler_configuration_manager_);
|
||||
}
|
||||
|
||||
|
@ -7,16 +7,12 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ash/public/cpp/default_scale_factor_retriever.h"
|
||||
#include "ash/public/mojom/cros_display_config.mojom.h"
|
||||
#include "base/macros.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
|
||||
class Profile;
|
||||
|
||||
namespace ash {
|
||||
class DefaultScaleFactorRetriever;
|
||||
}
|
||||
|
||||
namespace chromeos {
|
||||
class SchedulerConfigurationManagerBase;
|
||||
@ -41,8 +37,7 @@ class ArcServiceLauncher {
|
||||
static ArcServiceLauncher* Get();
|
||||
|
||||
// Must be called early in startup.
|
||||
void Initialize(mojo::PendingRemote<ash::mojom::CrosDisplayConfigController>
|
||||
display_config);
|
||||
void Initialize();
|
||||
|
||||
// Called just before most of BrowserContextKeyedService instance creation.
|
||||
// Set the given |profile| to ArcSessionManager, if the profile is allowed
|
||||
@ -63,7 +58,6 @@ class ArcServiceLauncher {
|
||||
void ResetForTesting();
|
||||
|
||||
private:
|
||||
ash::DefaultScaleFactorRetriever default_scale_factor_retriever_;
|
||||
std::unique_ptr<ArcServiceManager> arc_service_manager_;
|
||||
std::unique_ptr<ArcSessionManager> arc_session_manager_;
|
||||
std::unique_ptr<ArcPlayStoreEnabledPreferenceHandler>
|
||||
|
@ -67,6 +67,7 @@
|
||||
#include "components/arc/session/arc_session.h"
|
||||
#include "components/arc/session/arc_session_runner.h"
|
||||
#include "components/arc/session/arc_supervision_transition.h"
|
||||
#include "components/exo/wm_helper_chromeos.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/services/app_service/public/cpp/intent_util.h"
|
||||
#include "components/session_manager/core/session_manager.h"
|
||||
@ -1643,6 +1644,8 @@ void ArcSessionManager::MaybeStartTimer() {
|
||||
|
||||
void ArcSessionManager::StartMiniArc() {
|
||||
pre_start_time_ = base::TimeTicks::Now();
|
||||
arc_session_runner_->set_default_device_scale_factor(
|
||||
exo::GetDefaultDeviceScaleFactor());
|
||||
arc_session_runner_->RequestStartMiniInstance();
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,10 @@ class ArcSessionManager : public ArcSessionRunner::Observer,
|
||||
// via SetProfile().
|
||||
void Initialize();
|
||||
|
||||
// Set the device scale factor used to start the arc. This must be called
|
||||
// before staring mini-ARC.
|
||||
void SetDefaultDeviceScaleFactor(float default_device_scale_factor);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
// Sets the |profile|, and sets up Profile related fields in this instance.
|
||||
|
@ -836,12 +836,7 @@ void ChromeBrowserMainPartsChromeos::PreProfileInit() {
|
||||
// ash::Shell.
|
||||
ChromeBrowserMainPartsLinux::PreProfileInit();
|
||||
|
||||
// ash::Shell must be initialized before we can ask Ash to bind a
|
||||
// CrosDisplayConfigController.
|
||||
mojo::PendingRemote<ash::mojom::CrosDisplayConfigController> display_config;
|
||||
ash::BindCrosDisplayConfigController(
|
||||
display_config.InitWithNewPipeAndPassReceiver());
|
||||
arc_service_launcher_->Initialize(std::move(display_config));
|
||||
arc_service_launcher_->Initialize();
|
||||
|
||||
// Needs to be initialized after ash::Shell.
|
||||
chrome_keyboard_controller_client_->Init(ash::KeyboardController::Get());
|
||||
|
@ -22,13 +22,12 @@ void ArcSession::RemoveObserver(Observer* observer) {
|
||||
// static
|
||||
std::unique_ptr<ArcSession> ArcSession::Create(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel,
|
||||
chromeos::SchedulerConfigurationManagerBase*
|
||||
scheduler_configuration_manager,
|
||||
AdbSideloadingAvailabilityDelegate* adb_sideloading_availability_delegate) {
|
||||
return std::make_unique<ArcSessionImpl>(
|
||||
ArcSessionImpl::CreateDelegate(arc_bridge_service, retriever, channel),
|
||||
ArcSessionImpl::CreateDelegate(arc_bridge_service, channel),
|
||||
scheduler_configuration_manager, adb_sideloading_availability_delegate);
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include "components/arc/session/arc_stop_reason.h"
|
||||
#include "components/arc/session/arc_upgrade_params.h"
|
||||
|
||||
namespace ash {
|
||||
class DefaultScaleFactorRetriever;
|
||||
}
|
||||
|
||||
namespace chromeos {
|
||||
class SchedulerConfigurationManagerBase;
|
||||
}
|
||||
@ -62,7 +58,6 @@ class ArcSession {
|
||||
// Creates a default instance of ArcSession.
|
||||
static std::unique_ptr<ArcSession> Create(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel,
|
||||
chromeos::SchedulerConfigurationManagerBase*
|
||||
scheduler_configuration_manager,
|
||||
@ -109,6 +104,8 @@ class ArcSession {
|
||||
base::OnceCallback<void(bool success, const std::string& failure_reason)>;
|
||||
virtual void TrimVmMemory(TrimVmMemoryCallback callback) = 0;
|
||||
|
||||
virtual void SetDefaultDeviceScaleFactor(float scale_factor) = 0;
|
||||
|
||||
void AddObserver(Observer* observer);
|
||||
void RemoveObserver(Observer* observer);
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_switches.h"
|
||||
#include "ash/public/cpp/default_scale_factor_retriever.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/compiler_specific.h"
|
||||
@ -166,7 +165,6 @@ void ApplyDisableDownloadProvider(StartParams* params) {
|
||||
class ArcSessionDelegateImpl : public ArcSessionImpl::Delegate {
|
||||
public:
|
||||
ArcSessionDelegateImpl(ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel);
|
||||
~ArcSessionDelegateImpl() override = default;
|
||||
|
||||
@ -175,7 +173,6 @@ class ArcSessionDelegateImpl : public ArcSessionImpl::Delegate {
|
||||
|
||||
base::ScopedFD ConnectMojo(base::ScopedFD socket_fd,
|
||||
ConnectMojoCallback callback) override;
|
||||
void GetLcdDensity(GetLcdDensityCallback callback) override;
|
||||
void GetFreeDiskSpace(GetFreeDiskSpaceCallback callback) override;
|
||||
version_info::Channel GetChannel() override;
|
||||
std::unique_ptr<ArcClientAdapter> CreateClient() override;
|
||||
@ -200,9 +197,6 @@ class ArcSessionDelegateImpl : public ArcSessionImpl::Delegate {
|
||||
// Owned by ArcServiceManager.
|
||||
ArcBridgeService* const arc_bridge_service_;
|
||||
|
||||
// Owned by ArcServiceLauncher.
|
||||
ash::DefaultScaleFactorRetriever* const default_scale_factor_retriever_;
|
||||
|
||||
const version_info::Channel channel_;
|
||||
|
||||
// WeakPtrFactory to use callbacks.
|
||||
@ -213,10 +207,8 @@ class ArcSessionDelegateImpl : public ArcSessionImpl::Delegate {
|
||||
|
||||
ArcSessionDelegateImpl::ArcSessionDelegateImpl(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel)
|
||||
: arc_bridge_service_(arc_bridge_service),
|
||||
default_scale_factor_retriever_(retriever),
|
||||
channel_(channel) {}
|
||||
|
||||
void ArcSessionDelegateImpl::CreateSocket(CreateSocketCallback callback) {
|
||||
@ -250,15 +242,6 @@ base::ScopedFD ArcSessionDelegateImpl::ConnectMojo(
|
||||
return return_fd;
|
||||
}
|
||||
|
||||
void ArcSessionDelegateImpl::GetLcdDensity(GetLcdDensityCallback callback) {
|
||||
default_scale_factor_retriever_->GetDefaultScaleFactor(base::BindOnce(
|
||||
[](GetLcdDensityCallback callback, float default_scale_factor) {
|
||||
std::move(callback).Run(
|
||||
GetLcdDensityForDeviceScaleFactor(default_scale_factor));
|
||||
},
|
||||
std::move(callback)));
|
||||
}
|
||||
|
||||
void ArcSessionDelegateImpl::GetFreeDiskSpace(
|
||||
GetFreeDiskSpaceCallback callback) {
|
||||
base::ThreadPool::PostTaskAndReplyWithResult(
|
||||
@ -414,10 +397,8 @@ void ArcSessionDelegateImpl::OnMojoConnected(
|
||||
// static
|
||||
std::unique_ptr<ArcSessionImpl::Delegate> ArcSessionImpl::CreateDelegate(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel) {
|
||||
return std::make_unique<ArcSessionDelegateImpl>(arc_bridge_service, retriever,
|
||||
channel);
|
||||
return std::make_unique<ArcSessionDelegateImpl>(arc_bridge_service, channel);
|
||||
}
|
||||
|
||||
ArcSessionImpl::ArcSessionImpl(
|
||||
@ -448,19 +429,6 @@ void ArcSessionImpl::StartMiniInstance() {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
DCHECK_EQ(state_, State::NOT_STARTED);
|
||||
|
||||
state_ = State::WAITING_FOR_LCD_DENSITY;
|
||||
|
||||
VLOG(2) << "Querying the lcd density to start ARC mini instance";
|
||||
|
||||
delegate_->GetLcdDensity(base::BindOnce(&ArcSessionImpl::OnLcdDensity,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void ArcSessionImpl::OnLcdDensity(int32_t lcd_density) {
|
||||
DCHECK_GT(lcd_density, 0);
|
||||
DCHECK(state_ == State::WAITING_FOR_LCD_DENSITY);
|
||||
|
||||
lcd_density_ = lcd_density;
|
||||
const auto& last_reply = scheduler_configuration_manager_->GetLastReply();
|
||||
if (last_reply) {
|
||||
state_ = State::STARTING_MINI_INSTANCE;
|
||||
@ -555,7 +523,6 @@ void ArcSessionImpl::RequestUpgrade(UpgradeParams params) {
|
||||
case State::NOT_STARTED:
|
||||
NOTREACHED();
|
||||
break;
|
||||
case State::WAITING_FOR_LCD_DENSITY:
|
||||
case State::WAITING_FOR_NUM_CORES:
|
||||
case State::STARTING_MINI_INSTANCE:
|
||||
// OnMiniInstanceStarted() will restart a full instance.
|
||||
@ -750,7 +717,6 @@ void ArcSessionImpl::Stop() {
|
||||
scheduler_configuration_manager_->RemoveObserver(this);
|
||||
FALLTHROUGH;
|
||||
case State::NOT_STARTED:
|
||||
case State::WAITING_FOR_LCD_DENSITY:
|
||||
// If |Stop()| is called while waiting for LCD density or CPU cores
|
||||
// information, it can directly move to stopped state.
|
||||
VLOG(1) << "ARC session is not started. state: " << state_;
|
||||
@ -790,8 +756,7 @@ void ArcSessionImpl::Stop() {
|
||||
|
||||
void ArcSessionImpl::StopArcInstance(bool on_shutdown, bool should_backup_log) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
DCHECK(state_ == State::WAITING_FOR_LCD_DENSITY ||
|
||||
state_ == State::WAITING_FOR_NUM_CORES ||
|
||||
DCHECK(state_ == State::WAITING_FOR_NUM_CORES ||
|
||||
state_ == State::STARTING_MINI_INSTANCE ||
|
||||
state_ == State::RUNNING_MINI_INSTANCE ||
|
||||
state_ == State::STARTING_FULL_INSTANCE ||
|
||||
@ -902,6 +867,11 @@ void ArcSessionImpl::TrimVmMemory(TrimVmMemoryCallback callback) {
|
||||
client_->TrimVmMemory(std::move(callback));
|
||||
}
|
||||
|
||||
void ArcSessionImpl::SetDefaultDeviceScaleFactor(float scale_factor) {
|
||||
lcd_density_ = GetLcdDensityForDeviceScaleFactor(scale_factor);
|
||||
DCHECK_GT(lcd_density_, 0);
|
||||
}
|
||||
|
||||
void ArcSessionImpl::OnConfigurationSet(bool success,
|
||||
size_t num_cores_disabled) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
@ -924,7 +894,6 @@ std::ostream& operator<<(std::ostream& os, ArcSessionImpl::State state) {
|
||||
|
||||
switch (state) {
|
||||
MAP_STATE(NOT_STARTED);
|
||||
MAP_STATE(WAITING_FOR_LCD_DENSITY);
|
||||
MAP_STATE(WAITING_FOR_NUM_CORES);
|
||||
MAP_STATE(STARTING_MINI_INSTANCE);
|
||||
MAP_STATE(RUNNING_MINI_INSTANCE);
|
||||
|
@ -20,10 +20,6 @@
|
||||
#include "components/arc/session/arc_session.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace ash {
|
||||
class DefaultScaleFactorRetriever;
|
||||
}
|
||||
|
||||
namespace base {
|
||||
struct SystemMemoryInfoKB;
|
||||
}
|
||||
@ -49,8 +45,6 @@ class ArcSessionImpl
|
||||
//
|
||||
// NOT_STARTED
|
||||
// -> StartMiniInstance() ->
|
||||
// WAITING_FOR_LCD_DENSITY
|
||||
// -> OnLcdDensity ->
|
||||
// WAITING_FOR_NUM_CORES
|
||||
// -> OnConfigurationSet ->
|
||||
// STARTING_MINI_INSTANCE
|
||||
@ -67,12 +61,6 @@ class ArcSessionImpl
|
||||
// state, the state change to STARTING_FULL_INSTANCE is suspended until
|
||||
// the state becomes RUNNING_MINI_INSTANCE.
|
||||
//
|
||||
// Upon |StartMiniInstance()| call, it queries LCD Density through
|
||||
// Delegate::GetLcdDenstity, and moves to WAITING_FOR_LCD_DENSITY state. The
|
||||
// query may be made synchronlsly or asynchronosly depending on the
|
||||
// availability of the density information. It then asks SessionManager to
|
||||
// start mini container and moves to STARTING_MINI_INSTANCE state.
|
||||
//
|
||||
// At any state, Stop() can be called. It may not immediately stop the
|
||||
// instance, but will eventually stop it. The actual stop will be notified
|
||||
// via ArcSession::Observer::OnSessionStopped().
|
||||
@ -117,9 +105,6 @@ class ArcSessionImpl
|
||||
// ARC is not yet started.
|
||||
NOT_STARTED,
|
||||
|
||||
// It's waiting for LCD density to be available.
|
||||
WAITING_FOR_LCD_DENSITY,
|
||||
|
||||
// It's waiting for CPU cores information to be available.
|
||||
WAITING_FOR_NUM_CORES,
|
||||
|
||||
@ -162,14 +147,6 @@ class ArcSessionImpl
|
||||
virtual base::ScopedFD ConnectMojo(base::ScopedFD socket_fd,
|
||||
ConnectMojoCallback callback) = 0;
|
||||
|
||||
using GetLcdDensityCallback = base::OnceCallback<void(int32_t)>;
|
||||
|
||||
// Gets the lcd density via callback. The callback may be invoked
|
||||
// immediately if it's already available, or called asynchronously later if
|
||||
// it's not yet available. Calling this method while there is a pending
|
||||
// callback will cancel the pending callback.
|
||||
virtual void GetLcdDensity(GetLcdDensityCallback callback) = 0;
|
||||
|
||||
// Gets the available disk space under /home. The result is in bytes.
|
||||
using GetFreeDiskSpaceCallback = base::OnceCallback<void(int64_t)>;
|
||||
virtual void GetFreeDiskSpace(GetFreeDiskSpaceCallback callback) = 0;
|
||||
@ -194,7 +171,6 @@ class ArcSessionImpl
|
||||
// Returns default delegate implementation used for the production.
|
||||
static std::unique_ptr<Delegate> CreateDelegate(
|
||||
ArcBridgeService* arc_bridge_service,
|
||||
ash::DefaultScaleFactorRetriever* retriever,
|
||||
version_info::Channel channel);
|
||||
|
||||
State GetStateForTesting() { return state_; }
|
||||
@ -214,6 +190,7 @@ class ArcSessionImpl
|
||||
void SetDemoModeDelegate(
|
||||
ArcClientAdapter::DemoModeDelegate* delegate) override;
|
||||
void TrimVmMemory(TrimVmMemoryCallback callback) override;
|
||||
void SetDefaultDeviceScaleFactor(float scale_factor) override;
|
||||
|
||||
// chromeos::SchedulerConfigurationManagerBase::Observer overrides:
|
||||
void OnConfigurationSet(bool success, size_t num_cores_disabled) override;
|
||||
@ -261,9 +238,6 @@ class ArcSessionImpl
|
||||
// deleting |this| because the function calls observers' OnSessionStopped().
|
||||
void OnStopped(ArcStopReason reason);
|
||||
|
||||
// LCD density for the device is available.
|
||||
void OnLcdDensity(int32_t lcd_density);
|
||||
|
||||
// Called when |state_| moves to STARTING_MINI_INSTANCE.
|
||||
void DoStartMiniInstance(size_t num_cores_disabled);
|
||||
|
||||
|
@ -126,8 +126,7 @@ class FakeArcClientAdapter : public ArcClientAdapter {
|
||||
|
||||
class FakeDelegate : public ArcSessionImpl::Delegate {
|
||||
public:
|
||||
explicit FakeDelegate(int32_t lcd_density = 160)
|
||||
: lcd_density_(lcd_density) {}
|
||||
FakeDelegate() = default;
|
||||
|
||||
// Emulates to fail Mojo connection establishing. |callback| passed to
|
||||
// ConnectMojo will be called with nullptr.
|
||||
@ -168,13 +167,6 @@ class FakeDelegate : public ArcSessionImpl::Delegate {
|
||||
return base::ScopedFD(open("/dev/null", O_RDONLY | O_CLOEXEC));
|
||||
}
|
||||
|
||||
void GetLcdDensity(GetLcdDensityCallback callback) override {
|
||||
if (lcd_density_ > 0)
|
||||
std::move(callback).Run(lcd_density_);
|
||||
else
|
||||
lcd_density_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void GetFreeDiskSpace(GetFreeDiskSpaceCallback callback) override {
|
||||
std::move(callback).Run(free_disk_space_);
|
||||
}
|
||||
@ -187,12 +179,6 @@ class FakeDelegate : public ArcSessionImpl::Delegate {
|
||||
return std::make_unique<FakeArcClientAdapter>();
|
||||
}
|
||||
|
||||
void SetLcdDensity(int32_t lcd_density) {
|
||||
lcd_density_ = lcd_density;
|
||||
ASSERT_TRUE(!lcd_density_callback_.is_null());
|
||||
std::move(lcd_density_callback_).Run(lcd_density_);
|
||||
}
|
||||
|
||||
void SetFreeDiskSpace(int64_t space) { free_disk_space_ = space; }
|
||||
|
||||
private:
|
||||
@ -204,12 +190,10 @@ class FakeDelegate : public ArcSessionImpl::Delegate {
|
||||
success_ ? std::make_unique<FakeArcBridgeHost>() : nullptr));
|
||||
}
|
||||
|
||||
int32_t lcd_density_ = 0;
|
||||
bool success_ = true;
|
||||
bool suspend_ = false;
|
||||
int64_t free_disk_space_ = kMinimumFreeDiskSpaceBytes * 2;
|
||||
ConnectMojoCallback pending_callback_;
|
||||
GetLcdDensityCallback lcd_density_callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FakeDelegate);
|
||||
};
|
||||
@ -314,9 +298,9 @@ class ArcSessionImplTest : public testing::Test {
|
||||
|
||||
std::unique_ptr<ArcSessionImpl, ArcSessionDeleter> CreateArcSession(
|
||||
std::unique_ptr<ArcSessionImpl::Delegate> delegate = nullptr,
|
||||
int32_t lcd_density = 160) {
|
||||
auto arc_session =
|
||||
CreateArcSessionInternal(std::move(delegate), lcd_density);
|
||||
float default_device_scale_factor = 1.0f) {
|
||||
auto arc_session = CreateArcSessionInternal(std::move(delegate),
|
||||
default_device_scale_factor);
|
||||
fake_schedule_configuration_manager_.SetLastReply(0);
|
||||
return arc_session;
|
||||
}
|
||||
@ -324,8 +308,9 @@ class ArcSessionImplTest : public testing::Test {
|
||||
std::unique_ptr<ArcSessionImpl, ArcSessionDeleter>
|
||||
CreateArcSessionWithoutCpuInfo(
|
||||
std::unique_ptr<ArcSessionImpl::Delegate> delegate = nullptr,
|
||||
int32_t lcd_density = 160) {
|
||||
return CreateArcSessionInternal(std::move(delegate), lcd_density);
|
||||
float default_device_scale_factor = 1.0f) {
|
||||
return CreateArcSessionInternal(std::move(delegate),
|
||||
default_device_scale_factor);
|
||||
}
|
||||
|
||||
void SetupMiniContainer(ArcSessionImpl* arc_session,
|
||||
@ -351,13 +336,15 @@ class ArcSessionImplTest : public testing::Test {
|
||||
private:
|
||||
std::unique_ptr<ArcSessionImpl, ArcSessionDeleter> CreateArcSessionInternal(
|
||||
std::unique_ptr<ArcSessionImpl::Delegate> delegate,
|
||||
int32_t lcd_density) {
|
||||
float default_device_scale_factor) {
|
||||
if (!delegate)
|
||||
delegate = std::make_unique<FakeDelegate>(lcd_density);
|
||||
return std::unique_ptr<ArcSessionImpl, ArcSessionDeleter>(
|
||||
new ArcSessionImpl(std::move(delegate),
|
||||
&fake_schedule_configuration_manager_,
|
||||
adb_sideloading_availability_delegate_.get()));
|
||||
delegate = std::make_unique<FakeDelegate>();
|
||||
auto arc_session =
|
||||
std::unique_ptr<ArcSessionImpl, ArcSessionDeleter>(new ArcSessionImpl(
|
||||
std::move(delegate), &fake_schedule_configuration_manager_,
|
||||
adb_sideloading_availability_delegate_.get()));
|
||||
arc_session->SetDefaultDeviceScaleFactor(default_device_scale_factor);
|
||||
return arc_session;
|
||||
}
|
||||
|
||||
base::test::TaskEnvironment task_environment_;
|
||||
@ -819,7 +806,7 @@ TEST_F(ArcSessionImplTest, SupervisionTransitionShouldGraduate) {
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StartArcMiniContainerWithDensity) {
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(nullptr, 240);
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(nullptr, 2.f);
|
||||
arc_session->StartMiniInstance();
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_NUM_CORES,
|
||||
arc_session->GetStateForTesting());
|
||||
@ -831,86 +818,10 @@ TEST_F(ArcSessionImplTest, StartArcMiniContainerWithDensity) {
|
||||
EXPECT_EQ(240, GetClient(arc_session.get())->last_start_params().lcd_density);
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StartArcMiniContainerWithDensityAsync) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto* delegate_ptr = delegate.get();
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_LCD_DENSITY,
|
||||
arc_session->GetStateForTesting());
|
||||
delegate_ptr->SetLcdDensity(240);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_NUM_CORES,
|
||||
arc_session->GetStateForTesting());
|
||||
fake_schedule_configuration_manager_.SetLastReply(2);
|
||||
EXPECT_EQ(ArcSessionImpl::State::STARTING_MINI_INSTANCE,
|
||||
arc_session->GetStateForTesting());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(240, GetClient(arc_session.get())->last_start_params().lcd_density);
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StartArcMiniContainerWithDensityAsyncReversedOrder) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto* delegate_ptr = delegate.get();
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
// This time, set the CPU cores information first.
|
||||
fake_schedule_configuration_manager_.SetLastReply(2);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_LCD_DENSITY,
|
||||
arc_session->GetStateForTesting());
|
||||
delegate_ptr->SetLcdDensity(240);
|
||||
EXPECT_EQ(ArcSessionImpl::State::STARTING_MINI_INSTANCE,
|
||||
arc_session->GetStateForTesting());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(240, GetClient(arc_session.get())->last_start_params().lcd_density);
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StartArcMiniContainerWithDensityAsyncCpuInfoEarly) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto* delegate_ptr = delegate.get();
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
// Set the CPU cores information even before StartMiniInstance() request.
|
||||
fake_schedule_configuration_manager_.SetLastReply(2);
|
||||
arc_session->StartMiniInstance();
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_LCD_DENSITY,
|
||||
arc_session->GetStateForTesting());
|
||||
delegate_ptr->SetLcdDensity(240);
|
||||
EXPECT_EQ(ArcSessionImpl::State::STARTING_MINI_INSTANCE,
|
||||
arc_session->GetStateForTesting());
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
EXPECT_EQ(240, GetClient(arc_session.get())->last_start_params().lcd_density);
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StopWhileWaitingForLcdDensity) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
fake_schedule_configuration_manager_.SetLastReply(2);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_LCD_DENSITY,
|
||||
arc_session->GetStateForTesting());
|
||||
arc_session->Stop();
|
||||
EXPECT_EQ(ArcSessionImpl::State::STOPPED, arc_session->GetStateForTesting());
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, ShutdownWhileWaitingForLcdDensity) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
fake_schedule_configuration_manager_.SetLastReply(2);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_LCD_DENSITY,
|
||||
arc_session->GetStateForTesting());
|
||||
arc_session->OnShutdown();
|
||||
EXPECT_EQ(ArcSessionImpl::State::STOPPED, arc_session->GetStateForTesting());
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, StopWhileWaitingForNumCores) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto* delegate_ptr = delegate.get();
|
||||
auto delegate = std::make_unique<FakeDelegate>();
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
delegate_ptr->SetLcdDensity(240);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_NUM_CORES,
|
||||
arc_session->GetStateForTesting());
|
||||
arc_session->Stop();
|
||||
@ -918,11 +829,9 @@ TEST_F(ArcSessionImplTest, StopWhileWaitingForNumCores) {
|
||||
}
|
||||
|
||||
TEST_F(ArcSessionImplTest, ShutdownWhileWaitingForNumCores) {
|
||||
auto delegate = std::make_unique<FakeDelegate>(0);
|
||||
auto* delegate_ptr = delegate.get();
|
||||
auto delegate = std::make_unique<FakeDelegate>();
|
||||
auto arc_session = CreateArcSessionWithoutCpuInfo(std::move(delegate));
|
||||
arc_session->StartMiniInstance();
|
||||
delegate_ptr->SetLcdDensity(240);
|
||||
EXPECT_EQ(ArcSessionImpl::State::WAITING_FOR_NUM_CORES,
|
||||
arc_session->GetStateForTesting());
|
||||
arc_session->OnShutdown();
|
||||
|
@ -285,6 +285,7 @@ void ArcSessionRunner::StartArcSession() {
|
||||
!serial_number_.empty()) {
|
||||
arc_session_->SetUserInfo(cryptohome_id_, user_id_hash_, serial_number_);
|
||||
}
|
||||
arc_session_->SetDefaultDeviceScaleFactor(default_device_scale_factor_);
|
||||
arc_session_->SetDemoModeDelegate(demo_mode_delegate_.get());
|
||||
arc_session_->AddObserver(this);
|
||||
arc_session_->StartMiniInstance();
|
||||
|
@ -116,6 +116,10 @@ class ArcSessionRunner : public ArcSession::Observer {
|
||||
base::OnceCallback<void(bool success, const std::string& failure_reason)>;
|
||||
void TrimVmMemory(TrimVmMemoryCallback callback);
|
||||
|
||||
void set_default_device_scale_factor(float scale_factor) {
|
||||
default_device_scale_factor_ = scale_factor;
|
||||
}
|
||||
|
||||
// Returns the current ArcSession instance for testing purpose.
|
||||
ArcSession* GetArcSessionForTesting() { return arc_session_.get(); }
|
||||
|
||||
@ -173,6 +177,8 @@ class ArcSessionRunner : public ArcSession::Observer {
|
||||
|
||||
bool resumed_ = false;
|
||||
|
||||
float default_device_scale_factor_ = 1.0f;
|
||||
|
||||
// DemoModeDelegate to be used by ArcSession.
|
||||
std::unique_ptr<ArcClientAdapter::DemoModeDelegate> demo_mode_delegate_;
|
||||
|
||||
|
@ -52,6 +52,8 @@ void FakeArcSession::TrimVmMemory(TrimVmMemoryCallback callback) {
|
||||
std::move(callback).Run(true, std::string());
|
||||
}
|
||||
|
||||
void FakeArcSession::SetDefaultDeviceScaleFactor(float scale_factor) {}
|
||||
|
||||
void FakeArcSession::StopWithReason(ArcStopReason reason) {
|
||||
bool was_mojo_connected = running_;
|
||||
running_ = false;
|
||||
|
@ -36,6 +36,7 @@ class FakeArcSession : public ArcSession {
|
||||
void SetDemoModeDelegate(
|
||||
ArcClientAdapter::DemoModeDelegate* delegate) override;
|
||||
void TrimVmMemory(TrimVmMemoryCallback callback) override;
|
||||
void SetDefaultDeviceScaleFactor(float scale_factor) override;
|
||||
|
||||
// To emulate unexpected stop, such as crash.
|
||||
void StopWithReason(ArcStopReason reason);
|
||||
|
@ -242,24 +242,13 @@ bool WMHelperChromeOS::InTabletMode() const {
|
||||
}
|
||||
|
||||
double WMHelperChromeOS::GetDefaultDeviceScaleFactor() const {
|
||||
if (!display::Display::HasInternalDisplay())
|
||||
return 1.0;
|
||||
|
||||
if (display::Display::HasForceDeviceScaleFactor())
|
||||
return display::Display::GetForcedDeviceScaleFactor();
|
||||
|
||||
display::DisplayManager* display_manager =
|
||||
ash::Shell::Get()->display_manager();
|
||||
const display::ManagedDisplayInfo& display_info =
|
||||
display_manager->GetDisplayInfo(display::Display::InternalDisplayId());
|
||||
DCHECK(display_info.display_modes().size());
|
||||
return display_info.display_modes()[0].device_scale_factor();
|
||||
return exo::GetDefaultDeviceScaleFactor();
|
||||
}
|
||||
|
||||
double WMHelperChromeOS::GetDeviceScaleFactorForWindow(
|
||||
aura::Window* window) const {
|
||||
if (default_scale_cancellation_)
|
||||
return GetDefaultDeviceScaleFactor();
|
||||
return exo::GetDefaultDeviceScaleFactor();
|
||||
const display::Screen* screen = display::Screen::GetScreen();
|
||||
display::Display display = screen->GetDisplayNearestWindow(window);
|
||||
return display.device_scale_factor();
|
||||
@ -287,4 +276,19 @@ aura::client::CaptureClient* WMHelperChromeOS::GetCaptureClient() {
|
||||
return wm::CaptureController::Get();
|
||||
}
|
||||
|
||||
float GetDefaultDeviceScaleFactor() {
|
||||
if (!display::Display::HasInternalDisplay())
|
||||
return 1.0;
|
||||
|
||||
if (display::Display::HasForceDeviceScaleFactor())
|
||||
return display::Display::GetForcedDeviceScaleFactor();
|
||||
|
||||
display::DisplayManager* display_manager =
|
||||
ash::Shell::Get()->display_manager();
|
||||
const display::ManagedDisplayInfo& display_info =
|
||||
display_manager->GetDisplayInfo(display::Display::InternalDisplayId());
|
||||
DCHECK(display_info.display_modes().size());
|
||||
return display_info.display_modes()[0].device_scale_factor();
|
||||
}
|
||||
|
||||
} // namespace exo
|
||||
|
@ -130,6 +130,10 @@ class WMHelperChromeOS : public WMHelper, public VSyncTimingManager::Delegate {
|
||||
DISALLOW_COPY_AND_ASSIGN(WMHelperChromeOS);
|
||||
};
|
||||
|
||||
// Returnsn the default device scale factor used for
|
||||
// ClientControlledShellSurface (ARC).
|
||||
float GetDefaultDeviceScaleFactor();
|
||||
|
||||
} // namespace exo
|
||||
|
||||
#endif // COMPONENTS_EXO_WM_HELPER_CHROMEOS_H_
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "components/exo/wm_helper_chromeos.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/frame_throttler/frame_throttling_controller.h"
|
||||
#include "ash/shell.h"
|
||||
@ -19,6 +20,10 @@
|
||||
#include "ui/base/dragdrop/drop_target_event.h"
|
||||
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
|
||||
#include "ui/base/dragdrop/os_exchange_data.h"
|
||||
#include "ui/display/manager/display_manager.h"
|
||||
#include "ui/display/manager/managed_display_info.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/display/test/display_manager_test_api.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
|
||||
namespace exo {
|
||||
@ -123,4 +128,22 @@ TEST_F(WMHelperChromeOSTest, MultipleDragDropObservers) {
|
||||
wm_helper_chromeos->RemoveDragDropObserver(&observer_copy_drop);
|
||||
}
|
||||
|
||||
TEST_F(WMHelperChromeOSTest, DockedModeShouldUseInternalAsDefault) {
|
||||
UpdateDisplay("1920x1080*2, 600x400");
|
||||
display::test::DisplayManagerTestApi(display_manager())
|
||||
.SetFirstDisplayAsInternalDisplay();
|
||||
auto display_list = display::Screen::GetScreen()->GetAllDisplays();
|
||||
auto first_info = display_manager()->GetDisplayInfo(display_list[0].id());
|
||||
auto second_info = display_manager()->GetDisplayInfo(display_list[1].id());
|
||||
ASSERT_EQ(gfx::Size(1920, 1080), first_info.size_in_pixel());
|
||||
ASSERT_EQ(first_info.id(), display::Display::InternalDisplayId());
|
||||
|
||||
std::vector<display::ManagedDisplayInfo> display_info_list{second_info};
|
||||
display_manager()->OnNativeDisplaysChanged(display_info_list);
|
||||
ASSERT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().id(),
|
||||
second_info.id());
|
||||
|
||||
EXPECT_EQ(2.0f, GetDefaultDeviceScaleFactor());
|
||||
}
|
||||
|
||||
} // namespace exo
|
||||
|
Reference in New Issue
Block a user