Skip to content

Commit

Permalink
Reland "Mash cleanup: migrate KioskNextShell{Client,Controller} off m…
Browse files Browse the repository at this point in the history
…ojo."

This relands commit b0d0f7b without the
stale include.

TBR=tsepez@chromium.org,sky@chromium.org

Bug: 958204
Change-Id: Ie214135089c50ee3f3c52931cebab6cbf8d84f09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1648657
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667008}
  • Loading branch information
Evan Stade authored and Commit Bot committed Jun 7, 2019
1 parent 4530d09 commit fe069b0
Show file tree
Hide file tree
Showing 47 changed files with 219 additions and 171 deletions.
4 changes: 2 additions & 2 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ component("ash") {
"keyboard/virtual_keyboard_controller.h",
"kiosk_next/kiosk_next_home_controller.cc",
"kiosk_next/kiosk_next_home_controller.h",
"kiosk_next/kiosk_next_shell_controller.cc",
"kiosk_next/kiosk_next_shell_controller.h",
"kiosk_next/kiosk_next_shell_controller_impl.cc",
"kiosk_next/kiosk_next_shell_controller_impl.h",
"kiosk_next/kiosk_next_shell_observer.h",
"laser/laser_pointer_controller.cc",
"laser/laser_pointer_controller.h",
Expand Down
2 changes: 1 addition & 1 deletion ash/accelerators/accelerator_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "ash/ime/ime_controller.h"
#include "ash/ime/ime_switch_type.h"
#include "ash/keyboard/ui/keyboard_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller_impl.h"
#include "ash/magnifier/docked_magnifier_controller_impl.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/media/media_controller_impl.h"
Expand Down
4 changes: 2 additions & 2 deletions ash/ash_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ash/assistant/assistant_controller.h"
#include "ash/detachable_base/detachable_base_handler.h"
#include "ash/display/display_prefs.h"
#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller_impl.h"
#include "ash/login/login_screen_controller.h"
#include "ash/magnifier/docked_magnifier_controller_impl.h"
#include "ash/shelf/shelf_controller.h"
Expand Down Expand Up @@ -37,7 +37,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
BluetoothPowerController::RegisterProfilePrefs(registry);
CapsLockNotificationController::RegisterProfilePrefs(registry, for_test);
DockedMagnifierControllerImpl::RegisterProfilePrefs(registry, for_test);
KioskNextShellController::RegisterProfilePrefs(registry, for_test);
KioskNextShellControllerImpl::RegisterProfilePrefs(registry, for_test);
LoginScreenController::RegisterProfilePrefs(registry, for_test);
LogoutButtonTray::RegisterProfilePrefs(registry);
MessageCenterController::RegisterProfilePrefs(registry);
Expand Down
3 changes: 2 additions & 1 deletion ash/display/screen_orientation_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,11 @@ class ScreenOrientationControllerKioskNextTest
set_start_session(false);
AshTestBase::SetUp();

client_ = BindMockKioskNextShellClient();
client_ = std::make_unique<MockKioskNextShellClient>();
}

void TearDown() override {
client_.reset();
home_screen_window_.reset();
AshTestBase::TearDown();
}
Expand Down
2 changes: 1 addition & 1 deletion ash/home_screen/home_screen_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "ash/home_screen/home_screen_controller.h"
#include "ash/home_screen/home_screen_delegate.h"
#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller_impl.h"
#include "ash/shell.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
Expand Down
4 changes: 2 additions & 2 deletions ash/kiosk_next/kiosk_next_home_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class KioskNextHomeControllerTest : public AshTestBase {
scoped_feature_list_.InitAndEnableFeature(features::kKioskNextShell);
set_start_session(false);
AshTestBase::SetUp();
client_ = BindMockKioskNextShellClient();
client_ = std::make_unique<MockKioskNextShellClient>();
LogInKioskNextUser(GetSessionControllerClient());
SetUpHomeWindow();
}

