Evict resources from resource pool after timeout
[chromium-blink-merge.git] / ui / views_content_client / views_content_client_main_parts_chromeos.cc
blobdc4162bb40abc2af5a07a1a1d925c590ee4df9df
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/context_factory.h"
6 #include "content/shell/browser/shell_browser_context.h"
7 #include "ui/aura/test/test_screen.h"
8 #include "ui/aura/window.h"
9 #include "ui/gfx/screen.h"
10 #include "ui/views_content_client/views_content_client.h"
11 #include "ui/views_content_client/views_content_client_main_parts_aura.h"
12 #include "ui/wm/core/nested_accelerator_controller.h"
13 #include "ui/wm/core/nested_accelerator_delegate.h"
14 #include "ui/wm/test/wm_test_helper.h"
16 namespace ui {
18 namespace {
20 // A dummy version of the delegate usually provided by the Ash Shell.
21 class NestedAcceleratorDelegate : public ::wm::NestedAcceleratorDelegate {
22 public:
23 NestedAcceleratorDelegate() {}
24 ~NestedAcceleratorDelegate() override {}
26 // ::wm::NestedAcceleratorDelegate:
27 Result ProcessAccelerator(const ui::Accelerator& accelerator) override {
28 return RESULT_NOT_PROCESSED;
31 private:
32 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDelegate);
35 class ViewsContentClientMainPartsChromeOS
36 : public ViewsContentClientMainPartsAura {
37 public:
38 ViewsContentClientMainPartsChromeOS(
39 const content::MainFunctionParams& content_params,
40 ViewsContentClient* views_content_client);
41 ~ViewsContentClientMainPartsChromeOS() override {}
43 // content::BrowserMainParts:
44 void PreMainMessageLoopRun() override;
45 void PostMainMessageLoopRun() override;
47 private:
48 // Enable a minimal set of views::corewm to be initialized.
49 scoped_ptr<gfx::Screen> test_screen_;
50 scoped_ptr< ::wm::WMTestHelper> wm_test_helper_;
51 scoped_ptr< ::wm::NestedAcceleratorController> nested_accelerator_controller_;
53 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsChromeOS);
56 ViewsContentClientMainPartsChromeOS::ViewsContentClientMainPartsChromeOS(
57 const content::MainFunctionParams& content_params,
58 ViewsContentClient* views_content_client)
59 : ViewsContentClientMainPartsAura(content_params, views_content_client) {
62 void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() {
63 ViewsContentClientMainPartsAura::PreMainMessageLoopRun();
65 gfx::Size host_size(800, 600);
66 test_screen_.reset(aura::TestScreen::Create(host_size));
67 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
68 // Set up basic pieces of views::corewm.
69 wm_test_helper_.reset(
70 new ::wm::WMTestHelper(host_size, content::GetContextFactory()));
71 // Ensure the X window gets mapped.
72 wm_test_helper_->host()->Show();
74 // Ensure Aura knows where to open new windows.
75 aura::Window* root_window = wm_test_helper_->host()->window();
76 views_content_client()->task().Run(browser_context(), root_window);
78 nested_accelerator_controller_.reset(
79 new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate));
80 aura::client::SetDispatcherClient(root_window,
81 nested_accelerator_controller_.get());
84 void ViewsContentClientMainPartsChromeOS::PostMainMessageLoopRun() {
85 aura::client::SetDispatcherClient(wm_test_helper_->host()->window(), NULL);
86 nested_accelerator_controller_.reset();
87 wm_test_helper_.reset();
88 test_screen_.reset();
90 ViewsContentClientMainPartsAura::PostMainMessageLoopRun();
93 } // namespace
95 // static
96 ViewsContentClientMainParts* ViewsContentClientMainParts::Create(
97 const content::MainFunctionParams& content_params,
98 ViewsContentClient* views_content_client) {
99 return new ViewsContentClientMainPartsChromeOS(
100 content_params, views_content_client);
103 } // namespace ui