Skip to content

Commit

Permalink
Inject GPUDataManager support into ash to abstract a content dependency.
Browse files Browse the repository at this point in the history
http://crbug.com/332504

R=oshima@chromium.org

Review URL: https://codereview.chromium.org/138223004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245010 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Jan 15, 2014
1 parent 9ac9a8e commit ac12ae9
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 23 deletions.
3 changes: 0 additions & 3 deletions ash/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ include_rules = [
"+net",
"+ui",
"+win8",

# Used by shell.cc, accelerator_controller.cc, tray_monitor.h
"+content/public/browser/gpu_data_manager.h",
]
4 changes: 2 additions & 2 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/focus_cycler.h"
#include "ash/gpu_support.h"
#include "ash/ime_control_delegate.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/magnifier/partial_magnification_controller.h"
Expand Down Expand Up @@ -55,7 +56,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/metrics/user_metrics.h"
#include "content/public/browser/gpu_data_manager.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/base/accelerators/accelerator.h"
Expand Down Expand Up @@ -968,7 +968,7 @@ bool AcceleratorController::PerformAction(int action,
case TOUCH_HUD_PROJECTION_TOGGLE:
return HandleTouchHudProjectToggle();
case DISABLE_GPU_WATCHDOG:
content::GpuDataManager::GetInstance()->DisableGpuWatchdog();
Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
return true;
#endif // OS_CHROMEOS
case OPEN_FEEDBACK_PAGE:
Expand Down
7 changes: 6 additions & 1 deletion ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
'first_run/first_run_helper_impl.h',
'focus_cycler.cc',
'focus_cycler.h',
'gpu_support.h',
'high_contrast/high_contrast_controller.cc',
'high_contrast/high_contrast_controller.h',
'host/root_window_host_factory.cc',
Expand Down Expand Up @@ -679,7 +680,11 @@
'ASH_WITH_CONTENT_IMPLEMENTATION',
],
'sources': [
'ash_with_content_export.h',
'content_support/ash_with_content_export.h',
'content_support/inject.cc',
'content_support/inject.h',
'content_support/gpu_support_impl.cc',
'content_support/gpu_support_impl.h',
'screensaver/screensaver_view.cc',
'screensaver/screensaver_view.h',
'keyboard_overlay/keyboard_overlay_delegate.cc',
Expand Down
5 changes: 5 additions & 0 deletions ash/content_support/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_rules = [
# TODO(beng): It may make sense to have a broad permit of content/public
# in this file, but I'm starting out conservative.
"+content/public/browser/gpu_data_manager.h",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_ASH_WITH_CONTENT_EXPORT_H_
#define ASH_ASH_WITH_CONTENT_EXPORT_H_
#ifndef ASH_CONTENT_SUPPORT_ASH_WITH_CONTENT_EXPORT_H_
#define ASH_CONTENT_SUPPORT_ASH_WITH_CONTENT_EXPORT_H_

// Defines ASH_EXPORT so that functionality implemented by the Ash module can
// be exported to consumers.
Expand All @@ -29,4 +29,4 @@
#define ASH_WITH_CONTENT_EXPORT
#endif

#endif // ASH_ASH_WITH_CONTENT_EXPORT_H_
#endif // ASH_CONTENT_SUPPORT_ASH_WITH_CONTENT_EXPORT_H_
32 changes: 32 additions & 0 deletions ash/content_support/gpu_support_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2014 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/content_support/gpu_support_impl.h"

#include "content/public/browser/gpu_data_manager.h"
#include "gpu/config/gpu_feature_type.h"

namespace ash {

GPUSupportImpl::GPUSupportImpl() {
}

GPUSupportImpl::~GPUSupportImpl() {
}

bool GPUSupportImpl::IsPanelFittingDisabled() const {
return content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
gpu::GPU_FEATURE_TYPE_PANEL_FITTING);
}

void GPUSupportImpl::DisableGpuWatchdog() {
content::GpuDataManager::GetInstance()->DisableGpuWatchdog();
}

void GPUSupportImpl::GetGpuProcessHandles(
const GetGpuProcessHandlesCallback& callback) const {
content::GpuDataManager::GetInstance()->GetGpuProcessHandles(callback);
}

} // namespace ash
29 changes: 29 additions & 0 deletions ash/content_support/gpu_support_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2014 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_CONTENT_SUPPORT_GPU_SUPPORT_IMPL_H_
#define ASH_CONTENT_SUPPORT_GPU_SUPPORT_IMPL_H_

#include "ash/gpu_support.h"

namespace ash {

class GPUSupportImpl : public GPUSupport {
public:
GPUSupportImpl();
virtual ~GPUSupportImpl();

private:
// Overridden from GPUSupport:
virtual bool IsPanelFittingDisabled() const OVERRIDE;
virtual void DisableGpuWatchdog() OVERRIDE;
virtual void GetGpuProcessHandles(
const GetGpuProcessHandlesCallback& callback) const OVERRIDE;

DISALLOW_COPY_AND_ASSIGN(GPUSupportImpl);
};

} // namespace ash

#endif // ASH_CONTENT_SUPPORT_GPU_SUPPORT_IMPL_H_
17 changes: 17 additions & 0 deletions ash/content_support/inject.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2014 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/content_support/inject.h"

#include "ash/content_support/gpu_support_impl.h"
#include "ash/shell.h"

namespace ash {

void InitContentSupport() {
scoped_ptr<GPUSupportImpl> gpu_support(new GPUSupportImpl);
Shell::GetInstance()->SetGPUSupport(gpu_support.Pass());
}

} // namespace ash
16 changes: 16 additions & 0 deletions ash/content_support/inject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2014 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_CONTENT_SUPPORT_INJECT_H_
#define ASH_CONTENT_SUPPORT_INJECT_H_

#include "ash/content_support/ash_with_content_export.h"

namespace ash {

ASH_WITH_CONTENT_EXPORT void InitContentSupport();

} // namespace ash

#endif // ASH_CONTENT_SUPPORT_INJECT_H_
34 changes: 34 additions & 0 deletions ash/gpu_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2014 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_GPU_SUPPORT_H_
#define ASH_GPU_SUPPORT_H_

#include <list>

#include "base/callback_forward.h"
#include "base/process/process.h"

namespace ash {

// An interface to allow use of content::GpuDataManager to be injected in
// configurations that permit a dependency on content.
class GPUSupport {
public:
typedef base::Callback<void(const std::list<base::ProcessHandle>&)>
GetGpuProcessHandlesCallback;

virtual ~GPUSupport() {}

virtual bool IsPanelFittingDisabled() const = 0;

virtual void DisableGpuWatchdog() = 0;

virtual void GetGpuProcessHandles(
const GetGpuProcessHandlesCallback& callback) const = 0;
};

} // namespace ash

#endif // ASH_GPU_SUPPORT_H_
2 changes: 1 addition & 1 deletion ash/keyboard_overlay/keyboard_overlay_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_
#define ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_

#include "ash/ash_with_content_export.h"
#include "ash/content_support/ash_with_content_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/keyboard_overlay/keyboard_overlay_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <vector>

#include "ash/ash_with_content_export.h"
#include "ash/content_support/ash_with_content_export.h"
#include "ash/wm/overlay_event_filter.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/screensaver/screensaver_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ASH_SCREENSAVER_SCREENSAVER_VIEW_H_
#define ASH_SCREENSAVER_SCREENSAVER_VIEW_H_

#include "ash/ash_with_content_export.h"
#include "ash/content_support/ash_with_content_export.h"
#include "base/callback.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/views/widget/widget_delegate.h"
Expand Down
33 changes: 25 additions & 8 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/first_run/first_run_helper_impl.h"
#include "ash/focus_cycler.h"
#include "ash/gpu_support.h"
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/host/root_window_host_factory.h"
#include "ash/keyboard_uma_event_filter.h"
Expand Down Expand Up @@ -125,8 +126,6 @@
#include "base/message_loop/message_pump_x11.h"
#include "base/sys_info.h"
#include "chromeos/display/output_configurator.h"
#include "content/public/browser/gpu_data_manager.h"
#include "gpu/config/gpu_feature_type.h"
#endif // defined(USE_X11)
#include "ash/sticky_keys/sticky_keys_controller.h"
#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
Expand Down Expand Up @@ -161,6 +160,23 @@ class AshVisibilityController : public views::corewm::VisibilityController {
DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
};

class DefaultGPUSupportImpl : public GPUSupport {
public:
DefaultGPUSupportImpl() {}
virtual ~DefaultGPUSupportImpl() {}

private:
// Overridden from GPUSupport:
virtual bool IsPanelFittingDisabled() const OVERRIDE {
return false;
}
virtual void DisableGpuWatchdog() OVERRIDE {}
virtual void GetGpuProcessHandles(
const GetGpuProcessHandlesCallback& callback) const OVERRIDE {}

DISALLOW_COPY_AND_ASSIGN(DefaultGPUSupportImpl);
};

} // namespace

