db068c1834f84c66b6e7e72bb2069b60e2a56295
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / athena / chrome_browser_main_extra_parts_athena.cc
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.
4
5 #include "chrome/browser/ui/views/athena/chrome_browser_main_extra_parts_athena.h"
6
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"
24
25 namespace {
26
27 class ChromeBrowserMainExtraPartsAthena : public ChromeBrowserMainExtraParts,
28                                           public content::NotificationObserver {
29  public:
30   ChromeBrowserMainExtraPartsAthena() {
31     registrar_.Add(this,
32                    chrome::NOTIFICATION_APP_TERMINATING,
33                    content::NotificationService::AllSources());
34   }
35
36   virtual ~ChromeBrowserMainExtraPartsAthena() {}
37
38  private:
39   // Overridden from ChromeBrowserMainExtraParts:
40   virtual void PreProfileInit() override {
41     athena::StartAthenaEnv(content::BrowserThread::GetBlockingPool()->
42         GetTaskRunnerWithShutdownBehavior(
43             base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
44
45     ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
46   }
47   virtual void PostProfileInit() override {
48     if (!CommandLine::ForCurrentProcess()->HasSwitch(
49             switches::kDisableZeroBrowsersOpenForTests)) {
50       chrome::IncrementKeepAliveCount();
51     }
52     Profile* profile =
53         g_browser_process->profile_manager()->GetActiveUserProfile();
54     if (!CommandLine::ForCurrentProcess()->HasSwitch(
55             chromeos::switches::kLoginManager)) {
56       athena::CreateVirtualKeyboardWithContext(profile);
57       athena::StartAthenaSessionWithContext(profile);
58     } else {
59       // Only initialize virtual keyboard with login profile, user session will
60       // start after login.
61       athena::CreateVirtualKeyboardWithContext(profile);
62     }
63   }
64   virtual void PostMainMessageLoopRun() override { athena::ShutdownAthena(); }
65
66   // content::NotificationObserver:
67   virtual void Observe(int type,
68                        const content::NotificationSource& source,
69                        const content::NotificationDetails& details) override {
70     switch (type) {
71       case chrome::NOTIFICATION_APP_TERMINATING:
72         athena::AthenaEnv::Get()->OnTerminating();
73         break;
74     }
75   }
76
77   content::NotificationRegistrar registrar_;
78
79   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAthena);
80 };
81
82 }  // namespace
83
84 ChromeBrowserMainExtraParts* CreateChromeBrowserMainExtraPartsAthena() {
85   return new ChromeBrowserMainExtraPartsAthena();
86 }