| 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" |
| 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); |
| 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 if (demo_app_path_) |
| 59 delete demo_app_path_; |
| 60 demo_app_path_ = new base::FilePath(path); |
| 37 } | 61 } |
| 38 | 62 |
| 39 void DemoAppLauncher::OnProfileLoaded(Profile* profile) { | 63 void DemoAppLauncher::OnProfileLoaded(Profile* profile) { |
| 40 DVLOG(1) << "Profile loaded... Starting demo app launch."; | 64 DVLOG(1) << "Profile loaded... Starting demo app launch."; |
| 41 profile_ = profile; | |
| 42 | 65 |
| 43 kiosk_profile_loader_.reset(); | 66 kiosk_profile_loader_.reset(); |
| 44 | 67 |
| 45 // Load our demo app, then launch it. | 68 // Load our demo app, then launch it. |
| 46 ExtensionService* extension_service = | 69 ExtensionService* extension_service = |
| 47 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 70 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 48 std::string extension_id = extension_service->component_loader()->Add( | 71 CHECK(demo_app_path_); |
| 72 const std::string extension_id = extension_service->component_loader()->Add( |
| 49 IDR_DEMO_APP_MANIFEST, | 73 IDR_DEMO_APP_MANIFEST, |
| 50 base::FilePath("/usr/share/chromeos-assets/demo_app")); | 74 *demo_app_path_); |
| 51 | 75 |
| 52 const extensions::Extension* extension = | 76 const extensions::Extension* extension = |
| 53 extension_service->GetExtensionById(extension_id, true); | 77 extension_service->GetExtensionById(extension_id, true); |
| 54 | 78 |
| 55 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 79 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 56 command_line->AppendSwitch(switches::kForceAppMode); | 80 command_line->AppendSwitch(switches::kForceAppMode); |
| 57 command_line->AppendSwitchASCII(switches::kAppId, extension_id); | 81 command_line->AppendSwitchASCII(switches::kAppId, extension_id); |
| 58 | 82 |
| 59 OpenApplication(AppLaunchParams( | 83 OpenApplication(AppLaunchParams( |
| 60 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 84 profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
| 61 InitAppSession(profile_, extension_id); | 85 InitAppSession(profile, extension_id); |
| 62 | 86 |
| 63 UserManager::Get()->SessionStarted(); | 87 UserManager::Get()->SessionStarted(); |
| 64 | 88 |
| 65 LoginDisplayHostImpl::default_host()->Finalize(); | 89 LoginDisplayHostImpl::default_host()->Finalize(); |
| 66 } | 90 } |
| 67 | 91 |
| 68 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) { | 92 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) { |
| 69 LOG(ERROR) << "Loading the Kiosk Profile failed: " << | 93 LOG(ERROR) << "Loading the Kiosk Profile failed: " << |
| 70 KioskAppLaunchError::GetErrorMessage(error); | 94 KioskAppLaunchError::GetErrorMessage(error); |
| 71 } | 95 } |
| 72 | 96 |
| 73 } // namespace chromeos | 97 } // namespace chromeos |
| OLD | NEW |