// static
Expand Down Expand Up @@ -545,6 +561,10 @@ void Shell::DoInitialWorkspaceAnimation() {
DoInitialAnimation();
}

void Shell::SetGPUSupport(scoped_ptr<GPUSupport> gpu_support) {
gpu_support_ = gpu_support.Pass();
}

////////////////////////////////////////////////////////////////////////////////
// Shell, private:

Expand All @@ -562,7 +582,8 @@ Shell::Shell(ShellDelegate* delegate)
cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>(
native_cursor_manager_)),
simulate_modal_window_open_for_testing_(false),
is_touch_hud_projection_enabled_(false) {
is_touch_hud_projection_enabled_(false),
gpu_support_(new DefaultGPUSupportImpl) {
DCHECK(delegate_.get());
display_manager_.reset(new internal::DisplayManager);

Expand All @@ -572,11 +593,7 @@ Shell::Shell(ShellDelegate* delegate)
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_);
display_controller_.reset(new DisplayController);
#if defined(OS_CHROMEOS) && defined(USE_X11)
bool is_panel_fitting_disabled =
content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
gpu::GPU_FEATURE_TYPE_PANEL_FITTING);

output_configurator_->Init(!is_panel_fitting_disabled);
output_configurator_->Init(!gpu_support_->IsPanelFittingDisabled());
user_metrics_recorder_.reset(new UserMetricsRecorder);

