Skip to content

Commit

Permalink
chromeos: adds AshDisplayController
Browse files Browse the repository at this point in the history
and wires up ChromeConsoleServiceProviderDelegate to use it. I will
get rid of MusConsoleServiceProviderDelegate soon, but can't until
simplified display management is enabled for --mash.

BUG=718860
TEST=none

Change-Id: I055806ab5f85238ad8b69e87143ea4e795fafa07
Reviewed-on: https://chromium-review.googlesource.com/522545
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476881}
  • Loading branch information
Scott Violet authored and Commit Bot committed Jun 3, 2017
1 parent 47dd4cc commit d64dac1
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 35 deletions.
2 changes: 2 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ component("ash") {
"devtools/widget_element.h",
"devtools/window_element.cc",
"devtools/window_element.h",
"display/ash_display_controller.cc",
"display/ash_display_controller.h",
"display/cursor_window_controller.cc",
"display/cursor_window_controller.h",
"display/display_animator.h",
Expand Down
31 changes: 31 additions & 0 deletions ash/display/ash_display_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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/display/ash_display_controller.h"

#include "ash/shell.h"
#include "ui/display/manager/chromeos/display_configurator.h"

namespace ash {

AshDisplayController::AshDisplayController() {}

AshDisplayController::~AshDisplayController() {}

void AshDisplayController::BindRequest(
mojom::AshDisplayControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
}

void AshDisplayController::TakeDisplayControl(
TakeDisplayControlCallback callback) {
Shell::Get()->display_configurator()->TakeControl(std::move(callback));
}

void AshDisplayController::RelinquishDisplayControl(
RelinquishDisplayControlCallback callback) {
Shell::Get()->display_configurator()->RelinquishControl(std::move(callback));
}

} // namespace ash
34 changes: 34 additions & 0 deletions ash/display/ash_display_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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_DISPLAY_ASH_DISPLAY_CONTROLLER_H_
#define ASH_DISPLAY_ASH_DISPLAY_CONTROLLER_H_

#include "ash/public/interfaces/ash_display_controller.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"

namespace ash {

class AshDisplayController : public mojom::AshDisplayController {
public:
AshDisplayController();
~AshDisplayController() override;

void BindRequest(mojom::AshDisplayControllerRequest request);

// mojom::AshDisplayController:
void TakeDisplayControl(TakeDisplayControlCallback callback) override;
void RelinquishDisplayControl(
RelinquishDisplayControlCallback callback) override;

private:
mojo::BindingSet<mojom::AshDisplayController> bindings_;

DISALLOW_COPY_AND_ASSIGN(AshDisplayController);
};

} // namespace ash

#endif // ASH_DISPLAY_ASH_DISPLAY_CONTROLLER_H_
10 changes: 10 additions & 0 deletions ash/mojo_interface_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "ash/accelerators/accelerator_controller.h"
#include "ash/cast_config_controller.h"
#include "ash/display/ash_display_controller.h"
#include "ash/login/lock_screen_controller.h"
#include "ash/media_controller.h"
#include "ash/new_window_controller.h"
Expand Down Expand Up @@ -44,6 +45,12 @@ void BindAppListRequestOnMainThread(
Shell::Get()->app_list()->BindRequest(std::move(request));
}

void BindAshDisplayControllerRequestOnMainThread(
const service_manager::BindSourceInfo& source_info,
mojom::AshDisplayControllerRequest request) {
Shell::Get()->ash_display_controller()->BindRequest(std::move(request));
}

void BindCastConfigOnMainThread(
const service_manager::BindSourceInfo& source_info,
mojom::CastConfigRequest request) {
Expand Down Expand Up @@ -135,6 +142,9 @@ void RegisterInterfaces(
main_thread_task_runner);
registry->AddInterface(base::Bind(&BindAppListRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface(
base::Bind(&BindAshDisplayControllerRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface(base::Bind(&BindCastConfigOnMainThread),
main_thread_task_runner);
registry->AddInterface(
Expand Down
4 changes: 4 additions & 0 deletions ash/mus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"ash::mojom::VpnList",
"ash::mojom::WallpaperController"
],
// Only chrome is allowed to use this (required as dbus runs in Chrome).
"display": [
"ash::mojom::AshDisplayController"
],
"mus:window_manager": [ "ui::mojom::AcceleratorRegistrar" ]
},
"requires": {
Expand Down
1 change: 1 addition & 0 deletions ash/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mojom("interfaces_internal") {

sources = [
"accelerator_controller.mojom",
"ash_display_controller.mojom",
"cast_config.mojom",
"constants.mojom",
"event_properties.mojom",
Expand Down
18 changes: 18 additions & 0 deletions ash/public/interfaces/ash_display_controller.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016 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;

// Allows configuring various display related state.
interface AshDisplayController {
// ============================ Virtual Terminal ============================

// Take control of all display output. This is called when switching from the
// virtual terminal back to Chrome in response to a dbus message.
TakeDisplayControl() => (bool status);

// Relinquish control of all display output. This is called when switching
// from Chrome to the virtual terminal in response to a dbus message.
RelinquishDisplayControl() => (bool status);
};
2 changes: 2 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ash/cast_config_controller.h"
#include "ash/devtools/ash_devtools_css_agent.h"
#include "ash/devtools/ash_devtools_dom_agent.h"
#include "ash/display/ash_display_controller.h"
#include "ash/display/cursor_window_controller.h"
#include "ash/display/display_color_manager_chromeos.h"
#include "ash/display/display_configuration_controller.h"
Expand Down Expand Up @@ -548,6 +549,7 @@ void Shell::SetIsBrowserProcessWithMash() {
Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
std::unique_ptr<ShellPort> shell_port)
: shell_port_(std::move(shell_port)),
ash_display_controller_(base::MakeUnique<AshDisplayController>()),
brightness_control_delegate_(
base::MakeUnique<system::BrightnessControllerChromeos>()),
cast_config_(base::MakeUnique<CastConfigController>()),
Expand Down
5 changes: 5 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace ash {

class AcceleratorController;
class AccessibilityDelegate;
class AshDisplayController;
class AppListDelegateImpl;
class AshNativeCursorManager;
class AshTouchTransformController;
Expand Down Expand Up @@ -303,6 +304,9 @@ class ASH_EXPORT Shell : public SessionObserver,
return accessibility_delegate_.get();
}
app_list::AppList* app_list() { return app_list_.get(); }
AshDisplayController* ash_display_controller() {
return ash_display_controller_.get();
}
const scoped_refptr<base::SequencedWorkerPool>& blocking_pool() {
return blocking_pool_;
}
Expand Down Expand Up @@ -679,6 +683,7 @@ class ASH_EXPORT Shell : public SessionObserver,

std::unique_ptr<AcceleratorController> accelerator_controller_;
std::unique_ptr<AccessibilityDelegate> accessibility_delegate_;
std::unique_ptr<AshDisplayController> ash_display_controller_;
std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate_;
std::unique_ptr<CastConfigController> cast_config_;
std::unique_ptr<DragDropController> drag_drop_controller_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"requires": {
"accessibility_autoclick": [ "ash:autoclick" ],
"ash": [ "ash" ],
"ash": [ "ash", "display" ],
"device": [ "device:fingerprint" ],
"identity": [ "identity_manager" ],
"nacl_broker": [ "browser" ],
Expand Down
23 changes: 22 additions & 1 deletion chrome/browser/chromeos/chrome_browser_main_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/service_manager_connection.h"
#include "crypto/nss_util_internal.h"
#include "crypto/scoped_nss_types.h"
#include "dbus/object_path.h"
Expand Down Expand Up @@ -297,8 +298,13 @@ class DBusServices {
// TODO(sky): once mash supports simplified display mode we should always
// use ChromeConsoleServiceProviderDelegate.
if (GetAshConfig() != ash::Config::MASH) {
std::unique_ptr<ChromeConsoleServiceProviderDelegate>
console_service_provider_delegate =
base::MakeUnique<ChromeConsoleServiceProviderDelegate>();
console_service_provider_delegate_ =
console_service_provider_delegate->AsWeakPtr();
service_providers.push_back(base::MakeUnique<ConsoleServiceProvider>(
base::MakeUnique<ChromeConsoleServiceProviderDelegate>()));
std::move(console_service_provider_delegate)));
} else {
service_providers.push_back(base::MakeUnique<ConsoleServiceProvider>(
base::MakeUnique<MusConsoleServiceProviderDelegate>()));
Expand Down Expand Up @@ -394,6 +400,12 @@ class DBusServices {
DBusThreadManager::Shutdown();
}

void ServiceManagerConnectionStarted(
content::ServiceManagerConnection* connection) {
if (console_service_provider_delegate_)
console_service_provider_delegate_->Connect(connection->GetConnector());
}

private:
// Hosts providers for the "org.chromium.LibCrosService" D-Bus service owned
// by Chrome. The name of this service was chosen for historical reasons that
Expand All @@ -408,6 +420,9 @@ class DBusServices {

std::unique_ptr<NetworkConnectDelegateChromeOS> network_connect_delegate_;

base::WeakPtr<ChromeConsoleServiceProviderDelegate>
console_service_provider_delegate_;

DISALLOW_COPY_AND_ASSIGN(DBusServices);
};

Expand Down Expand Up @@ -583,6 +598,12 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() {
ChromeBrowserMainPartsLinux::PostMainMessageLoopStart();
}

void ChromeBrowserMainPartsChromeos::ServiceManagerConnectionStarted(
content::ServiceManagerConnection* connection) {
ChromeBrowserMainPartsLinux::ServiceManagerConnectionStarted(connection);
dbus_services_->ServiceManagerConnectionStarted(connection);
}

// Threads are initialized between MainMessageLoopStart and MainMessageLoopRun.
// about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads.
void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() {
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/chrome_browser_main_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux {
void PreEarlyInitialization() override;
void PreMainMessageLoopStart() override;
void PostMainMessageLoopStart() override;
void ServiceManagerConnectionStarted(
content::ServiceManagerConnection* connection) override;
void PreMainMessageLoopRun() override;

// Stages called from PreMainMessageLoopRun.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,38 @@

#include "chrome/browser/chromeos/dbus/chrome_console_service_provider_delegate.h"

#include "ash/public/interfaces/constants.mojom.h"
#include "ash/shell.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/display/manager/chromeos/display_configurator.h"

namespace chromeos {

ChromeConsoleServiceProviderDelegate::ChromeConsoleServiceProviderDelegate() {
}
ChromeConsoleServiceProviderDelegate::ChromeConsoleServiceProviderDelegate() {}

ChromeConsoleServiceProviderDelegate::~ChromeConsoleServiceProviderDelegate() {}

ChromeConsoleServiceProviderDelegate::~ChromeConsoleServiceProviderDelegate() {
void ChromeConsoleServiceProviderDelegate::Connect(
service_manager::Connector* connector) {
connector->BindInterface(ash::mojom::kServiceName, &ash_display_controller_);
}

void ChromeConsoleServiceProviderDelegate::TakeDisplayOwnership(
const UpdateOwnershipCallback& callback) {
ash::Shell::Get()->display_configurator()->TakeControl(callback);
if (!ash_display_controller_) {
callback.Run(false);
return;
}
ash_display_controller_->TakeDisplayControl(callback);
}

void ChromeConsoleServiceProviderDelegate::ReleaseDisplayOwnership(
const UpdateOwnershipCallback& callback) {
ash::Shell::Get()->display_configurator()->RelinquishControl(callback);
if (!ash_display_controller_) {
callback.Run(false);
return;
}
ash_display_controller_->RelinquishDisplayControl(callback);
}

} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@
#ifndef CHROME_BROWSER_CHROMEOS_DBUS_CHROME_CONSOLE_SERVICE_PROVIDER_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_DBUS_CHROME_CONSOLE_SERVICE_PROVIDER_DELEGATE_H_

#include "ash/public/interfaces/ash_display_controller.mojom.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/dbus/services/console_service_provider.h"

namespace service_manager {
class Connector;
}

namespace chromeos {

// Chrome's implementation of ConsoleServiceProvider::Delegate
class ChromeConsoleServiceProviderDelegate
: public ConsoleServiceProvider::Delegate {
: public ConsoleServiceProvider::Delegate,
public base::SupportsWeakPtr<ChromeConsoleServiceProviderDelegate> {
public:
ChromeConsoleServiceProviderDelegate();
~ChromeConsoleServiceProviderDelegate() override;

void Connect(service_manager::Connector* connector);

// ConsoleServiceProvider::Delegate overrides:
void TakeDisplayOwnership(const UpdateOwnershipCallback& callback) override;
void ReleaseDisplayOwnership(
const UpdateOwnershipCallback& callback) override;

private:
ash::mojom::AshDisplayControllerPtr ash_display_controller_;

DISALLOW_COPY_AND_ASSIGN(ChromeConsoleServiceProviderDelegate);
};

Expand Down
2 changes: 1 addition & 1 deletion content/public/app/mojo/content_browser_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"requires": {
"*": [ "app" ],
// In classic ash, the browser supplies ash interfaces to itself.
"content_browser": [ "ash", "memory_instrumentation" ],
"content_browser": [ "ash", "display", "memory_instrumentation" ],
"content_gpu": [ "browser" ],
"content_plugin": [ "browser" ],
"content_renderer": [ "browser" ],
Expand Down
Loading

0 comments on commit d64dac1

Please sign in to comment.