Commit 6ed996f7 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Replace note_taking_controller.mojom by C++

TBR=tsepez@chromium.org

Bug: 958211
Test: trybot
Change-Id: Ie39f93df34fdd4f711a67d80412f5879c9854712
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1623490Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarVladislav Kaznacheev <kaznacheev@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663875}
parent eebac46b
...@@ -491,8 +491,6 @@ component("ash") { ...@@ -491,8 +491,6 @@ component("ash") {
"multi_user/user_switch_animator.h", "multi_user/user_switch_animator.h",
"network_connect_delegate_mus.cc", "network_connect_delegate_mus.cc",
"network_connect_delegate_mus.h", "network_connect_delegate_mus.h",
"note_taking_controller.cc",
"note_taking_controller.h",
"policy/policy_recommendation_restorer.cc", "policy/policy_recommendation_restorer.cc",
"policy/policy_recommendation_restorer.h", "policy/policy_recommendation_restorer.h",
"root_window_controller.cc", "root_window_controller.cc",
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "ash/kiosk_next/kiosk_next_shell_controller.h" #include "ash/kiosk_next/kiosk_next_shell_controller.h"
#include "ash/login/login_screen_controller.h" #include "ash/login/login_screen_controller.h"
#include "ash/media/media_controller.h" #include "ash/media/media_controller.h"
#include "ash/note_taking_controller.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -151,11 +150,6 @@ void BindNightLightControllerRequestOnMainThread( ...@@ -151,11 +150,6 @@ void BindNightLightControllerRequestOnMainThread(
Shell::Get()->night_light_controller()->BindRequest(std::move(request)); Shell::Get()->night_light_controller()->BindRequest(std::move(request));
} }
void BindNoteTakingControllerRequestOnMainThread(
mojom::NoteTakingControllerRequest request) {
Shell::Get()->note_taking_controller()->BindRequest(std::move(request));
}
void BindShelfIntegrationTestApiRequestOnMainThread( void BindShelfIntegrationTestApiRequestOnMainThread(
mojom::ShelfIntegrationTestApiRequest request) { mojom::ShelfIntegrationTestApiRequest request) {
ShelfIntegrationTestApi::BindRequest(std::move(request)); ShelfIntegrationTestApi::BindRequest(std::move(request));
...@@ -259,9 +253,6 @@ void RegisterInterfaces( ...@@ -259,9 +253,6 @@ void RegisterInterfaces(
registry->AddInterface( registry->AddInterface(
base::BindRepeating(&BindNightLightControllerRequestOnMainThread), base::BindRepeating(&BindNightLightControllerRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
registry->AddInterface(
base::BindRepeating(&BindNoteTakingControllerRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface( registry->AddInterface(
base::BindRepeating(&BindShutdownControllerRequestOnMainThread), base::BindRepeating(&BindShutdownControllerRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
......
// Copyright 2017 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/note_taking_controller.h"
#include "base/bind.h"
namespace ash {
NoteTakingController::NoteTakingController() : binding_(this) {}
NoteTakingController::~NoteTakingController() = default;
void NoteTakingController::BindRequest(
mojom::NoteTakingControllerRequest request) {
binding_.Bind(std::move(request));
}
void NoteTakingController::SetClient(
mojom::NoteTakingControllerClientPtr client) {
DCHECK(!client_);
client_ = std::move(client);
client_.set_connection_error_handler(base::Bind(
&NoteTakingController::OnClientConnectionLost, base::Unretained(this)));
}
bool NoteTakingController::CanCreateNote() const {
return static_cast<bool>(client_);
}
void NoteTakingController::CreateNote() {
DCHECK(client_);
client_->CreateNote();
}
void NoteTakingController::OnClientConnectionLost() {
client_.reset();
binding_.Close();
}
void NoteTakingController::FlushMojoForTesting() {
if (client_)
client_.FlushForTesting();
}
} // namespace ash
// Copyright 2017 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_NOTETAKING_CONTROLLER_H_
#define ASH_NOTETAKING_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/public/interfaces/note_taking_controller.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace ash {
// Controller for the note taking functionality.
class ASH_EXPORT NoteTakingController : public mojom::NoteTakingController {
public:
NoteTakingController();
~NoteTakingController() override;
void BindRequest(mojom::NoteTakingControllerRequest request);
// mojom::NoteTakingController:
void SetClient(mojom::NoteTakingControllerClientPtr client) override;
// Returns true if the client is attached.
bool CanCreateNote() const;
// Calls the method of the same name on |client_|.
void CreateNote();
private:
friend class TestNoteTakingControllerClient;
void OnClientConnectionLost();
void FlushMojoForTesting();
// Binding for mojom::NoteTakingController interface.
mojo::Binding<ash::mojom::NoteTakingController> binding_;
// Interface to NoteTaking controller client (chrome).
mojom::NoteTakingControllerClientPtr client_;
DISALLOW_COPY_AND_ASSIGN(NoteTakingController);
};
} // namespace ash
#endif // ASH_NOTETAKING_CONTROLLER_H_
...@@ -99,6 +99,8 @@ component("cpp") { ...@@ -99,6 +99,8 @@ component("cpp") {
"network_icon_image_source.h", "network_icon_image_source.h",
"new_window_delegate.cc", "new_window_delegate.cc",
"new_window_delegate.h", "new_window_delegate.h",
"note_taking_client.cc",
"note_taking_client.h",
"notification_utils.cc", "notification_utils.cc",
"notification_utils.h", "notification_utils.h",
"pagination/pagination_controller.cc", "pagination/pagination_controller.cc",
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "ash/public/interfaces/login_screen.mojom.h" #include "ash/public/interfaces/login_screen.mojom.h"
#include "ash/public/interfaces/media.mojom.h" #include "ash/public/interfaces/media.mojom.h"
#include "ash/public/interfaces/night_light_controller.mojom.h" #include "ash/public/interfaces/night_light_controller.mojom.h"
#include "ash/public/interfaces/note_taking_controller.mojom.h"
#include "ash/public/interfaces/shelf_integration_test_api.mojom.h" #include "ash/public/interfaces/shelf_integration_test_api.mojom.h"
#include "ash/public/interfaces/shutdown.mojom.h" #include "ash/public/interfaces/shutdown.mojom.h"
#include "ash/public/interfaces/tablet_mode.mojom.h" #include "ash/public/interfaces/tablet_mode.mojom.h"
...@@ -74,10 +73,9 @@ const service_manager::Manifest& GetManifest() { ...@@ -74,10 +73,9 @@ const service_manager::Manifest& GetManifest() {
mojom::ImeController, mojom::KeyboardController, mojom::ImeController, mojom::KeyboardController,
mojom::LocaleUpdateController, mojom::LoginScreen, mojom::LocaleUpdateController, mojom::LoginScreen,
mojom::MediaController, mojom::NightLightController, mojom::MediaController, mojom::NightLightController,
mojom::NoteTakingController, mojom::ShutdownController, mojom::ShutdownController, mojom::TabletModeController,
mojom::TabletModeController, mojom::TrayAction, mojom::TrayAction, mojom::VoiceInteractionController,
mojom::VoiceInteractionController, mojom::VpnList, mojom::VpnList, mojom::WallpaperController>())
mojom::WallpaperController>())
.ExposeCapability("test", service_manager::Manifest::InterfaceList< .ExposeCapability("test", service_manager::Manifest::InterfaceList<
mojom::ShelfIntegrationTestApi>()) mojom::ShelfIntegrationTestApi>())
.RequireCapability("*", "accessibility") .RequireCapability("*", "accessibility")
......
// Copyright 2019 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/note_taking_client.h"
#include "base/logging.h"
namespace ash {
namespace {
NoteTakingClient* g_note_taking_client = nullptr;
}
// static
NoteTakingClient* NoteTakingClient::GetInstance() {
return g_note_taking_client;
}
NoteTakingClient::NoteTakingClient() {
DCHECK(!g_note_taking_client);
g_note_taking_client = this;
}
NoteTakingClient::~NoteTakingClient() {
DCHECK_EQ(g_note_taking_client, this);
g_note_taking_client = nullptr;
}
} // namespace ash
// Copyright 2019 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_NOTE_TAKING_CLIENT_H_
#define ASH_PUBLIC_CPP_NOTE_TAKING_CLIENT_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h"
namespace ash {
// Interface for ash to notify the client (e.g. Chrome) about the new note
// creation.
class ASH_PUBLIC_EXPORT NoteTakingClient {
public:
static NoteTakingClient* GetInstance();
// Returns true when it can create notes.
virtual bool CanCreateNote() = 0;
// Called when the controller needs to create a new note.
virtual void CreateNote() = 0;
protected:
NoteTakingClient();
virtual ~NoteTakingClient();
private:
DISALLOW_COPY_AND_ASSIGN(NoteTakingClient);
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_NOTE_TAKING_CLIENT_H_
...@@ -38,7 +38,6 @@ mojom("interfaces_internal") { ...@@ -38,7 +38,6 @@ mojom("interfaces_internal") {
"login_screen.mojom", "login_screen.mojom",
"media.mojom", "media.mojom",
"night_light_controller.mojom", "night_light_controller.mojom",
"note_taking_controller.mojom",
"shelf_integration_test_api.mojom", "shelf_integration_test_api.mojom",
"shutdown.mojom", "shutdown.mojom",
"tablet_mode.mojom", "tablet_mode.mojom",
......
// Copyright 2017 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.
module ash.mojom;
// Interface for ash client (e.g. Chrome) to connect to the note taking
// controller.
interface NoteTakingController {
// Sets the client interface.
SetClient(NoteTakingControllerClient client);
};
// Interface for ash to notify the client (e.g. Chrome) about the new note
// creation.
interface NoteTakingControllerClient {
// Called when the controller needs to create a new note.
CreateNote();
};
\ No newline at end of file
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
#include "ash/media/media_controller.h" #include "ash/media/media_controller.h"
#include "ash/media/media_notification_controller_impl.h" #include "ash/media/media_notification_controller_impl.h"
#include "ash/multi_device_setup/multi_device_notification_presenter.h" #include "ash/multi_device_setup/multi_device_notification_presenter.h"
#include "ash/note_taking_controller.h"
#include "ash/policy/policy_recommendation_restorer.h" #include "ash/policy/policy_recommendation_restorer.h"
#include "ash/public/cpp/ash_constants.h" #include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
...@@ -556,7 +555,6 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, ...@@ -556,7 +555,6 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
locale_update_controller_(std::make_unique<LocaleUpdateController>()), locale_update_controller_(std::make_unique<LocaleUpdateController>()),
media_controller_(std::make_unique<MediaController>(connector)), media_controller_(std::make_unique<MediaController>(connector)),
session_controller_(std::make_unique<SessionControllerImpl>()), session_controller_(std::make_unique<SessionControllerImpl>()),
note_taking_controller_(std::make_unique<NoteTakingController>()),
shell_delegate_(std::move(shell_delegate)), shell_delegate_(std::move(shell_delegate)),
shell_state_(std::make_unique<ShellState>()), shell_state_(std::make_unique<ShellState>()),
shutdown_controller_(std::make_unique<ShutdownController>()), shutdown_controller_(std::make_unique<ShutdownController>()),
......
...@@ -143,7 +143,6 @@ class MouseCursorEventFilter; ...@@ -143,7 +143,6 @@ class MouseCursorEventFilter;
class MruWindowTracker; class MruWindowTracker;
class MultiDeviceNotificationPresenter; class MultiDeviceNotificationPresenter;
class NightLightController; class NightLightController;
class NoteTakingController;
class OverlayEventFilter; class OverlayEventFilter;
class OverviewController; class OverviewController;
class PartialMagnificationController; class PartialMagnificationController;
...@@ -415,9 +414,6 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -415,9 +414,6 @@ class ASH_EXPORT Shell : public SessionObserver,
} }
MruWindowTracker* mru_window_tracker() { return mru_window_tracker_.get(); } MruWindowTracker* mru_window_tracker() { return mru_window_tracker_.get(); }
NightLightController* night_light_controller(); NightLightController* night_light_controller();
NoteTakingController* note_taking_controller() {
return note_taking_controller_.get();
}
OverlayEventFilter* overlay_filter() { return overlay_filter_.get(); } OverlayEventFilter* overlay_filter() { return overlay_filter_.get(); }
PartialMagnificationController* partial_magnification_controller() { PartialMagnificationController* partial_magnification_controller() {
return partial_magnification_controller_.get(); return partial_magnification_controller_.get();
...@@ -682,7 +678,6 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -682,7 +678,6 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<ResizeShadowController> resize_shadow_controller_; std::unique_ptr<ResizeShadowController> resize_shadow_controller_;
std::unique_ptr<SessionControllerImpl> session_controller_; std::unique_ptr<SessionControllerImpl> session_controller_;
std::unique_ptr<NightLightController> night_light_controller_; std::unique_ptr<NightLightController> night_light_controller_;
std::unique_ptr<NoteTakingController> note_taking_controller_;
std::unique_ptr<PolicyRecommendationRestorer> policy_recommendation_restorer_; std::unique_ptr<PolicyRecommendationRestorer> policy_recommendation_restorer_;
std::unique_ptr<ScreenSwitchCheckController> screen_switch_check_controller_; std::unique_ptr<ScreenSwitchCheckController> screen_switch_check_controller_;
std::unique_ptr<ShelfController> shelf_controller_; std::unique_ptr<ShelfController> shelf_controller_;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "ash/system/palette/tools/create_note_action.h" #include "ash/system/palette/tools/create_note_action.h"
#include "ash/note_taking_controller.h" #include "ash/public/cpp/note_taking_client.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace ash { namespace ash {
namespace {
NoteTakingClient* GetAvailableClient() {
auto* client = NoteTakingClient::GetInstance();
if (!client || !client->CanCreateNote())
return nullptr;
return client;
}
} // namespace
CreateNoteAction::CreateNoteAction(Delegate* delegate) CreateNoteAction::CreateNoteAction(Delegate* delegate)
: CommonPaletteTool(delegate) {} : CommonPaletteTool(delegate) {}
...@@ -29,14 +37,16 @@ PaletteToolId CreateNoteAction::GetToolId() const { ...@@ -29,14 +37,16 @@ PaletteToolId CreateNoteAction::GetToolId() const {
void CreateNoteAction::OnEnable() { void CreateNoteAction::OnEnable() {
CommonPaletteTool::OnEnable(); CommonPaletteTool::OnEnable();
Shell::Get()->note_taking_controller()->CreateNote(); auto* client = GetAvailableClient();
if (client)
client->CreateNote();
delegate()->DisableTool(GetToolId()); delegate()->DisableTool(GetToolId());
delegate()->HidePalette(); delegate()->HidePalette();
} }
views::View* CreateNoteAction::CreateView() { views::View* CreateNoteAction::CreateView() {
if (!Shell::Get()->note_taking_controller()->CanCreateNote()) if (!GetAvailableClient())
return nullptr; return nullptr;
return CreateDefaultView( return CreateDefaultView(
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
#include <memory> #include <memory>
#include "ash/note_taking_controller.h" #include "ash/public/cpp/note_taking_client.h"
#include "ash/shell.h"
#include "ash/system/palette/mock_palette_tool_delegate.h" #include "ash/system/palette/mock_palette_tool_delegate.h"
#include "ash/system/palette/palette_ids.h" #include "ash/system/palette/palette_ids.h"
#include "ash/system/palette/palette_tool.h" #include "ash/system/palette/palette_tool.h"
...@@ -17,48 +16,25 @@ ...@@ -17,48 +16,25 @@
namespace ash { namespace ash {
class TestNoteTakingControllerClient class TestNoteTakingControllerClient : public NoteTakingClient {
: public ash::mojom::NoteTakingControllerClient {
public: public:
TestNoteTakingControllerClient() : binding_(this) {} TestNoteTakingControllerClient() = default;
~TestNoteTakingControllerClient() override = default; ~TestNoteTakingControllerClient() override = default;
void Attach() {
DCHECK(!controller_);
Shell::Get()->note_taking_controller()->BindRequest(
mojo::MakeRequest(&controller_));
ash::mojom::NoteTakingControllerClientPtr client;
binding_.Bind(mojo::MakeRequest(&client));
controller_->SetClient(std::move(client));
controller_.FlushForTesting();
}
void Detach() {
DCHECK(controller_);
controller_ = nullptr;
DCHECK(binding_.is_bound());
binding_.Close();
FlushClientMojo();
}
int GetCreateNoteCount() { int GetCreateNoteCount() {
FlushClientMojo();
return create_note_count_; return create_note_count_;
} }
// ash::mojom::NoteTakingControllerClient: void set_can_create(bool can_create) { can_create_ = can_create; }
// NoteTakingClient:
bool CanCreateNote() override { return can_create_; }
void CreateNote() override { create_note_count_++; } void CreateNote() override { create_note_count_++; }
private: private:
void FlushClientMojo() { bool can_create_ = true;
Shell::Get()->note_taking_controller()->FlushMojoForTesting();
}
int create_note_count_ = 0; int create_note_count_ = 0;
mojo::Binding<ash::mojom::NoteTakingControllerClient> binding_;
ash::mojom::NoteTakingControllerPtr controller_;
DISALLOW_COPY_AND_ASSIGN(TestNoteTakingControllerClient); DISALLOW_COPY_AND_ASSIGN(TestNoteTakingControllerClient);
}; };
...@@ -75,13 +51,11 @@ class CreateNoteTest : public AshTestBase { ...@@ -75,13 +51,11 @@ class CreateNoteTest : public AshTestBase {
palette_tool_delegate_ = std::make_unique<MockPaletteToolDelegate>(); palette_tool_delegate_ = std::make_unique<MockPaletteToolDelegate>();
tool_ = std::make_unique<CreateNoteAction>(palette_tool_delegate_.get()); tool_ = std::make_unique<CreateNoteAction>(palette_tool_delegate_.get());
note_taking_client_ = std::make_unique<TestNoteTakingControllerClient>();
} }
protected: protected:
std::unique_ptr<MockPaletteToolDelegate> palette_tool_delegate_; std::unique_ptr<MockPaletteToolDelegate> palette_tool_delegate_;
std::unique_ptr<PaletteTool> tool_; std::unique_ptr<PaletteTool> tool_;
std::unique_ptr<TestNoteTakingControllerClient> note_taking_client_;
private: private:
DISALLOW_COPY_AND_ASSIGN(CreateNoteTest); DISALLOW_COPY_AND_ASSIGN(CreateNoteTest);
...@@ -94,12 +68,16 @@ TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) { ...@@ -94,12 +68,16 @@ TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) {
EXPECT_FALSE(tool_->CreateView()); EXPECT_FALSE(tool_->CreateView());
tool_->OnViewDestroyed(); tool_->OnViewDestroyed();
note_taking_client_->Attach(); auto note_taking_client = std::make_unique<TestNoteTakingControllerClient>();
std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView()); std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView());
EXPECT_TRUE(view); EXPECT_TRUE(view);
tool_->OnViewDestroyed(); tool_->OnViewDestroyed();
note_taking_client_->Detach(); note_taking_client->set_can_create(false);
EXPECT_FALSE(tool_->CreateView());
tool_->OnViewDestroyed();
note_taking_client.reset();
EXPECT_FALSE(tool_->CreateView()); EXPECT_FALSE(tool_->CreateView());
tool_->OnViewDestroyed(); tool_->OnViewDestroyed();
} }
...@@ -107,7 +85,7 @@ TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) { ...@@ -107,7 +85,7 @@ TEST_F(CreateNoteTest, ViewOnlyCreatedWhenNoteAppIsAvailable) {
// Activating the note tool both creates a note on the client and also // Activating the note tool both creates a note on the client and also
// disables the tool and hides the palette. // disables the tool and hides the palette.
TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) { TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) {
note_taking_client_->Attach(); auto note_taking_client = std::make_unique<TestNoteTakingControllerClient>();
std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView()); std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView());
EXPECT_CALL(*palette_tool_delegate_.get(), EXPECT_CALL(*palette_tool_delegate_.get(),
...@@ -115,7 +93,34 @@ TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) { ...@@ -115,7 +93,34 @@ TEST_F(CreateNoteTest, EnablingToolCreatesNewNoteAndDisablesTool) {
EXPECT_CALL(*palette_tool_delegate_.get(), HidePalette()); EXPECT_CALL(*palette_tool_delegate_.get(), HidePalette());
tool_->OnEnable(); tool_->OnEnable();
EXPECT_EQ(1, note_taking_client_->GetCreateNoteCount()); EXPECT_EQ(1, note_taking_client->GetCreateNoteCount());
}
TEST_F(CreateNoteTest, ClientGetsDisabledAfterViewCreated) {
auto note_taking_client = std::make_unique<TestNoteTakingControllerClient>();
std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView());
EXPECT_CALL(*palette_tool_delegate_.get(),
DisableTool(PaletteToolId::CREATE_NOTE));
EXPECT_CALL(*palette_tool_delegate_.get(), HidePalette());
note_taking_client->set_can_create(false);
tool_->OnEnable();
EXPECT_EQ(0, note_taking_client->GetCreateNoteCount());
}
TEST_F(CreateNoteTest, ClientGetsRemovedAfterViewCreated) {
auto note_taking_client = std::make_unique<TestNoteTakingControllerClient>();
std::unique_ptr<views::View> view = base::WrapUnique(tool_->CreateView());
EXPECT_CALL(*palette_tool_delegate_.get(),
DisableTool(PaletteToolId::CREATE_NOTE));
EXPECT_CALL(*palette_tool_delegate_.get(), HidePalette());
note_taking_client.reset();
tool_->OnEnable();
} }
} // namespace ash } // namespace ash
...@@ -4,21 +4,16 @@ ...@@ -4,21 +4,16 @@
#include "chrome/browser/chromeos/note_taking_controller_client.h" #include "chrome/browser/chromeos/note_taking_controller_client.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/cpp/connector.h"
namespace chromeos { namespace chromeos {
NoteTakingControllerClient::NoteTakingControllerClient(NoteTakingHelper* helper) NoteTakingControllerClient::NoteTakingControllerClient(NoteTakingHelper* helper)
: helper_(helper), note_observer_(this), binding_(this) { : helper_(helper) {
note_observer_.Add(helper_);
registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
...@@ -27,35 +22,14 @@ NoteTakingControllerClient::NoteTakingControllerClient(NoteTakingHelper* helper) ...@@ -27,35 +22,14 @@ NoteTakingControllerClient::NoteTakingControllerClient(NoteTakingHelper* helper)
NoteTakingControllerClient::~NoteTakingControllerClient() = default; NoteTakingControllerClient::~NoteTakingControllerClient() = default;
void NoteTakingControllerClient::CreateNote() { bool NoteTakingControllerClient::CanCreateNote() {
helper_->LaunchAppForNewNote(profile_, base::FilePath()); return profile_ && helper_->IsAppAvailable(profile_);
} }
void NoteTakingControllerClient::OnAvailableNoteTakingAppsUpdated() { void NoteTakingControllerClient::CreateNote() {
bool has_app = profile_ && helper_->IsAppAvailable(profile_); helper_->LaunchAppForNewNote(profile_, base::FilePath());
// No need to rebind the client if already connected.
if (binding_.is_bound() == has_app)
return;
if (binding_.is_bound()) {
binding_.Close();
} else {
// Connector can be overridden for testing.
if (!connector_) {
connector_ =
content::ServiceManagerConnection::GetForProcess()->GetConnector();
}
connector_->BindInterface(ash::mojom::kServiceName, &controller_);
ash::mojom::NoteTakingControllerClientPtr client;
binding_.Bind(mojo::MakeRequest(&client));
controller_->SetClient(std::move(client));
}
} }
void NoteTakingControllerClient::OnPreferredNoteTakingAppUpdated(
Profile* profile) {}
void NoteTakingControllerClient::ActiveUserChanged( void NoteTakingControllerClient::ActiveUserChanged(
const user_manager::User* active_user) { const user_manager::User* active_user) {
SetProfile(ProfileHelper::Get()->GetProfileByUser(active_user)); SetProfile(ProfileHelper::Get()->GetProfileByUser(active_user));
...@@ -88,7 +62,6 @@ void NoteTakingControllerClient::Observe( ...@@ -88,7 +62,6 @@ void NoteTakingControllerClient::Observe(
void NoteTakingControllerClient::SetProfile(Profile* profile) { void NoteTakingControllerClient::SetProfile(Profile* profile) {
profile_ = profile; profile_ = profile;
OnAvailableNoteTakingAppsUpdated();
} }
} // namespace chromeos } // namespace chromeos
...@@ -5,38 +5,29 @@ ...@@ -5,38 +5,29 @@
#ifndef CHROME_BROWSER_CHROMEOS_NOTE_TAKING_CONTROLLER_CLIENT_H_ #ifndef CHROME_BROWSER_CHROMEOS_NOTE_TAKING_CONTROLLER_CLIENT_H_
#define CHROME_BROWSER_CHROMEOS_NOTE_TAKING_CONTROLLER_CLIENT_H_ #define CHROME_BROWSER_CHROMEOS_NOTE_TAKING_CONTROLLER_CLIENT_H_
#include "ash/public/interfaces/note_taking_controller.mojom.h" #include "ash/public/cpp/note_taking_client.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/note_taking_helper.h" #include "chrome/browser/chromeos/note_taking_helper.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/binding.h"
class Profile; class Profile;
namespace service_manager {
class Connector;
}
namespace chromeos { namespace chromeos {
class NoteTakingControllerClient class NoteTakingControllerClient
: public ash::mojom::NoteTakingControllerClient, : public ash::NoteTakingClient,
public NoteTakingHelper::Observer,
public user_manager::UserManager::UserSessionStateObserver, public user_manager::UserManager::UserSessionStateObserver,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
explicit NoteTakingControllerClient(NoteTakingHelper* helper); explicit NoteTakingControllerClient(NoteTakingHelper* helper);
~NoteTakingControllerClient() override; ~NoteTakingControllerClient() override;
// ash::mojom::NoteTakingControllerClient: // ash::NoteTakingClient:
bool CanCreateNote() override;
void CreateNote() override; void CreateNote() override;
// chromeos::NoteTakingHelper::Observer:
void OnAvailableNoteTakingAppsUpdated() override;
void OnPreferredNoteTakingAppUpdated(Profile* profile) override;
// user_manager::UserManager::UserSessionStateObserver: // user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(const user_manager::User* active_user) override; void ActiveUserChanged(const user_manager::User* active_user) override;
...@@ -45,17 +36,8 @@ class NoteTakingControllerClient ...@@ -45,17 +36,8 @@ class NoteTakingControllerClient
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override; const content::NotificationDetails& details) override;
void SetConnectorForTesting(service_manager::Connector* connector) {
connector_ = connector;
}
void SetProfileForTesting(Profile* profile) { SetProfile(profile); } void SetProfileForTesting(Profile* profile) { SetProfile(profile); }
void FlushMojoForTesting() {
if (controller_)
controller_.FlushForTesting();
}
private: private:
void SetProfile(Profile* profile); void SetProfile(Profile* profile);
...@@ -65,15 +47,10 @@ class NoteTakingControllerClient ...@@ -65,15 +47,10 @@ class NoteTakingControllerClient
// Unowned pointer to the active profile. // Unowned pointer to the active profile.
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
ScopedObserver<NoteTakingHelper, NoteTakingHelper::Observer> note_observer_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
std::unique_ptr<user_manager::ScopedUserSessionStateObserver> std::unique_ptr<user_manager::ScopedUserSessionStateObserver>
session_state_observer_; session_state_observer_;
mojo::Binding<ash::mojom::NoteTakingControllerClient> binding_;
service_manager::Connector* connector_ = nullptr;
ash::mojom::NoteTakingControllerPtr controller_;
DISALLOW_COPY_AND_ASSIGN(NoteTakingControllerClient); DISALLOW_COPY_AND_ASSIGN(NoteTakingControllerClient);
}; };
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <utility> #include <utility>
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -47,9 +46,6 @@ ...@@ -47,9 +46,6 @@
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "extensions/common/extension_id.h" #include "extensions/common/extension_id.h"
#include "extensions/common/value_builder.h" #include "extensions/common/value_builder.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace app_runtime = extensions::api::app_runtime; namespace app_runtime = extensions::api::app_runtime;
...@@ -148,53 +144,6 @@ class TestObserver : public NoteTakingHelper::Observer { ...@@ -148,53 +144,6 @@ class TestObserver : public NoteTakingHelper::Observer {
DISALLOW_COPY_AND_ASSIGN(TestObserver); DISALLOW_COPY_AND_ASSIGN(TestObserver);
}; };
class TestNoteTakingController : public ash::mojom::NoteTakingController,
public service_manager::Service {
public:
explicit TestNoteTakingController(
service_manager::mojom::ServiceRequest request)
: service_binding_(this, std::move(request)) {}
~TestNoteTakingController() override = default;
void CallCreateNote() {
client_->CreateNote();
client_.FlushForTesting();
}
bool client_attached() const { return static_cast<bool>(client_); }
// ash::mojom::NoteTakingController:
void SetClient(ash::mojom::NoteTakingControllerClientPtr client) override {
DCHECK(!client_);
client_ = std::move(client);
client_.set_connection_error_handler(
base::Bind(&TestNoteTakingController::OnClientConnectionLost,
base::Unretained(this)));
}
// service_manager::Service:
void OnBindInterface(const service_manager::BindSourceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override {
DCHECK(interface_name == ash::mojom::NoteTakingController::Name_);
binding_.Bind(
ash::mojom::NoteTakingControllerRequest(std::move(interface_pipe)));
}
private:
void OnClientConnectionLost() {
client_.reset();
binding_.Close();
}
service_manager::ServiceBinding service_binding_;
mojo::Binding<ash::mojom::NoteTakingController> binding_{this};
ash::mojom::NoteTakingControllerClientPtr client_;
DISALLOW_COPY_AND_ASSIGN(TestNoteTakingController);
};
} // namespace } // namespace
class NoteTakingHelperTest : public BrowserWithTestWindowTest { class NoteTakingHelperTest : public BrowserWithTestWindowTest {
...@@ -240,10 +189,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -240,10 +189,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
static NoteTakingHelper* helper() { return NoteTakingHelper::Get(); } static NoteTakingHelper* helper() { return NoteTakingHelper::Get(); }
TestNoteTakingController* test_note_taking_controller() {
return test_note_taking_controller_.get();
}
NoteTakingControllerClient* note_taking_client() { NoteTakingControllerClient* note_taking_client() {
return helper()->GetNoteTakingControllerClientForTesting(); return helper()->GetNoteTakingControllerClientForTesting();
} }
...@@ -251,12 +196,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -251,12 +196,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
void SetNoteTakingClientProfile(Profile* profile) { void SetNoteTakingClientProfile(Profile* profile) {
if (note_taking_client()) if (note_taking_client())
note_taking_client()->SetProfileForTesting(profile); note_taking_client()->SetProfileForTesting(profile);
FlushNoteTakingClientMojo();
}
void FlushNoteTakingClientMojo() {
if (note_taking_client())
note_taking_client()->FlushMojoForTesting();
} }
// Initializes ARC and NoteTakingHelper. |flags| contains OR-ed together // Initializes ARC and NoteTakingHelper. |flags| contains OR-ed together
...@@ -291,11 +230,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -291,11 +230,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
NoteTakingHelper::Get()->SetProfileWithEnabledLockScreenApps(profile()); NoteTakingHelper::Get()->SetProfileWithEnabledLockScreenApps(profile());
NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind( NoteTakingHelper::Get()->set_launch_chrome_app_callback_for_test(base::Bind(
&NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this))); &NoteTakingHelperTest::LaunchChromeApp, base::Unretained(this)));
test_note_taking_controller_ = std::make_unique<TestNoteTakingController>(
connector_factory_.RegisterInstance(ash::mojom::kServiceName));
note_taking_client()->SetConnectorForTesting(
connector_factory_.GetDefaultConnector());
} }
// Creates an extension. // Creates an extension.
...@@ -355,7 +289,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -355,7 +289,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
extensions::ExtensionSystem::Get(profile) extensions::ExtensionSystem::Get(profile)
->extension_service() ->extension_service()
->AddExtension(extension); ->AddExtension(extension);
FlushNoteTakingClientMojo();
} }
void UninstallExtension(const extensions::Extension* extension, void UninstallExtension(const extensions::Extension* extension,
Profile* profile) { Profile* profile) {
...@@ -365,7 +298,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -365,7 +298,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
->UninstallExtension( ->UninstallExtension(
extension->id(), extension->id(),
extensions::UninstallReason::UNINSTALL_REASON_FOR_TESTING, &error); extensions::UninstallReason::UNINSTALL_REASON_FOR_TESTING, &error);
FlushNoteTakingClientMojo();
} }
scoped_refptr<const extensions::Extension> CreateAndInstallLockScreenApp( scoped_refptr<const extensions::Extension> CreateAndInstallLockScreenApp(
...@@ -494,8 +426,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest { ...@@ -494,8 +426,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
ArcAppTest arc_test_; ArcAppTest arc_test_;
std::unique_ptr<arc::ArcIntentHelperBridge> intent_helper_bridge_; std::unique_ptr<arc::ArcIntentHelperBridge> intent_helper_bridge_;
service_manager::TestConnectorFactory connector_factory_;
std::unique_ptr<TestNoteTakingController> test_note_taking_controller_;
DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest); DISALLOW_COPY_AND_ASSIGN(NoteTakingHelperTest);
}; };
...@@ -1501,7 +1431,8 @@ TEST_F(NoteTakingHelperTest, NoteTakingControllerClient) { ...@@ -1501,7 +1431,8 @@ TEST_F(NoteTakingHelperTest, NoteTakingControllerClient) {
Init(ENABLE_PALETTE); Init(ENABLE_PALETTE);
auto has_note_taking_apps = [&]() { auto has_note_taking_apps = [&]() {
return test_note_taking_controller()->client_attached(); auto* client = ash::NoteTakingClient::GetInstance();
return client && client->CanCreateNote();
}; };
EXPECT_FALSE(has_note_taking_apps()); EXPECT_FALSE(has_note_taking_apps());
...@@ -1543,7 +1474,7 @@ TEST_F(NoteTakingHelperTest, NoteTakingControllerClient) { ...@@ -1543,7 +1474,7 @@ TEST_F(NoteTakingHelperTest, NoteTakingControllerClient) {
SetNoteTakingClientProfile(profile()); SetNoteTakingClientProfile(profile());
EXPECT_TRUE(has_note_taking_apps()); EXPECT_TRUE(has_note_taking_apps());
test_note_taking_controller()->CallCreateNote(); ash::NoteTakingClient::GetInstance()->CreateNote();
ASSERT_EQ(1u, launched_chrome_apps_.size()); ASSERT_EQ(1u, launched_chrome_apps_.size());
ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId, ASSERT_EQ(NoteTakingHelper::kProdKeepExtensionId,
launched_chrome_apps_[0].id); launched_chrome_apps_[0].id);
......
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