base::MessagePumpX11::Current()->AddDispatcherForRootWindow(
Expand Down
7 changes: 7 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CapsLockDelegate;
class DesktopBackgroundController;
class DisplayController;
class FirstRunHelper;
class GPUSupport;
class HighContrastController;
class LockStateController;
class MagnificationController;
Expand Down Expand Up @@ -535,6 +536,9 @@ class ASH_EXPORT Shell
}
#endif // defined(OS_CHROMEOS)

GPUSupport* gpu_support() { return gpu_support_.get(); }
void SetGPUSupport(scoped_ptr<GPUSupport> gpu_support);

private:
FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
Expand Down Expand Up @@ -707,6 +711,9 @@ class ASH_EXPORT Shell

bool is_touch_hud_projection_enabled_;

// Injected content::GPUDataManager support.
scoped_ptr<GPUSupport> gpu_support_;

DISALLOW_COPY_AND_ASSIGN(Shell);
};

Expand Down
2 changes: 2 additions & 0 deletions ash/shell/content_client/shell_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/shell/content_client/shell_browser_main_parts.h"

#include "ash/ash_switches.h"
#include "ash/content_support/inject.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/shell.h"
#include "ash/shell/shell_delegate_impl.h"
Expand Down Expand Up @@ -123,6 +124,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
#endif

ash::Shell::CreateInstance(delegate_);
ash::InitContentSupport();
delegate_->set_browser_context(browser_context_.get());
ash::Shell::GetInstance()->CreateShelf();
ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
Expand Down
7 changes: 4 additions & 3 deletions ash/system/monitor/tray_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "ash/system/monitor/tray_monitor.h"

#include "ash/gpu_support.h"
#include "ash/shell.h"
#include "ash/system/tray/tray_item_view.h"
#include "base/process/memory.h"
#include "base/process/process_metrics.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/gpu_data_manager.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
Expand Down Expand Up @@ -53,10 +54,10 @@ void TrayMonitor::DestroyTrayView() {
}

void TrayMonitor::OnTimer() {
content::GpuDataManager::GetGpuProcessHandlesCallback callback =
GPUSupport::GetGpuProcessHandlesCallback callback =
base::Bind(&TrayMonitor::OnGotHandles, base::Unretained(this));
refresh_timer_.Stop();
content::GpuDataManager::GetInstance()->GetGpuProcessHandles(callback);
Shell::GetInstance()->gpu_support()->GetGpuProcessHandles(callback);
}

void TrayMonitor::OnGotHandles(const std::list<base::ProcessHandle>& handles) {
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/ash/ash_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/accelerators/accelerator_controller.h"
#include "ash/ash_switches.h"
#include "ash/content_support/inject.h"
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/magnifier/partial_magnification_controller.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ void OpenAsh() {

// Shell takes ownership of ChromeShellDelegate.
ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate);
ash::InitContentSupport();
shell->event_rewriter_filter()->SetEventRewriterDelegate(
scoped_ptr<ash::EventRewriterDelegate>(new EventRewriter).Pass());
shell->accelerator_controller()->SetScreenshotDelegate(
Expand Down

0 comments on commit ac12ae9

Please sign in to comment.