Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / login / demo_mode / demo_app_launcher.cc
blob6be11b895d9e117c323bd0ae6afa70ac9287a08e
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/chromeos/login/demo_mode/demo_app_launcher.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
13 #include "chrome/browser/extensions/component_loader.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/extensions/app_launch_params.h"
18 #include "chrome/browser/ui/extensions/application_launch.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/grit/browser_resources.h"
22 #include "chromeos/network/network_handler.h"
23 #include "chromeos/network/network_state_handler.h"
24 #include "components/user_manager/user_manager.h"
25 #include "extensions/browser/extension_system.h"
26 #include "extensions/common/constants.h"
27 #include "extensions/common/extension.h"
28 #include "ui/base/window_open_disposition.h"
30 namespace chromeos {
32 const char DemoAppLauncher::kDemoUserName[] = "demouser@demo.app.local";
33 const char DemoAppLauncher::kDemoAppId[] = "klimoghijjogocdbaikffefjfcfheiel";
34 const base::FilePath::CharType kDefaultDemoAppPath[] =
35 FILE_PATH_LITERAL("/usr/share/chromeos-assets/demo_app");
37 // static
38 base::FilePath* DemoAppLauncher::demo_app_path_ = NULL;
40 DemoAppLauncher::DemoAppLauncher() {
41 if (!demo_app_path_)
42 demo_app_path_ = new base::FilePath(kDefaultDemoAppPath);
45 DemoAppLauncher::~DemoAppLauncher() {
46 delete demo_app_path_;
49 void DemoAppLauncher::StartDemoAppLaunch() {
50 DVLOG(1) << "Launching demo app...";
51 // user_id = DemoAppUserId, force_emphemeral = true, delegate = this.
52 kiosk_profile_loader_.reset(
53 new KioskProfileLoader(kDemoUserName, true, this));
54 kiosk_profile_loader_->Start();
57 // static
58 bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) {
59 return user_id == kDemoUserName;
62 // static
63 void DemoAppLauncher::SetDemoAppPathForTesting(const base::FilePath& path) {
64 delete demo_app_path_;
65 demo_app_path_ = new base::FilePath(path);
68 void DemoAppLauncher::OnProfileLoaded(Profile* profile) {
69 DVLOG(1) << "Profile loaded... Starting demo app launch.";
71 kiosk_profile_loader_.reset();
73 // Load our demo app, then launch it.
74 ExtensionService* extension_service =
75 extensions::ExtensionSystem::Get(profile)->extension_service();
76 CHECK(demo_app_path_);
77 const std::string extension_id = extension_service->component_loader()->Add(
78 IDR_DEMO_APP_MANIFEST,
79 *demo_app_path_);
81 const extensions::Extension* extension =
82 extension_service->GetExtensionById(extension_id, true);
83 if (!extension) {
84 // We've already done too much setup at this point to just return out, it
85 // is safer to just restart.
86 chrome::AttemptUserExit();
87 return;
90 // Disable network before launching the app.
91 LOG(WARNING) << "Disabling network before launching demo app..";
92 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
93 handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(),
94 false,
95 chromeos::network_handler::ErrorCallback());
97 OpenApplication(
98 AppLaunchParams(profile, extension, extensions::LAUNCH_CONTAINER_WINDOW,
99 NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
100 InitAppSession(profile, extension_id);
102 user_manager::UserManager::Get()->SessionStarted();
104 LoginDisplayHostImpl::default_host()->Finalize();
107 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) {
108 LOG(ERROR) << "Loading the Kiosk Profile failed: " <<
109 KioskAppLaunchError::GetErrorMessage(error);
112 } // namespace chromeos