Fix some lint errors in url_request_context_adapter
[chromium-blink-merge.git] / athena / main / athena_launcher.cc
blob77bf29ea58a157c69a51a9f664bdd6c7f5820e4e
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 "athena/main/public/athena_launcher.h"
7 #include "athena/activity/public/activity_factory.h"
8 #include "athena/activity/public/activity_manager.h"
9 #include "athena/content/public/app_registry.h"
10 #include "athena/content/public/content_activity_factory_creator.h"
11 #include "athena/env/public/athena_env.h"
12 #include "athena/extensions/public/apps_search_controller_factory.h"
13 #include "athena/extensions/public/extension_app_model_builder.h"
14 #include "athena/extensions/public/extensions_delegate.h"
15 #include "athena/home/public/home_card.h"
16 #include "athena/home/public/search_controller_factory.h"
17 #include "athena/input/public/input_manager.h"
18 #include "athena/main/athena_views_delegate.h"
19 #include "athena/main/placeholder.h"
20 #include "athena/main/placeholder.h"
21 #include "athena/resource_manager/public/resource_manager.h"
22 #include "athena/screen/public/screen_manager.h"
23 #include "athena/system/public/system_ui.h"
24 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
25 #include "athena/wm/public/window_manager.h"
26 #include "base/command_line.h"
27 #include "base/memory/scoped_ptr.h"
28 #include "content/public/common/content_switches.h"
29 #include "ui/app_list/app_list_switches.h"
30 #include "ui/aura/window_property.h"
31 #include "ui/aura/window_tree_host.h"
32 #include "ui/keyboard/keyboard_controller.h"
33 #include "ui/keyboard/keyboard_controller_observer.h"
34 #include "ui/native_theme/native_theme_switches.h"
35 #include "ui/wm/core/visibility_controller.h"
37 #if defined(USE_X11)
38 #include "ui/events/x/touch_factory_x11.h"
39 #endif
41 namespace athena {
42 struct AthenaEnvState;
45 DECLARE_WINDOW_PROPERTY_TYPE(athena::AthenaEnvState*);
47 namespace athena {
49 namespace {
51 bool session_started = false;
53 } // namespace
55 class VirtualKeyboardObserver;
57 // Athena's env state.
58 struct AthenaEnvState {
59 scoped_ptr< ::wm::VisibilityController> visibility_client;
60 scoped_ptr<VirtualKeyboardObserver> virtual_keyboard_observer;
63 DEFINE_OWNED_WINDOW_PROPERTY_KEY(athena::AthenaEnvState,
64 kAthenaEnvStateKey,
65 NULL);
67 // This class observes the change of the virtual keyboard and distribute the
68 // change to appropriate modules of athena.
69 // TODO(oshima): move the VK bounds logic to screen manager.
70 class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver {
71 public:
72 VirtualKeyboardObserver() {
73 keyboard::KeyboardController::GetInstance()->AddObserver(this);
76 virtual ~VirtualKeyboardObserver() {
77 keyboard::KeyboardController::GetInstance()->RemoveObserver(this);
80 private:
81 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override {
82 HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds);
85 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver);
88 void StartAthenaEnv(scoped_refptr<base::TaskRunner> blocking_task_runner) {
89 athena::AthenaEnv::Create();
91 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
93 // Force showing in the experimental app-list view.
94 command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList);
95 command_line->AppendSwitch(switches::kEnableOverlayScrollbar);
97 // Enable vertical overscroll.
98 command_line->AppendSwitchASCII(switches::kScrollEndEffect, "1");
100 #if defined(USE_X11)
101 ui::TouchFactory::SetTouchDeviceListFromCommandLine();
102 #endif
104 CreateAthenaViewsDelegate();
106 AthenaEnvState* env_state = new AthenaEnvState;
108 // Setup VisibilityClient
109 env_state->visibility_client.reset(new ::wm::VisibilityController);
110 aura::Window* root_window = athena::AthenaEnv::Get()->GetHost()->window();
112 aura::client::SetVisibilityClient(root_window,
113 env_state->visibility_client.get());
115 athena::InputManager::Create()->OnRootWindowCreated(root_window);
116 athena::ScreenManager::Create(root_window);
117 athena::SystemUI::Create(blocking_task_runner);
118 athena::WindowManager::Create();
119 athena::AppRegistry::Create();
120 SetupBackgroundImage();
122 athena::ScreenManager::Get()->GetContext()->SetProperty(
123 kAthenaEnvStateKey, env_state);
126 void CreateVirtualKeyboardWithContext(content::BrowserContext* context) {
127 athena::VirtualKeyboardManager::Create(context);
130 void StartAthenaSessionWithContext(content::BrowserContext* context) {
131 athena::ExtensionsDelegate::CreateExtensionsDelegate(context);
132 StartAthenaSession(
133 athena::CreateContentActivityFactory(),
134 make_scoped_ptr(new athena::ExtensionAppModelBuilder(context)),
135 athena::CreateSearchControllerFactory(context));
136 AthenaEnvState* env_state =
137 athena::ScreenManager::Get()->GetContext()->GetProperty(
138 kAthenaEnvStateKey);
140 env_state->virtual_keyboard_observer.reset(new VirtualKeyboardObserver);
141 CreateTestPages(context);
144 void StartAthenaSession(
145 athena::ActivityFactory* activity_factory,
146 scoped_ptr<athena::AppModelBuilder> app_model_builder,
147 scoped_ptr<athena::SearchControllerFactory> search_factory) {
148 DCHECK(!session_started);
149 session_started = true;
150 athena::HomeCard::Create(app_model_builder.Pass(), search_factory.Pass());
151 athena::ActivityManager::Create();
152 athena::ResourceManager::Create();
153 athena::ActivityFactory::RegisterActivityFactory(activity_factory);
156 void ShutdownAthena() {
157 if (session_started) {
158 athena::ActivityFactory::Shutdown();
159 athena::ResourceManager::Shutdown();
160 athena::ActivityManager::Shutdown();
161 athena::HomeCard::Shutdown();
162 athena::ExtensionsDelegate::Shutdown();
163 session_started = false;
165 athena::AppRegistry::ShutDown();
166 athena::WindowManager::Shutdown();
167 athena::SystemUI::Shutdown();
168 athena::ScreenManager::Shutdown();
169 athena::InputManager::Shutdown();
170 athena::AthenaEnv::Shutdown();
172 ShutdownAthenaViewsDelegate();
175 } // namespace athena