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 "chrome/browser/ui/views/athena/chrome_browser_main_extra_parts_athena.h"
7 #include "athena/env/public/athena_env.h"
8 #include "athena/main/public/athena_launcher.h"
9 #include "base/command_line.h"
10 #include "base/macros.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_browser_main_extra_parts.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/views/select_file_dialog_extension_factory.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23 #include "content/public/browser/notification_service.h"
27 class ChromeBrowserMainExtraPartsAthena : public ChromeBrowserMainExtraParts,
28 public content::NotificationObserver {
30 ChromeBrowserMainExtraPartsAthena() {
32 chrome::NOTIFICATION_APP_TERMINATING,
33 content::NotificationService::AllSources());
36 virtual ~ChromeBrowserMainExtraPartsAthena() {}
39 // Overridden from ChromeBrowserMainExtraParts:
40 virtual void PreProfileInit() override {
41 athena::StartAthenaEnv(content::BrowserThread::GetBlockingPool()->
42 GetTaskRunnerWithShutdownBehavior(
43 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
45 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
47 virtual void PostProfileInit() override {
48 if (!CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kDisableZeroBrowsersOpenForTests)) {
50 chrome::IncrementKeepAliveCount();
53 g_browser_process->profile_manager()->GetActiveUserProfile();
54 if (!CommandLine::ForCurrentProcess()->HasSwitch(
55 chromeos::switches::kLoginManager)) {
56 athena::CreateVirtualKeyboardWithContext(profile);
57 athena::StartAthenaSessionWithContext(profile);
59 // Only initialize virtual keyboard with login profile, user session will
61 athena::CreateVirtualKeyboardWithContext(profile);
64 virtual void PostMainMessageLoopRun() override { athena::ShutdownAthena(); }
66 // content::NotificationObserver:
67 virtual void Observe(int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) override {
71 case chrome::NOTIFICATION_APP_TERMINATING:
72 athena::AthenaEnv::Get()->OnTerminating();
77 content::NotificationRegistrar registrar_;
79 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAthena);
84 ChromeBrowserMainExtraParts* CreateChromeBrowserMainExtraPartsAthena() {
85 return new ChromeBrowserMainExtraPartsAthena();