OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" | 5 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | |
9 #include "base/logging.h" | |
8 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" | 10 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" |
11 #include "chrome/browser/chromeos/login/login_display_host.h" | |
xiyuan
2014/03/20 01:14:03
nit: No need since login_display_host_impl.h is in
bartfab (slow)
2014/03/20 13:22:29
But LoginDisplayHostImpl::default_host() returns a
| |
9 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 12 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
10 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
11 #include "chrome/browser/extensions/component_loader.h" | 14 #include "chrome/browser/extensions/component_loader.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
14 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/extension_constants.h" | |
15 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | |
16 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
23 #include "ui/base/window_open_disposition.h" | |
17 | 24 |
18 namespace chromeos { | 25 namespace chromeos { |
19 | 26 |
20 const char DemoAppLauncher::kDemoUserName[] = "demouser@demo.app.local"; | 27 const char DemoAppLauncher::kDemoUserName[] = "demouser@demo.app.local"; |
28 const base::FilePath::CharType kDefaultDemoAppPath[] = | |
29 FILE_PATH_LITERAL("/usr/share/chromeos-assets/demo_app"); | |
21 | 30 |
22 DemoAppLauncher::DemoAppLauncher() : profile_(NULL) {} | 31 // static |
32 base::FilePath* DemoAppLauncher::demo_app_path_ = NULL; | |
23 | 33 |
24 DemoAppLauncher::~DemoAppLauncher() {} | 34 DemoAppLauncher::DemoAppLauncher() { |
35 if (!demo_app_path_) | |
36 demo_app_path_ = new base::FilePath(kDefaultDemoAppPath); | |
xiyuan
2014/03/20 01:14:03
nit: 1 space after '='
rkc
2014/03/20 21:45:01
Done.
| |
37 } | |
38 | |
39 DemoAppLauncher::~DemoAppLauncher() { | |
40 delete demo_app_path_; | |
41 } | |
25 | 42 |
26 void DemoAppLauncher::StartDemoAppLaunch() { | 43 void DemoAppLauncher::StartDemoAppLaunch() { |
27 DVLOG(1) << "Launching demo app..."; | 44 DVLOG(1) << "Launching demo app..."; |
28 // user_id = DemoAppUserId, force_emphemeral = true, delegate = this. | 45 // user_id = DemoAppUserId, force_emphemeral = true, delegate = this. |
29 kiosk_profile_loader_.reset( | 46 kiosk_profile_loader_.reset( |
30 new KioskProfileLoader(kDemoUserName, true, this)); | 47 new KioskProfileLoader(kDemoUserName, true, this)); |
31 kiosk_profile_loader_->Start(); | 48 kiosk_profile_loader_->Start(); |
32 } | 49 } |
33 | 50 |
34 // static | 51 // static |
35 bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) { | 52 bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) { |
36 return user_id == kDemoUserName ? true : false; | 53 return user_id == kDemoUserName; |
54 } | |
55 | |
56 // static | |
57 void DemoAppLauncher::SetDemoAppPathForTesting(const base::FilePath& path) { | |
58 demo_app_path_ = new base::FilePath(path); | |
xiyuan
2014/03/20 01:14:03
To be safe and avoid future leaks, we should delet
rkc
2014/03/20 21:45:01
Done.
| |
37 } | 59 } |
38 | 60 |
39 void DemoAppLauncher::OnProfileLoaded(Profile* profile) { | 61 void DemoAppLauncher::OnProfileLoaded(Profile* profile) { |
40 DVLOG(1) << "Profile loaded... Starting demo app launch."; | 62 DVLOG(1) << "Profile loaded... Starting demo app launch."; |
41 profile_ = profile; | |
42 | 63 |
43 kiosk_profile_loader_.reset(); | 64 kiosk_profile_loader_.reset(); |
44 | 65 |
45 // Load our demo app, then launch it. | 66 // Load our demo app, then launch it. |
46 ExtensionService* extension_service = | 67 ExtensionService* extension_service = |
47 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 68 extensions::ExtensionSystem::Get(profile)->extension_service(); |
48 std::string extension_id = extension_service->component_loader()->Add( | 69 CHECK(demo_app_path_); |
70 const std::string extension_id = extension_service->component_loader()->Add( | |
49 IDR_DEMO_APP_MANIFEST, | 71 IDR_DEMO_APP_MANIFEST, |
50 base::FilePath("/usr/share/chromeos-assets/demo_app")); | 72 *demo_app_path_); |
51 | 73 |
52 const extensions::Extension* extension = | 74 const extensions::Extension* extension = |
53 extension_service->GetExtensionById(extension_id, true); | 75 extension_service->GetExtensionById(extension_id, true); |
54 | 76 |
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 77 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
56 command_line->AppendSwitch(switches::kForceAppMode); | 78 command_line->AppendSwitch(switches::kForceAppMode); |
57 command_line->AppendSwitchASCII(switches::kAppId, extension_id); | 79 command_line->AppendSwitchASCII(switches::kAppId, extension_id); |
58 | 80 |
59 OpenApplication(AppLaunchParams( | 81 OpenApplication(AppLaunchParams( |
60 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 82 profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
61 InitAppSession(profile_, extension_id); | 83 InitAppSession(profile, extension_id); |
62 | 84 |
63 UserManager::Get()->SessionStarted(); | 85 UserManager::Get()->SessionStarted(); |
64 | 86 |
65 LoginDisplayHostImpl::default_host()->Finalize(); | 87 LoginDisplayHostImpl::default_host()->Finalize(); |
66 } | 88 } |
67 | 89 |
68 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) { | 90 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) { |
69 LOG(ERROR) << "Loading the Kiosk Profile failed: " << | 91 LOG(ERROR) << "Loading the Kiosk Profile failed: " << |
70 KioskAppLaunchError::GetErrorMessage(error); | 92 KioskAppLaunchError::GetErrorMessage(error); |
71 } | 93 } |
72 | 94 |
73 } // namespace chromeos | 95 } // namespace chromeos |
OLD | NEW |