Commit f539884f authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Convert some first-run tutorial methods to mojo

This is part of moving ash out-of-process for mustash.

* Introduce FirstRunHelper mojo interface
* Make ash::FirstRunHelper object owned by ash::Shell
* Add explicit create/close widget methods because object is now
  persistent
* Add system tray test API to check if bubble is open

Next step is to move the widget creation into chrome.

Bug: 756057
Test: ash_unittests, browser_tests
Change-Id: Ie3994bd36b6dfeecd1c685773c5ce8e19394052e
Reviewed-on: https://chromium-review.googlesource.com/998181
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551091}
parent 97c1d4d2
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/first_run/first_run_helper.h" #include "ash/first_run/first_run_helper.h"
#include "ash/first_run/desktop_cleaner.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/shelf/app_list_button.h" #include "ash/shelf/app_list_button.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
...@@ -38,15 +39,12 @@ views::Widget* CreateFirstRunWindow() { ...@@ -38,15 +39,12 @@ views::Widget* CreateFirstRunWindow() {
} // namespace } // namespace
FirstRunHelper::FirstRunHelper() : widget_(CreateFirstRunWindow()) { FirstRunHelper::FirstRunHelper() = default;
Shell::Get()->overlay_filter()->Activate(this);
}
FirstRunHelper::~FirstRunHelper() { FirstRunHelper::~FirstRunHelper() = default;
Shell::Get()->overlay_filter()->Deactivate(this);
if (IsTrayBubbleOpened()) void FirstRunHelper::BindRequest(mojom::FirstRunHelperRequest request) {
CloseTrayBubble(); bindings_.AddBinding(this, std::move(request));
widget_->Close();
} }
void FirstRunHelper::AddObserver(Observer* observer) { void FirstRunHelper::AddObserver(Observer* observer) {
...@@ -61,38 +59,48 @@ views::Widget* FirstRunHelper::GetOverlayWidget() { ...@@ -61,38 +59,48 @@ views::Widget* FirstRunHelper::GetOverlayWidget() {
return widget_; return widget_;
} }
gfx::Rect FirstRunHelper::GetAppListButtonBounds() { void FirstRunHelper::CreateOverlayWidget() {
widget_ = CreateFirstRunWindow();
cleaner_ = std::make_unique<DesktopCleaner>();
Shell::Get()->overlay_filter()->Activate(this);
}
void FirstRunHelper::CloseOverlayWidget() {
Shell::Get()->overlay_filter()->Deactivate(this);
// Ensure the tray is closed.
Shell::Get()->GetPrimarySystemTray()->CloseBubble();
widget_->Close();
widget_ = nullptr;
cleaner_.reset();
}
void FirstRunHelper::GetAppListButtonBounds(GetAppListButtonBoundsCallback cb) {
Shelf* shelf = Shelf::ForWindow(Shell::GetPrimaryRootWindow()); Shelf* shelf = Shelf::ForWindow(Shell::GetPrimaryRootWindow());
AppListButton* app_button = shelf->shelf_widget()->GetAppListButton(); AppListButton* app_button = shelf->shelf_widget()->GetAppListButton();
return app_button->GetBoundsInScreen(); std::move(cb).Run(app_button->GetBoundsInScreen());
} }
void FirstRunHelper::OpenTrayBubble() { void FirstRunHelper::OpenTrayBubble(OpenTrayBubbleCallback cb) {
SystemTray* tray = Shell::Get()->GetPrimarySystemTray(); SystemTray* tray = Shell::Get()->GetPrimarySystemTray();
tray->ShowPersistentDefaultView(); tray->ShowPersistentDefaultView();
views::View* bubble = tray->GetSystemBubble()->bubble_view();
std::move(cb).Run(bubble->GetBoundsInScreen());
} }
void FirstRunHelper::CloseTrayBubble() { void FirstRunHelper::CloseTrayBubble() {
SystemTray* tray = Shell::Get()->GetPrimarySystemTray(); SystemTray* tray = Shell::Get()->GetPrimarySystemTray();
DCHECK(tray->HasSystemBubble()) << "Tray bubble is closed already.";
tray->CloseBubble(); tray->CloseBubble();
} }
bool FirstRunHelper::IsTrayBubbleOpened() { void FirstRunHelper::GetHelpButtonBounds(GetHelpButtonBoundsCallback cb) {
SystemTray* tray = Shell::Get()->GetPrimarySystemTray();
return tray->HasSystemBubble();
}
gfx::Rect FirstRunHelper::GetTrayBubbleBounds() {
SystemTray* tray = Shell::Get()->GetPrimarySystemTray();
views::View* bubble = tray->GetSystemBubble()->bubble_view();
return bubble->GetBoundsInScreen();
}
gfx::Rect FirstRunHelper::GetHelpButtonBounds() {
SystemTray* tray = Shell::Get()->GetPrimarySystemTray(); SystemTray* tray = Shell::Get()->GetPrimarySystemTray();
views::View* help_button = tray->GetHelpButtonView(); views::View* help_button = tray->GetHelpButtonView();
return help_button->GetBoundsInScreen(); // |help_button| could be null if the tray isn't open.
if (!help_button) {
std::move(cb).Run(gfx::Rect());
return;
}
std::move(cb).Run(help_button->GetBoundsInScreen());
} }
// OverlayEventFilter::Delegate: // OverlayEventFilter::Delegate:
......
...@@ -6,14 +6,11 @@ ...@@ -6,14 +6,11 @@
#define ASH_FIRST_RUN_FIRST_RUN_HELPER_H_ #define ASH_FIRST_RUN_FIRST_RUN_HELPER_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/first_run/desktop_cleaner.h" #include "ash/public/interfaces/first_run_helper.mojom.h"
#include "ash/wm/overlay_event_filter.h" #include "ash/wm/overlay_event_filter.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "mojo/public/cpp/bindings/binding_set.h"
namespace gfx {
class Rect;
}
namespace views { namespace views {
class Widget; class Widget;
...@@ -21,10 +18,12 @@ class Widget; ...@@ -21,10 +18,12 @@ class Widget;
namespace ash { namespace ash {
class DesktopCleaner;
// Interface used by first-run tutorial to manipulate and retrieve information // Interface used by first-run tutorial to manipulate and retrieve information
// about shell elements. // about shell elements.
// All returned coordinates are in screen coordinate system. class ASH_EXPORT FirstRunHelper : public mojom::FirstRunHelper,
class ASH_EXPORT FirstRunHelper : public OverlayEventFilter::Delegate { public OverlayEventFilter::Delegate {
public: public:
class Observer { class Observer {
public: public:
...@@ -35,31 +34,24 @@ class ASH_EXPORT FirstRunHelper : public OverlayEventFilter::Delegate { ...@@ -35,31 +34,24 @@ class ASH_EXPORT FirstRunHelper : public OverlayEventFilter::Delegate {
public: public:
FirstRunHelper(); FirstRunHelper();
virtual ~FirstRunHelper(); ~FirstRunHelper() override;
void BindRequest(mojom::FirstRunHelperRequest request);
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
// Returns widget to place tutorial UI into it. // Returns widget to place tutorial UI into it.
// TODO(jamescook): Migrate widget into chrome and remove these methods.
views::Widget* GetOverlayWidget(); views::Widget* GetOverlayWidget();
void CreateOverlayWidget();
void CloseOverlayWidget();
// Returns bounds of application list button. // mojom::FirstRunHelper:
gfx::Rect GetAppListButtonBounds(); void GetAppListButtonBounds(GetAppListButtonBoundsCallback cb) override;
void OpenTrayBubble(OpenTrayBubbleCallback cb) override;
// Opens and closes system tray bubble. void CloseTrayBubble() override;
void OpenTrayBubble(); void GetHelpButtonBounds(GetHelpButtonBoundsCallback cb) override;
void CloseTrayBubble();
// Returns |true| iff system tray bubble is opened now.
bool IsTrayBubbleOpened();
// Returns bounds of system tray bubble. You must open bubble before calling
// this method.
gfx::Rect GetTrayBubbleBounds();
// Returns bounds of help app button from system tray buble. You must open
// bubble before calling this method.
gfx::Rect GetHelpButtonBounds();
// OverlayEventFilter::Delegate: // OverlayEventFilter::Delegate:
void Cancel() override; void Cancel() override;
...@@ -67,12 +59,16 @@ class ASH_EXPORT FirstRunHelper : public OverlayEventFilter::Delegate { ...@@ -67,12 +59,16 @@ class ASH_EXPORT FirstRunHelper : public OverlayEventFilter::Delegate {
aura::Window* GetWindow() override; aura::Window* GetWindow() override;
private: private:
// Bindings for clients of the mojo interface.
mojo::BindingSet<mojom::FirstRunHelper> bindings_;
// TODO(jamescook): Convert to mojo observer.
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
// The first run dialog window. // The first run dialog window.
views::Widget* widget_; views::Widget* widget_ = nullptr;
DesktopCleaner cleaner_; std::unique_ptr<DesktopCleaner> cleaner_;
DISALLOW_COPY_AND_ASSIGN(FirstRunHelper); DISALLOW_COPY_AND_ASSIGN(FirstRunHelper);
}; };
......
...@@ -64,11 +64,12 @@ class FirstRunHelperTest : public AshTestBase, public FirstRunHelper::Observer { ...@@ -64,11 +64,12 @@ class FirstRunHelperTest : public AshTestBase, public FirstRunHelper::Observer {
CheckContainersAreVisible(); CheckContainersAreVisible();
helper_ = std::make_unique<FirstRunHelper>(); helper_ = std::make_unique<FirstRunHelper>();
helper_->AddObserver(this); helper_->AddObserver(this);
helper_->CreateOverlayWidget();
helper_->GetOverlayWidget()->Show(); helper_->GetOverlayWidget()->Show();
} }
void TearDown() override { void TearDown() override {
EXPECT_TRUE(helper_.get()); helper_->CloseOverlayWidget();
helper_.reset(); helper_.reset();
CheckContainersAreVisible(); CheckContainersAreVisible();
AshTestBase::TearDown(); AshTestBase::TearDown();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"ash::mojom::AshMessageCenterController", "ash::mojom::AshMessageCenterController",
"ash::mojom::CastConfig", "ash::mojom::CastConfig",
"ash::mojom::DockedMagnifierController", "ash::mojom::DockedMagnifierController",
"ash::mojom::FirstRunHelper",
"ash::mojom::HighlighterController", "ash::mojom::HighlighterController",
"ash::mojom::ImeController", "ash::mojom::ImeController",
"ash::mojom::LocaleNotificationController", "ash::mojom::LocaleNotificationController",
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/assistant/ash_assistant_controller.h" #include "ash/assistant/ash_assistant_controller.h"
#include "ash/cast_config_controller.h" #include "ash/cast_config_controller.h"
#include "ash/display/ash_display_controller.h" #include "ash/display/ash_display_controller.h"
#include "ash/first_run/first_run_helper.h"
#include "ash/highlighter/highlighter_controller.h" #include "ash/highlighter/highlighter_controller.h"
#include "ash/ime/ime_controller.h" #include "ash/ime/ime_controller.h"
#include "ash/login/login_screen_controller.h" #include "ash/login/login_screen_controller.h"
...@@ -95,6 +96,11 @@ void BindDockedMagnifierControllerRequestOnMainThread( ...@@ -95,6 +96,11 @@ void BindDockedMagnifierControllerRequestOnMainThread(
Shell::Get()->docked_magnifier_controller()->BindRequest(std::move(request)); Shell::Get()->docked_magnifier_controller()->BindRequest(std::move(request));
} }
void BindFirstRunHelperRequestOnMainThread(
mojom::FirstRunHelperRequest request) {
Shell::Get()->first_run_helper()->BindRequest(std::move(request));
}
void BindHighlighterControllerRequestOnMainThread( void BindHighlighterControllerRequestOnMainThread(
mojom::HighlighterControllerRequest request) { mojom::HighlighterControllerRequest request) {
Shell::Get()->highlighter_controller()->BindRequest(std::move(request)); Shell::Get()->highlighter_controller()->BindRequest(std::move(request));
...@@ -219,6 +225,9 @@ void RegisterInterfaces( ...@@ -219,6 +225,9 @@ void RegisterInterfaces(
base::BindRepeating(&BindDockedMagnifierControllerRequestOnMainThread), base::BindRepeating(&BindDockedMagnifierControllerRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
} }
registry->AddInterface(
base::BindRepeating(&BindFirstRunHelperRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface( registry->AddInterface(
base::Bind(&BindHighlighterControllerRequestOnMainThread), base::Bind(&BindHighlighterControllerRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
......
...@@ -23,6 +23,7 @@ mojom("interfaces_internal") { ...@@ -23,6 +23,7 @@ mojom("interfaces_internal") {
"constants.mojom", "constants.mojom",
"docked_magnifier_controller.mojom", "docked_magnifier_controller.mojom",
"event_properties.mojom", "event_properties.mojom",
"first_run_helper.mojom",
"highlighter_controller.mojom", "highlighter_controller.mojom",
"ime_controller.mojom", "ime_controller.mojom",
"ime_info.mojom", "ime_info.mojom",
......
// 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.
module ash.mojom;
import "ui/gfx/geometry/mojo/geometry.mojom";
// Allows clients to control pieces of the UI used in first-run tutorials.
// Exists because the first-run tutorial is a component extension run by
// Chrome. Methods exist here instead of on the Shelf or SystemTray interfaces
// due to small behavior differences (all methods only affect the primary
// display, opening the system tray bubble is persistent, etc.).
interface FirstRunHelper {
// Returns the bounds of the app list button on the primary display in screen
// coordinates.
GetAppListButtonBounds() => (gfx.mojom.Rect screen_bounds);
// Opens the system tray bubble menu to show the default view. Does nothing if
// the bubble is already open. The bubble stays open until explicitly closed.
// Returns bubble bounds in screen coordinates.
OpenTrayBubble() => (gfx.mojom.Rect screen_bounds);
// Closes the system tray bubble menu. Does nothing if the bubble is already
// closed.
CloseTrayBubble();
// Returns the bounds of the help button on the system tray bubble menu in
// screen coordinates. Returns empty bounds if the bubble is not open.
GetHelpButtonBounds() => (gfx.mojom.Rect screen_bounds);
};
...@@ -18,6 +18,9 @@ interface SystemTrayTestApi { ...@@ -18,6 +18,9 @@ interface SystemTrayTestApi {
// Disables animations (e.g. the tray view icon slide-in). // Disables animations (e.g. the tray view icon slide-in).
DisableAnimations() => (); DisableAnimations() => ();
// Returns true if the system tray bubble menu is open.
IsTrayBubbleOpen() => (bool is_open);
// Returns true if the view exists and is visible in the system tray area // Returns true if the view exists and is visible in the system tray area
// at the bottom of the screen. Usually these views are icons, like the Wi-Fi // at the bottom of the screen. Usually these views are icons, like the Wi-Fi
// or battery icon. // or battery icon.
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "ash/display/screen_position_controller.h" #include "ash/display/screen_position_controller.h"
#include "ash/display/window_tree_host_manager.h" #include "ash/display/window_tree_host_manager.h"
#include "ash/drag_drop/drag_drop_controller.h" #include "ash/drag_drop/drag_drop_controller.h"
#include "ash/first_run/first_run_helper.h"
#include "ash/focus_cycler.h" #include "ash/focus_cycler.h"
#include "ash/frame/custom_frame_view_ash.h" #include "ash/frame/custom_frame_view_ash.h"
#include "ash/high_contrast/high_contrast_controller.h" #include "ash/high_contrast/high_contrast_controller.h"
...@@ -661,6 +662,7 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate, ...@@ -661,6 +662,7 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
brightness_control_delegate_( brightness_control_delegate_(
std::make_unique<system::BrightnessControllerChromeos>()), std::make_unique<system::BrightnessControllerChromeos>()),
cast_config_(std::make_unique<CastConfigController>()), cast_config_(std::make_unique<CastConfigController>()),
first_run_helper_(std::make_unique<FirstRunHelper>()),
focus_cycler_(std::make_unique<FocusCycler>()), focus_cycler_(std::make_unique<FocusCycler>()),
ime_controller_(std::make_unique<ImeController>()), ime_controller_(std::make_unique<ImeController>()),
immersive_context_(std::make_unique<ImmersiveContextAsh>()), immersive_context_(std::make_unique<ImmersiveContextAsh>()),
......
...@@ -108,6 +108,7 @@ class DockedMagnifierController; ...@@ -108,6 +108,7 @@ class DockedMagnifierController;
class DragDropController; class DragDropController;
class EventClientImpl; class EventClientImpl;
class EventTransformationHandler; class EventTransformationHandler;
class FirstRunHelper;
class FocusCycler; class FocusCycler;
class HighContrastController; class HighContrastController;
class HighlighterController; class HighlighterController;
...@@ -383,6 +384,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -383,6 +384,7 @@ class ASH_EXPORT Shell : public SessionObserver,
EventTransformationHandler* event_transformation_handler() { EventTransformationHandler* event_transformation_handler() {
return event_transformation_handler_.get(); return event_transformation_handler_.get();
} }
FirstRunHelper* first_run_helper() { return first_run_helper_.get(); }
FocusCycler* focus_cycler() { return focus_cycler_.get(); } FocusCycler* focus_cycler() { return focus_cycler_.get(); }
HighlighterController* highlighter_controller() { HighlighterController* highlighter_controller() {
return highlighter_controller_.get(); return highlighter_controller_.get();
...@@ -694,6 +696,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -694,6 +696,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<DetachableBaseNotificationController> std::unique_ptr<DetachableBaseNotificationController>
detachable_base_notification_controller_; detachable_base_notification_controller_;
std::unique_ptr<DragDropController> drag_drop_controller_; std::unique_ptr<DragDropController> drag_drop_controller_;
std::unique_ptr<FirstRunHelper> first_run_helper_;
std::unique_ptr<FocusCycler> focus_cycler_; std::unique_ptr<FocusCycler> focus_cycler_;
std::unique_ptr<ImeController> ime_controller_; std::unique_ptr<ImeController> ime_controller_;
std::unique_ptr<ImmersiveContextAsh> immersive_context_; std::unique_ptr<ImmersiveContextAsh> immersive_context_;
......
...@@ -56,6 +56,10 @@ void SystemTrayTestApi::DisableAnimations(DisableAnimationsCallback cb) { ...@@ -56,6 +56,10 @@ void SystemTrayTestApi::DisableAnimations(DisableAnimationsCallback cb) {
std::move(cb).Run(); std::move(cb).Run();
} }
void SystemTrayTestApi::IsTrayBubbleOpen(IsTrayBubbleOpenCallback cb) {
std::move(cb).Run(tray_->HasSystemBubble());
}
void SystemTrayTestApi::IsTrayViewVisible(int view_id, void SystemTrayTestApi::IsTrayViewVisible(int view_id,
IsTrayViewVisibleCallback cb) { IsTrayViewVisibleCallback cb) {
// Search for the view among the tray icons. // Search for the view among the tray icons.
......
...@@ -43,6 +43,7 @@ class SystemTrayTestApi : public mojom::SystemTrayTestApi { ...@@ -43,6 +43,7 @@ class SystemTrayTestApi : public mojom::SystemTrayTestApi {
// mojom::SystemTrayTestApi: // mojom::SystemTrayTestApi:
void DisableAnimations(DisableAnimationsCallback cb) override; void DisableAnimations(DisableAnimationsCallback cb) override;
void IsTrayBubbleOpen(IsTrayBubbleOpenCallback cb) override;
void IsTrayViewVisible(int view_id, IsTrayViewVisibleCallback cb) override; void IsTrayViewVisible(int view_id, IsTrayViewVisibleCallback cb) override;
void ShowBubble(ShowBubbleCallback cb) override; void ShowBubble(ShowBubbleCallback cb) override;
void ShowDetailedView(mojom::TrayItem item, void ShowDetailedView(mojom::TrayItem item,
......
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/shell.h" #include "ash/public/interfaces/constants.mojom.h"
#include "ash/system/tray/system_tray.h" #include "ash/public/interfaces/system_tray_test_api.mojom.h"
#include "chrome/browser/chromeos/first_run/first_run.h" #include "chrome/browser/chromeos/first_run/first_run.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h" #include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/first_run/step_names.h" #include "chrome/browser/chromeos/first_run/step_names.h"
#include "chrome/browser/chromeos/login/test/js_checker.h" #include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "services/service_manager/public/cpp/connector.h"
namespace chromeos { namespace chromeos {
...@@ -21,6 +23,14 @@ class FirstRunUIBrowserTest : public InProcessBrowserTest, ...@@ -21,6 +23,14 @@ class FirstRunUIBrowserTest : public InProcessBrowserTest,
finalized_(false) { finalized_(false) {
} }
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
// Connect to the ash test interface.
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &tray_test_api_);
}
// FirstRunActor::Delegate overrides. // FirstRunActor::Delegate overrides.
void OnActorInitialized() override { void OnActorInitialized() override {
initialized_ = true; initialized_ = true;
...@@ -104,7 +114,19 @@ class FirstRunUIBrowserTest : public InProcessBrowserTest, ...@@ -104,7 +114,19 @@ class FirstRunUIBrowserTest : public InProcessBrowserTest,
return FirstRunController::GetInstanceForTest(); return FirstRunController::GetInstanceForTest();
} }
bool IsTrayBubbleOpen() {
bool is_open = false;
ash::mojom::SystemTrayTestApiAsyncWaiter wait_for(tray_test_api_.get());
wait_for.IsTrayBubbleOpen(&is_open);
return is_open;
}
void FlushForTesting() {
controller()->first_run_helper_ptr_.FlushForTesting();
}
private: private:
ash::mojom::SystemTrayTestApiPtr tray_test_api_;
std::string current_step_name_; std::string current_step_name_;
bool initialized_; bool initialized_;
bool finalized_; bool finalized_;
...@@ -118,19 +140,24 @@ IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest, FirstRunFlow) { ...@@ -118,19 +140,24 @@ IN_PROC_BROWSER_TEST_F(FirstRunUIBrowserTest, FirstRunFlow) {
LaunchTutorial(); LaunchTutorial();
WaitForInitialization(); WaitForInitialization();
WaitForStep(first_run::kAppListStep); WaitForStep(first_run::kAppListStep);
EXPECT_FALSE(controller()->IsTrayBubbleOpened()); FlushForTesting();
EXPECT_FALSE(IsTrayBubbleOpen());
AdvanceStep(); AdvanceStep();
WaitForStep(first_run::kTrayStep); WaitForStep(first_run::kTrayStep);
EXPECT_TRUE(controller()->IsTrayBubbleOpened()); FlushForTesting();
EXPECT_TRUE(IsTrayBubbleOpen());
AdvanceStep(); AdvanceStep();
WaitForStep(first_run::kHelpStep); WaitForStep(first_run::kHelpStep);
EXPECT_TRUE(controller()->IsTrayBubbleOpened()); FlushForTesting();
EXPECT_TRUE(IsTrayBubbleOpen());
AdvanceStep(); AdvanceStep();
WaitForFinalization(); WaitForFinalization();
content::RunAllPendingInMessageLoop(); content::RunAllPendingInMessageLoop();
EXPECT_EQ(controller(), nullptr); EXPECT_EQ(controller(), nullptr);
// controller() is destructed already, that's why we call Shell directly. EXPECT_FALSE(IsTrayBubbleOpen());
EXPECT_FALSE(ash::Shell::Get()->GetPrimarySystemTray()->HasSystemBubble());
} }
} // namespace chromeos } // namespace chromeos
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include "ash/first_run/first_run_helper.h" #include "ash/first_run/first_run_helper.h"
#include "ash/public/cpp/shelf_prefs.h" #include "ash/public/cpp/shelf_prefs.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/first_run_helper.mojom.h"
#include "ash/shell.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -19,6 +22,8 @@ ...@@ -19,6 +22,8 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -65,30 +70,6 @@ void FirstRunController::Stop() { ...@@ -65,30 +70,6 @@ void FirstRunController::Stop() {
g_first_run_controller_instance = NULL; g_first_run_controller_instance = NULL;
} }
gfx::Rect FirstRunController::GetAppListButtonBounds() const {
return shell_helper_->GetAppListButtonBounds();
}
void FirstRunController::OpenTrayBubble() {
shell_helper_->OpenTrayBubble();
}
void FirstRunController::CloseTrayBubble() {
shell_helper_->CloseTrayBubble();
}
bool FirstRunController::IsTrayBubbleOpened() const {
return shell_helper_->IsTrayBubbleOpened();
}
gfx::Rect FirstRunController::GetTrayBubbleBounds() const {
return shell_helper_->GetTrayBubbleBounds();
}
gfx::Rect FirstRunController::GetHelpButtonBounds() const {
return shell_helper_->GetHelpButtonBounds();
}
gfx::Size FirstRunController::GetOverlaySize() const { gfx::Size FirstRunController::GetOverlaySize() const {
return shell_helper_->GetOverlayWidget()->GetWindowBoundsInScreen().size(); return shell_helper_->GetOverlayWidget()->GetWindowBoundsInScreen().size();
} }
...@@ -116,8 +97,12 @@ void FirstRunController::Init() { ...@@ -116,8 +97,12 @@ void FirstRunController::Init() {
user_profile_ = ProfileHelper::Get()->GetProfileByUserUnsafe( user_profile_ = ProfileHelper::Get()->GetProfileByUserUnsafe(
user_manager->GetActiveUser()); user_manager->GetActiveUser());
shell_helper_ = std::make_unique<ash::FirstRunHelper>(); content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &first_run_helper_ptr_);
shell_helper_ = ash::Shell::Get()->first_run_helper();
shell_helper_->AddObserver(this); shell_helper_->AddObserver(this);
shell_helper_->CreateOverlayWidget();
FirstRunView* view = new FirstRunView(); FirstRunView* view = new FirstRunView();
view->Init(user_profile_); view->Init(user_profile_);
...@@ -146,8 +131,9 @@ void FirstRunController::Finalize() { ...@@ -146,8 +131,9 @@ void FirstRunController::Finalize() {
if (actor_) if (actor_)
actor_->set_delegate(NULL); actor_->set_delegate(NULL);
actor_ = NULL; actor_ = NULL;
shell_helper_->CloseOverlayWidget();
shell_helper_->RemoveObserver(this); shell_helper_->RemoveObserver(this);
shell_helper_.reset(); shell_helper_ = nullptr;
} }
void FirstRunController::OnActorInitialized() { void FirstRunController::OnActorInitialized() {
...@@ -198,9 +184,9 @@ void FirstRunController::OnCancelled() { ...@@ -198,9 +184,9 @@ void FirstRunController::OnCancelled() {
} }
void FirstRunController::RegisterSteps() { void FirstRunController::RegisterSteps() {
steps_.push_back(make_linked_ptr(new first_run::AppListStep(this, actor_))); steps_.push_back(std::make_unique<first_run::AppListStep>(this, actor_));
steps_.push_back(make_linked_ptr(new first_run::TrayStep(this, actor_))); steps_.push_back(std::make_unique<first_run::TrayStep>(this, actor_));
steps_.push_back(make_linked_ptr(new first_run::HelpStep(this, actor_))); steps_.push_back(std::make_unique<first_run::HelpStep>(this, actor_));
} }
void FirstRunController::ShowNextStep() { void FirstRunController::ShowNextStep() {
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "ash/first_run/first_run_helper.h" #include "ash/first_run/first_run_helper.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/interfaces/first_run_helper.mojom.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h" #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"
...@@ -38,8 +38,6 @@ class Step; ...@@ -38,8 +38,6 @@ class Step;
// tutorial. // tutorial.
class FirstRunController : public FirstRunActor::Delegate, class FirstRunController : public FirstRunActor::Delegate,
public ash::FirstRunHelper::Observer { public ash::FirstRunHelper::Observer {
typedef std::vector<linked_ptr<first_run::Step> > Steps;
public: public:
~FirstRunController() override; ~FirstRunController() override;
...@@ -49,30 +47,16 @@ class FirstRunController : public FirstRunActor::Delegate, ...@@ -49,30 +47,16 @@ class FirstRunController : public FirstRunActor::Delegate,
// Finalizes first-run tutorial and destroys UI. // Finalizes first-run tutorial and destroys UI.
static void Stop(); static void Stop();
// Returns bounds of application list button in screen coordinates.
gfx::Rect GetAppListButtonBounds() const;
// Opens and closes system tray bubble.
void OpenTrayBubble();
void CloseTrayBubble();
// Returns |true| iff system tray bubble is opened now.
bool IsTrayBubbleOpened() const;
// Returns bounds of system tray bubble in screen coordinates. The bubble
// must be open.
gfx::Rect GetTrayBubbleBounds() const;
// Returns bounds of help app button from system tray bubble in screen
// coordinates. The bubble must be open.
gfx::Rect GetHelpButtonBounds() const;
// Returns the size of the semi-transparent overlay window in DIPs. // Returns the size of the semi-transparent overlay window in DIPs.
gfx::Size GetOverlaySize() const; gfx::Size GetOverlaySize() const;
// Returns the shelf alignment on the primary display. // Returns the shelf alignment on the primary display.
ash::ShelfAlignment GetShelfAlignment() const; ash::ShelfAlignment GetShelfAlignment() const;
const ash::mojom::FirstRunHelperPtr& first_run_helper_ptr() {
return first_run_helper_ptr_;
}
private: private:
friend class FirstRunUIBrowserTest; friend class FirstRunUIBrowserTest;
...@@ -104,10 +88,14 @@ class FirstRunController : public FirstRunActor::Delegate, ...@@ -104,10 +88,14 @@ class FirstRunController : public FirstRunActor::Delegate,
FirstRunActor* actor_; FirstRunActor* actor_;
// Helper for manipulating and retreiving information from Shell. // Helper for manipulating and retreiving information from Shell.
std::unique_ptr<ash::FirstRunHelper> shell_helper_; // TODO(jamescook): Remove once all methods are converted to mojo.
ash::FirstRunHelper* shell_helper_ = nullptr;
// Mojo interface for manipulating and retrieving information from ash.
ash::mojom::FirstRunHelperPtr first_run_helper_ptr_;
// List of all tutorial steps. // List of all tutorial steps.
Steps steps_; std::vector<std::unique_ptr<first_run::Step>> steps_;
// Index of step that is currently shown. // Index of step that is currently shown.
size_t current_step_index_; size_t current_step_index_;
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "chrome/browser/chromeos/first_run/steps/app_list_step.h" #include "chrome/browser/chromeos/first_run/steps/app_list_step.h"
#include "ash/public/interfaces/first_run_helper.mojom.h"
#include "base/bind.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h" #include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/first_run/step_names.h" #include "chrome/browser/chromeos/first_run/step_names.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h" #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace { namespace {
...@@ -22,8 +25,14 @@ AppListStep::AppListStep(FirstRunController* controller, FirstRunActor* actor) ...@@ -22,8 +25,14 @@ AppListStep::AppListStep(FirstRunController* controller, FirstRunActor* actor)
: Step(kAppListStep, controller, actor) {} : Step(kAppListStep, controller, actor) {}
void AppListStep::DoShow() { void AppListStep::DoShow() {
gfx::Rect button_bounds = first_run_controller()->GetAppListButtonBounds(); // FirstRunController owns this object, so use Unretained.
gfx::Point center = button_bounds.CenterPoint(); first_run_controller()->first_run_helper_ptr()->GetAppListButtonBounds(
base::BindOnce(&AppListStep::ShowWithButtonBounds,
base::Unretained(this)));
}
void AppListStep::ShowWithButtonBounds(const gfx::Rect& screen_bounds) {
gfx::Point center = screen_bounds.CenterPoint();
actor()->AddRoundHole(center.x(), center.y(), kCircleRadius); actor()->AddRoundHole(center.x(), center.y(), kCircleRadius);
actor()->ShowStepPointingTo(name(), center.x(), center.y(), kCircleRadius); actor()->ShowStepPointingTo(name(), center.x(), center.y(), kCircleRadius);
} }
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/first_run/step.h" #include "chrome/browser/chromeos/first_run/step.h"
namespace gfx {
class Rect;
}
namespace chromeos { namespace chromeos {
namespace first_run { namespace first_run {
...@@ -16,9 +20,11 @@ class AppListStep : public Step { ...@@ -16,9 +20,11 @@ class AppListStep : public Step {
AppListStep(FirstRunController* controller, FirstRunActor* actor); AppListStep(FirstRunController* controller, FirstRunActor* actor);
private: private:
// Overriden from Step. // Step:
void DoShow() override; void DoShow() override;
void ShowWithButtonBounds(const gfx::Rect& screen_bounds);
DISALLOW_COPY_AND_ASSIGN(AppListStep); DISALLOW_COPY_AND_ASSIGN(AppListStep);
}; };
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "chrome/browser/chromeos/first_run/steps/help_step.h" #include "chrome/browser/chromeos/first_run/steps/help_step.h"
#include "ash/public/interfaces/first_run_helper.mojom.h"
#include "base/bind.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h" #include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/first_run/step_names.h" #include "chrome/browser/chromeos/first_run/step_names.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h" #include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace { namespace {
...@@ -22,16 +25,22 @@ HelpStep::HelpStep(FirstRunController* controller, FirstRunActor* actor) ...@@ -22,16 +25,22 @@ HelpStep::HelpStep(FirstRunController* controller, FirstRunActor* actor)
: Step(kHelpStep, controller, actor) {} : Step(kHelpStep, controller, actor) {}
void HelpStep::DoShow() { void HelpStep::DoShow() {
if (!first_run_controller()->IsTrayBubbleOpened()) const ash::mojom::FirstRunHelperPtr& helper_ptr =
first_run_controller()->OpenTrayBubble(); first_run_controller()->first_run_helper_ptr();
gfx::Rect button_bounds = first_run_controller()->GetHelpButtonBounds(); helper_ptr->OpenTrayBubble(base::DoNothing());
gfx::Point center = button_bounds.CenterPoint(); // FirstRunController owns |this|, so use Unretained.
actor()->AddRoundHole(center.x(), center.y(), kCircleRadius); helper_ptr->GetHelpButtonBounds(base::BindOnce(
actor()->ShowStepPointingTo(name(), center.x(), center.y(), kCircleRadius); &HelpStep::ShowWithHelpButtonBounds, base::Unretained(this)));
} }
void HelpStep::DoOnAfterHide() { void HelpStep::DoOnAfterHide() {
first_run_controller()->CloseTrayBubble(); first_run_controller()->first_run_helper_ptr()->CloseTrayBubble();
}
void HelpStep::ShowWithHelpButtonBounds(const gfx::Rect& screen_bounds) {
gfx::Point center = screen_bounds.CenterPoint();
actor()->AddRoundHole(center.x(), center.y(), kCircleRadius);
actor()->ShowStepPointingTo(name(), center.x(), center.y(), kCircleRadius);
} }
} // namespace first_run } // namespace first_run
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/first_run/step.h" #include "chrome/browser/chromeos/first_run/step.h"
namespace gfx {
class Rect;
}
namespace chromeos { namespace chromeos {
namespace first_run { namespace first_run {
...@@ -16,10 +20,12 @@ class HelpStep : public Step { ...@@ -16,10 +20,12 @@ class HelpStep : public Step {
HelpStep(FirstRunController* controller, FirstRunActor* actor); HelpStep(FirstRunController* controller, FirstRunActor* actor);
private: private:
// Overriden from Step. // Step:
void DoShow() override; void DoShow() override;
void DoOnAfterHide() override; void DoOnAfterHide() override;
void ShowWithHelpButtonBounds(const gfx::Rect& screen_bounds);
DISALLOW_COPY_AND_ASSIGN(HelpStep); DISALLOW_COPY_AND_ASSIGN(HelpStep);
}; };
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "chrome/browser/chromeos/first_run/steps/tray_step.h" #include "chrome/browser/chromeos/first_run/steps/tray_step.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/interfaces/first_run_helper.mojom.h"
#include "base/bind.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h" #include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/first_run/step_names.h" #include "chrome/browser/chromeos/first_run/step_names.h"
...@@ -19,9 +21,12 @@ TrayStep::TrayStep(FirstRunController* controller, FirstRunActor* actor) ...@@ -19,9 +21,12 @@ TrayStep::TrayStep(FirstRunController* controller, FirstRunActor* actor)
: Step(kTrayStep, controller, actor) {} : Step(kTrayStep, controller, actor) {}
void TrayStep::DoShow() { void TrayStep::DoShow() {
if (!first_run_controller()->IsTrayBubbleOpened()) // FirstRunController owns this object, so use Unretained.
first_run_controller()->OpenTrayBubble(); first_run_controller()->first_run_helper_ptr()->OpenTrayBubble(
gfx::Rect bounds = first_run_controller()->GetTrayBubbleBounds(); base::BindOnce(&TrayStep::ShowWithBubbleBounds, base::Unretained(this)));
}
void TrayStep::ShowWithBubbleBounds(const gfx::Rect& bounds) {
actor()->AddRectangularHole(bounds.x(), bounds.y(), bounds.width(), actor()->AddRectangularHole(bounds.x(), bounds.y(), bounds.width(),
bounds.height()); bounds.height());
FirstRunActor::StepPosition position; FirstRunActor::StepPosition position;
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/first_run/step.h" #include "chrome/browser/chromeos/first_run/step.h"
namespace gfx {
class Rect;
}
namespace chromeos { namespace chromeos {
namespace first_run { namespace first_run {
...@@ -16,9 +20,12 @@ class TrayStep : public Step { ...@@ -16,9 +20,12 @@ class TrayStep : public Step {
TrayStep(FirstRunController* controller, FirstRunActor* actor); TrayStep(FirstRunController* controller, FirstRunActor* actor);
private: private:
// Overriden from Step. // Step:
void DoShow() override; void DoShow() override;
// Shows the step when the bubble bounds are available.
void ShowWithBubbleBounds(const gfx::Rect& screen_bounds);
DISALLOW_COPY_AND_ASSIGN(TrayStep); DISALLOW_COPY_AND_ASSIGN(TrayStep);
}; };
......
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