void TearDown() override {
home_screen_window_.reset();
AshTestBase::TearDown();
client_.reset();
AshTestBase::TearDown();
}

void SetUpHomeWindow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller_impl.h"

#include <memory>
#include <utility>
Expand Down Expand Up @@ -52,12 +52,12 @@ std::unique_ptr<ShelfModel> CreateKioskNextShelfModel() {

} // namespace

KioskNextShellController::KioskNextShellController() = default;
KioskNextShellControllerImpl::KioskNextShellControllerImpl() = default;

KioskNextShellController::~KioskNextShellController() = default;
KioskNextShellControllerImpl::~KioskNextShellControllerImpl() = default;

// static
void KioskNextShellController::RegisterProfilePrefs(
void KioskNextShellControllerImpl::RegisterProfilePrefs(
PrefRegistrySimple* registry,
bool for_test) {
if (for_test) {
Expand All @@ -67,43 +67,40 @@ void KioskNextShellController::RegisterProfilePrefs(
}
}

void KioskNextShellController::BindRequest(
mojom::KioskNextShellControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
void KioskNextShellControllerImpl::SetClientAndLaunchSession(
KioskNextShellClient* client) {
DCHECK_NE(!!client, !!client_);
client_ = client;
LaunchKioskNextShellIfEnabled();
}

bool KioskNextShellController::IsEnabled() {
bool KioskNextShellControllerImpl::IsEnabled() {
return kiosk_next_enabled_;
}

void KioskNextShellController::AddObserver(KioskNextShellObserver* observer) {
void KioskNextShellControllerImpl::AddObserver(
KioskNextShellObserver* observer) {
observer_list_.AddObserver(observer);
}

void KioskNextShellController::RemoveObserver(
void KioskNextShellControllerImpl::RemoveObserver(
KioskNextShellObserver* observer) {
observer_list_.RemoveObserver(observer);
}

void KioskNextShellController::SetClient(
mojom::KioskNextShellClientPtr client) {
kiosk_next_shell_client_ = std::move(client);
LaunchKioskNextShellIfEnabled();
}

void KioskNextShellController::OnActiveUserPrefServiceChanged(
void KioskNextShellControllerImpl::OnActiveUserPrefServiceChanged(
PrefService* pref_service) {
LaunchKioskNextShellIfEnabled();
}

void KioskNextShellController::LaunchKioskNextShellIfEnabled() {
void KioskNextShellControllerImpl::LaunchKioskNextShellIfEnabled() {
SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
PrefService* pref_service = session_controller->GetPrimaryUserPrefService();
if (!pref_service)
return;

if (!kiosk_next_shell_client_.is_bound())
if (!client_)
return;

bool prev_kiosk_next_enabled = kiosk_next_enabled_;
Expand All @@ -119,7 +116,7 @@ void KioskNextShellController::LaunchKioskNextShellIfEnabled() {
kiosk_next_home_controller_.get());
Shell::Get()->RemoveAppListController();

kiosk_next_shell_client_->LaunchKioskNextShell(
client_->LaunchKioskNextShell(
session_controller->GetPrimaryUserSession()->user_info.account_id);
UMA_HISTOGRAM_BOOLEAN("KioskNextShell.Launched", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_H_
#define ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_H_
#ifndef ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_IMPL_H_
#define ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_IMPL_H_

#include <memory>

#include "ash/ash_export.h"
#include "ash/kiosk_next/kiosk_next_shell_observer.h"
#include "ash/public/interfaces/kiosk_next_shell.mojom.h"
#include "ash/public/cpp/kiosk_next_shell.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "mojo/public/cpp/bindings/binding_set.h"

class PrefRegistrySimple;

Expand All @@ -22,21 +21,20 @@ namespace ash {
class KioskNextHomeController;
class ShelfModel;

// KioskNextShellController allows an ash consumer to manage a Kiosk Next
// KioskNextShellControllerImpl allows an ash consumer to manage a Kiosk Next
// session. During this session most system functions are disabled and we launch
// a specific app (Kiosk Next Home) that takes the whole screen.
class ASH_EXPORT KioskNextShellController
: public mojom::KioskNextShellController,
public SessionObserver {
class ASH_EXPORT KioskNextShellControllerImpl : public KioskNextShellController,
public SessionObserver {
public:
KioskNextShellController();
~KioskNextShellController() override;
KioskNextShellControllerImpl();
~KioskNextShellControllerImpl() override;

// Register prefs related to the Kiosk Next Shell.
static void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test);

// Binds the mojom::KioskNextShellController interface to this object.
void BindRequest(mojom::KioskNextShellControllerRequest request);
// KioskNextShellController:
void SetClientAndLaunchSession(KioskNextShellClient* client) override;

// Returns if the Kiosk Next Shell is enabled for the current user. If there's
// no signed-in user, this returns false.
Expand All @@ -45,9 +43,6 @@ class ASH_EXPORT KioskNextShellController
void AddObserver(KioskNextShellObserver* observer);
void RemoveObserver(KioskNextShellObserver* observer);

// mojom::KioskNextShellController:
void SetClient(mojom::KioskNextShellClientPtr client) override;

// SessionObserver:
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;

Expand All @@ -58,8 +53,8 @@ class ASH_EXPORT KioskNextShellController
// available.
void LaunchKioskNextShellIfEnabled();

mojom::KioskNextShellClientPtr kiosk_next_shell_client_;
mojo::BindingSet<mojom::KioskNextShellController> bindings_;
KioskNextShellClient* client_ = nullptr;

base::ObserverList<KioskNextShellObserver> observer_list_;
ScopedSessionObserver session_observer_{this};
bool kiosk_next_enabled_ = false;
Expand All @@ -68,13 +63,13 @@ class ASH_EXPORT KioskNextShellController
std::unique_ptr<KioskNextHomeController> kiosk_next_home_controller_;

// When KioskNextShell is enabled, only the home button and back button are
// made visible on the Shelf. KioskNextShellController therefore hosts its own
// ShelfModel to control the entries visible on the shelf.
// made visible on the Shelf. KioskNextShellControllerImpl therefore hosts its
// own ShelfModel to control the entries visible on the shelf.
std::unique_ptr<ShelfModel> shelf_model_;

DISALLOW_COPY_AND_ASSIGN(KioskNextShellController);
DISALLOW_COPY_AND_ASSIGN(KioskNextShellControllerImpl);
};

} // namespace ash

#endif // ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_H_
#endif // ASH_KIOSK_NEXT_KIOSK_NEXT_SHELL_CONTROLLER_IMPL_H_
8 changes: 4 additions & 4 deletions ash/kiosk_next/kiosk_next_shell_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller_impl.h"

#include <memory>

Expand All @@ -18,7 +18,7 @@
namespace ash {
namespace {

KioskNextShellController* GetKioskNextShellController() {
KioskNextShellControllerImpl* GetKioskNextShellController() {
return Shell::Get()->kiosk_next_shell_controller();
}

Expand All @@ -42,13 +42,13 @@ class KioskNextShellControllerTest : public AshTestBase {
void SetUp() override {
set_start_session(false);
AshTestBase::SetUp();
client_ = BindMockKioskNextShellClient();
client_ = std::make_unique<MockKioskNextShellClient>();
scoped_feature_list_.InitAndEnableFeature(features::kKioskNextShell);
}

void TearDown() override {
AshTestBase::TearDown();
client_.reset();
AshTestBase::TearDown();
}

protected:
Expand Down
21 changes: 4 additions & 17 deletions ash/kiosk_next/mock_kiosk_next_shell_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@

#include "ash/kiosk_next/mock_kiosk_next_shell_client.h"

#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/shell.h"

namespace ash {

MockKioskNextShellClient::MockKioskNextShellClient() = default;

MockKioskNextShellClient::~MockKioskNextShellClient() = default;

mojom::KioskNextShellClientPtr
MockKioskNextShellClient::CreateInterfacePtrAndBind() {
mojom::KioskNextShellClientPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
MockKioskNextShellClient::MockKioskNextShellClient() {
KioskNextShellController::Get()->SetClientAndLaunchSession(this);
}

std::unique_ptr<MockKioskNextShellClient> BindMockKioskNextShellClient() {
auto client = std::make_unique<MockKioskNextShellClient>();
Shell::Get()->kiosk_next_shell_controller()->SetClient(
client->CreateInterfacePtrAndBind());
return client;
MockKioskNextShellClient::~MockKioskNextShellClient() {
KioskNextShellController::Get()->SetClientAndLaunchSession(nullptr);
}

} // namespace ash
17 changes: 3 additions & 14 deletions ash/kiosk_next/mock_kiosk_next_shell_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,25 @@
#ifndef ASH_KIOSK_NEXT_MOCK_KIOSK_NEXT_SHELL_CLIENT_H_
#define ASH_KIOSK_NEXT_MOCK_KIOSK_NEXT_SHELL_CLIENT_H_

#include <memory>

#include "ash/public/interfaces/kiosk_next_shell.mojom.h"
#include "ash/public/cpp/kiosk_next_shell.h"
#include "base/macros.h"
#include "components/account_id/account_id.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace ash {

class MockKioskNextShellClient : public mojom::KioskNextShellClient {
class MockKioskNextShellClient : public KioskNextShellClient {
public:
MockKioskNextShellClient();
~MockKioskNextShellClient() override;

mojom::KioskNextShellClientPtr CreateInterfacePtrAndBind();

// mojom::KioskNextShellClient:
// KioskNextShellClient:
MOCK_METHOD1(LaunchKioskNextShell, void(const AccountId& account_id));

private:
mojo::Binding<mojom::KioskNextShellClient> binding_{this};

DISALLOW_COPY_AND_ASSIGN(MockKioskNextShellClient);
};

// Helper function to bind a KioskNextShellClient so that it receives mojo
// calls.
std::unique_ptr<MockKioskNextShellClient> BindMockKioskNextShellClient();

} // namespace ash

#endif // ASH_KIOSK_NEXT_MOCK_KIOSK_NEXT_SHELL_CLIENT_H_
11 changes: 0 additions & 11 deletions ash/mojo_interface_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ash/autotest/shelf_integration_test_api.h"
#include "ash/display/cros_display_config.h"
#include "ash/ime/ime_controller.h"
#include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/login/login_screen_controller.h"
#include "ash/media/media_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
Expand Down Expand Up @@ -97,11 +96,6 @@ void BindImeControllerRequestOnMainThread(mojom::ImeControllerRequest request) {
Shell::Get()->ime_controller()->BindRequest(std::move(request));
}

void BindKioskNextShellControllerRequestOnMainThread(
mojom::KioskNextShellControllerRequest request) {
Shell::Get()->kiosk_next_shell_controller()->BindRequest(std::move(request));
}

void BindNightLightControllerRequestOnMainThread(
mojom::NightLightControllerRequest request) {
Shell::Get()->night_light_controller()->BindRequest(std::move(request));
Expand Down Expand Up @@ -163,11 +157,6 @@ void RegisterInterfaces(
registry->AddInterface(
base::BindRepeating(&BindAshMessageCenterControllerRequestOnMainThread),
main_thread_task_runner);
if (base::FeatureList::IsEnabled(features::kKioskNextShell)) {
registry->AddInterface(
base::BindRepeating(&BindKioskNextShellControllerRequestOnMainThread),
main_thread_task_runner);
}
registry->AddInterface(
base::BindRepeating(&BindImeControllerRequestOnMainThread),
main_thread_task_runner);
Expand Down
Loading

0 comments on commit fe069b0

Please sign in to comment.