Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/chromeos/app_mode/startup_app_launcher.cc

Issue 13581008: cros: Explicitly manage app session lifetime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: solution 2 Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_mode/startup_app_launcher.h" 5 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/time.h" 12 #include "base/time.h"
14 #include "base/values.h" 13 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
16 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 15 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h"
18 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/chromeos/ui/app_launch_view.h" 17 #include "chrome/browser/chromeos/ui/app_launch_view.h"
20 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h" 19 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/extensions/webstore_startup_installer.h" 20 #include "chrome/browser/extensions/webstore_startup_installer.h"
23 #include "chrome/browser/lifetime/application_lifetime.h" 21 #include "chrome/browser/lifetime/application_lifetime.h"
24 #include "chrome/browser/policy/browser_policy_connector.h"
25 #include "chrome/browser/signin/token_service.h" 22 #include "chrome/browser/signin/token_service.h"
26 #include "chrome/browser/signin/token_service_factory.h" 23 #include "chrome/browser/signin/token_service_factory.h"
27 #include "chrome/browser/ui/extensions/application_launch.h" 24 #include "chrome/browser/ui/extensions/application_launch.h"
28 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/extensions/extension.h" 27 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" 28 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h"
32 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
34 #include "google_apis/gaia/gaia_auth_consumer.h" 30 #include "google_apis/gaia/gaia_auth_consumer.h"
35 #include "google_apis/gaia/gaia_constants.h" 31 #include "google_apis/gaia/gaia_constants.h"
36 32
37 using content::BrowserThread; 33 using content::BrowserThread;
38 using extensions::Extension; 34 using extensions::Extension;
39 using extensions::WebstoreStartupInstaller; 35 using extensions::WebstoreStartupInstaller;
40 36
41 namespace chromeos { 37 namespace chromeos {
42 38
43 namespace { 39 namespace {
44 40
45
46 const char kOAuthRefreshToken[] = "refresh_token"; 41 const char kOAuthRefreshToken[] = "refresh_token";
47 const char kOAuthClientId[] = "client_id"; 42 const char kOAuthClientId[] = "client_id";
48 const char kOAuthClientSecret[] = "client_secret"; 43 const char kOAuthClientSecret[] = "client_secret";
49 44
50 const base::FilePath::CharType kOAuthFileName[] = 45 const base::FilePath::CharType kOAuthFileName[] =
51 FILE_PATH_LITERAL("kiosk_auth"); 46 FILE_PATH_LITERAL("kiosk_auth");
52 47
53 // Application install splash screen minimum show time in milliseconds. 48 // Application install splash screen minimum show time in milliseconds.
54 const int kAppInstallSplashScreenMinTimeMS = 3000; 49 const int kAppInstallSplashScreenMinTimeMS = 3000;
55 50
56 // Initial delay that gives an app 30 seconds during which the main app window
57 // must be created. If app fails to create the main window in this timeframe,
58 // chrome will exit.
59 // TODO(xiyuan): Find a nicer way to trace process lifetime management at
60 // startup. This just fixes a race that happens on faster machines.
61 const int kInitialEndKeepAliveDelayinSec = 30;
62
63 bool IsAppInstalled(Profile* profile, const std::string& app_id) { 51 bool IsAppInstalled(Profile* profile, const std::string& app_id) {
64 return extensions::ExtensionSystem::Get(profile)->extension_service()-> 52 return extensions::ExtensionSystem::Get(profile)->extension_service()->
65 GetInstalledExtension(app_id); 53 GetInstalledExtension(app_id);
66 } 54 }
67 55
68 } // namespace 56 } // namespace
69 57
70 StartupAppLauncher::StartupAppLauncher(Profile* profile, 58 StartupAppLauncher::StartupAppLauncher(Profile* profile,
71 const std::string& app_id) 59 const std::string& app_id)
72 : profile_(profile), 60 : profile_(profile),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 198 }
211 default: 199 default:
212 NOTREACHED(); 200 NOTREACHED();
213 break; 201 break;
214 } 202 }
215 } 203 }
216 204
217 void StartupAppLauncher::Cleanup() { 205 void StartupAppLauncher::Cleanup() {
218 chromeos::CloseAppLaunchSplashScreen(); 206 chromeos::CloseAppLaunchSplashScreen();
219 207
220 // Ends OpenAsh() keep alive since the session should either be bound with
221 // the just launched app on success or should be ended on failure.
222 // Invoking it via a PostNonNestableTask because Cleanup() could be called
223 // before main message loop starts.
224 BrowserThread::PostNonNestableDelayedTask(
225 BrowserThread::UI,
226 FROM_HERE,
227 base::Bind(&chrome::EndKeepAlive),
228 base::TimeDelta::FromSeconds(kInitialEndKeepAliveDelayinSec));
229
230 delete this; 208 delete this;
231 } 209 }
232 210
233 void StartupAppLauncher::OnLaunchSuccess() { 211 void StartupAppLauncher::OnLaunchSuccess() {
234 const int64 time_taken_ms = (base::TimeTicks::Now() - 212 const int64 time_taken_ms = (base::TimeTicks::Now() -
235 base::TimeTicks::FromInternalValue(launch_splash_start_time_)). 213 base::TimeTicks::FromInternalValue(launch_splash_start_time_)).
236 InMilliseconds(); 214 InMilliseconds();
237 215
238 // Enforce that we show app install splash screen for some minimum amount 216 // Enforce that we show app install splash screen for some minimum amount
239 // of time. 217 // of time.
(...skipping 23 matching lines...) Expand all
263 void StartupAppLauncher::Launch() { 241 void StartupAppLauncher::Launch() {
264 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> 242 const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
265 extension_service()->GetInstalledExtension(app_id_); 243 extension_service()->GetInstalledExtension(app_id_);
266 CHECK(extension); 244 CHECK(extension);
267 245
268 if (!extensions::KioskEnabledInfo::IsKioskEnabled(extension)) { 246 if (!extensions::KioskEnabledInfo::IsKioskEnabled(extension)) {
269 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED); 247 OnLaunchFailure(KioskAppLaunchError::NOT_KIOSK_ENABLED);
270 return; 248 return;
271 } 249 }
272 250
273 // Set the app_id for the current instance of KioskAppUpdateService.
274 KioskAppUpdateService* update_service =
275 KioskAppUpdateServiceFactory::GetForProfile(profile_);
276 DCHECK(update_service);
277 if (update_service)
278 update_service->set_app_id(app_id_);
279
280 // If the device is not enterprise managed, set prefs to reboot after update.
281 if (!g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) {
282 PrefService* local_state = g_browser_process->local_state();
283 local_state->SetBoolean(prefs::kRebootAfterUpdate, true);
284 }
285
286 // Always open the app in a window. 251 // Always open the app in a window.
287 chrome::OpenApplication(chrome::AppLaunchParams(profile_, 252 chrome::OpenApplication(chrome::AppLaunchParams(profile_,
288 extension, 253 extension,
289 extension_misc::LAUNCH_WINDOW, 254 extension_misc::LAUNCH_WINDOW,
290 NEW_WINDOW)); 255 NEW_WINDOW));
256 InitAppSession(profile_, app_id_);
291 OnLaunchSuccess(); 257 OnLaunchSuccess();
292 } 258 }
293 259
294 void StartupAppLauncher::BeginInstall() { 260 void StartupAppLauncher::BeginInstall() {
295 DVLOG(1) << "BeginInstall... connection = " 261 DVLOG(1) << "BeginInstall... connection = "
296 << net::NetworkChangeNotifier::GetConnectionType(); 262 << net::NetworkChangeNotifier::GetConnectionType();
297 263
298 chromeos::UpdateAppLaunchSplashScreenState( 264 chromeos::UpdateAppLaunchSplashScreenState(
299 chromeos::APP_LAUNCH_STATE_INSTALLING_APPLICATION); 265 chromeos::APP_LAUNCH_STATE_INSTALLING_APPLICATION);
300 266
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (event->key_code() != ui::VKEY_S || 326 if (event->key_code() != ui::VKEY_S ||
361 !(event->flags() & ui::EF_CONTROL_DOWN) || 327 !(event->flags() & ui::EF_CONTROL_DOWN) ||
362 !(event->flags() & ui::EF_ALT_DOWN)) { 328 !(event->flags() & ui::EF_ALT_DOWN)) {
363 return; 329 return;
364 } 330 }
365 331
366 OnLaunchFailure(KioskAppLaunchError::USER_CANCEL); 332 OnLaunchFailure(KioskAppLaunchError::USER_CANCEL);
367 } 333 }
368 334
369 } // namespace chromeos 335 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/app_mode/app_session_lifetime.cc ('k') | chrome/browser/lifetime/application_lifetime_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698