[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / ash / chrome_browser_main_extra_parts_ash.cc
blob87a0b739ea4e59ce00bdd854f957f62166d4e10c
1 // Copyright (c) 2012 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 "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/session/session_state_delegate.h"
9 #include "ash/shell.h"
10 #include "base/command_line.h"
11 #include "base/lazy_instance.h"
12 #include "chrome/browser/chrome_browser_main.h"
13 #include "chrome/browser/ui/ash/ash_init.h"
14 #include "chrome/browser/ui/ash/ash_util.h"
15 #include "chrome/browser/ui/views/ash/tab_scrubber.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "ui/aura/env.h"
18 #include "ui/gfx/screen.h"
19 #include "ui/gfx/screen_type_delegate.h"
20 #include "ui/keyboard/keyboard.h"
21 #include "ui/keyboard/keyboard_controller.h"
22 #include "ui/keyboard/keyboard_util.h"
24 #if defined(OS_CHROMEOS)
25 #include "chrome/browser/ui/views/select_file_dialog_extension.h"
26 #include "chrome/browser/ui/views/select_file_dialog_extension_factory.h"
27 #endif
29 #if !defined(OS_CHROMEOS)
30 #include "ui/shell_dialogs/select_file_dialog.h"
31 #include "ui/shell_dialogs/shell_dialogs_delegate.h"
32 #endif
34 #if !defined(OS_CHROMEOS)
35 class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate {
36 public:
37 ScreenTypeDelegateWin() {}
38 virtual gfx::ScreenType GetScreenTypeForNativeView(
39 gfx::NativeView view) OVERRIDE {
40 return chrome::IsNativeViewInAsh(view) ?
41 gfx::SCREEN_TYPE_ALTERNATE :
42 gfx::SCREEN_TYPE_NATIVE;
44 private:
45 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin);
48 class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate {
49 public:
50 ShellDialogsDelegateWin() {}
51 virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE {
52 return chrome::IsNativeViewInAsh(window);
54 private:
55 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin);
58 base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate;
60 #endif
62 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
65 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
68 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
69 if (chrome::ShouldOpenAshOnStartup()) {
70 chrome::OpenAsh(gfx::kNullAcceleratedWidget);
72 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
73 ash::Shell::GetInstance()->CreateShelf();
74 ash::Shell::GetInstance()->ShowShelf();
75 #endif
76 } else {
77 #if !defined(OS_CHROMEOS)
78 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin);
79 ui::SelectFileDialog::SetShellDialogsDelegate(
80 g_shell_dialogs_delegate.Pointer());
81 #endif
83 #if defined(OS_CHROMEOS)
84 // For OS_CHROMEOS, virtual keyboard needs to be initialized before profile
85 // initialized. Otherwise, virtual keyboard extension will not load at login
86 // screen.
87 keyboard::InitializeKeyboard();
88 #endif
90 #if defined(OS_CHROMEOS)
91 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
92 #endif
95 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
96 if (!ash::Shell::HasInstance())
97 return;
99 // Initialize TabScrubber after the Ash Shell has been initialized.
100 TabScrubber::GetInstance();
101 // Activate virtual keyboard after profile is initialized. It depends on the
102 // default profile. If keyboard usability experiment flag is set, defer the
103 // activation to UpdateWindow() in virtual_keyboard_window_controller.cc.
104 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
105 ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
106 keyboard::KeyboardController::GetInstance());
110 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
111 chrome::CloseAsh();