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

Side by Side Diff: chrome/browser/chromeos/login/app_launch_controller.cc

Issue 163493002: Fix race condition on kiosk app launch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/login/app_launch_controller.h" 5 #include "chrome/browser/chromeos/login/app_launch_controller.h"
6 6
7 #include "apps/shell_window.h"
7 #include "apps/shell_window_registry.h" 8 #include "apps/shell_window_registry.h"
9 #include "base/bind.h"
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
10 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h" 15 #include "base/time/time.h"
12 #include "base/values.h" 16 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" 19 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
16 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
17 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h" 21 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
18 #include "chrome/browser/chromeos/login/login_display_host.h" 22 #include "chrome/browser/chromeos/login/login_display_host.h"
19 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 23 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
20 #include "chrome/browser/chromeos/login/oobe_display.h" 24 #include "chrome/browser/chromeos/login/oobe_display.h"
(...skipping 25 matching lines...) Expand all
46 AppLaunchController::can_configure_network_callback_ = NULL; 50 AppLaunchController::can_configure_network_callback_ = NULL;
47 AppLaunchController::ReturnBoolCallback* 51 AppLaunchController::ReturnBoolCallback*
48 AppLaunchController::need_owner_auth_to_configure_network_callback_ = NULL; 52 AppLaunchController::need_owner_auth_to_configure_network_callback_ = NULL;
49 53
50 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
51 // AppLaunchController::AppWindowWatcher 55 // AppLaunchController::AppWindowWatcher
52 56
53 class AppLaunchController::AppWindowWatcher 57 class AppLaunchController::AppWindowWatcher
54 : public apps::ShellWindowRegistry::Observer { 58 : public apps::ShellWindowRegistry::Observer {
55 public: 59 public:
56 explicit AppWindowWatcher(AppLaunchController* controller) 60 explicit AppWindowWatcher(AppLaunchController* controller,
61 const std::string& app_id)
57 : controller_(controller), 62 : controller_(controller),
58 window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)) { 63 app_id_(app_id),
59 window_registry_->AddObserver(this); 64 window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)),
65 weak_factory_(this) {
66 if (!window_registry_->GetShellWindowsForApp(app_id).empty()) {
67 base::MessageLoop::current()->PostTask(
68 FROM_HERE,
69 base::Bind(&AppWindowWatcher::NotifyAppWindowCreated,
70 weak_factory_.GetWeakPtr()));
71 return;
72 } else {
73 window_registry_->AddObserver(this);
74 }
60 } 75 }
61 virtual ~AppWindowWatcher() { 76 virtual ~AppWindowWatcher() {
62 window_registry_->RemoveObserver(this); 77 window_registry_->RemoveObserver(this);
63 } 78 }
64 79
65 private: 80 private:
66 // apps::ShellWindowRegistry::Observer overrides: 81 // apps::ShellWindowRegistry::Observer overrides:
67 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE { 82 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE {
68 if (controller_) { 83 if (shell_window->extension_id() == app_id_) {
69 controller_->OnAppWindowCreated(); 84 window_registry_->RemoveObserver(this);
70 controller_= NULL; 85 NotifyAppWindowCreated();
71 } 86 }
72 } 87 }
73 virtual void OnShellWindowIconChanged( 88 virtual void OnShellWindowIconChanged(
74 apps::ShellWindow* shell_window) OVERRIDE {} 89 apps::ShellWindow* shell_window) OVERRIDE {}
75 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE {} 90 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE {}
76 91
92 void NotifyAppWindowCreated() {
93 controller_->OnAppWindowCreated();
94 }
95
77 AppLaunchController* controller_; 96 AppLaunchController* controller_;
97 std::string app_id_;
78 apps::ShellWindowRegistry* window_registry_; 98 apps::ShellWindowRegistry* window_registry_;
99 base::WeakPtrFactory<AppWindowWatcher> weak_factory_;
79 100
80 DISALLOW_COPY_AND_ASSIGN(AppWindowWatcher); 101 DISALLOW_COPY_AND_ASSIGN(AppWindowWatcher);
81 }; 102 };
82 103
83 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
84 // AppLaunchController 105 // AppLaunchController
85 106
86 AppLaunchController::AppLaunchController(const std::string& app_id, 107 AppLaunchController::AppLaunchController(const std::string& app_id,
87 bool diagnostic_mode, 108 bool diagnostic_mode,
88 LoginDisplayHost* host, 109 LoginDisplayHost* host,
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 375
355 startup_app_launcher_->LaunchApp(); 376 startup_app_launcher_->LaunchApp();
356 } 377 }
357 378
358 void AppLaunchController::OnLaunchSucceeded() { 379 void AppLaunchController::OnLaunchSucceeded() {
359 DVLOG(1) << "Kiosk launch succeeded, wait for app window."; 380 DVLOG(1) << "Kiosk launch succeeded, wait for app window.";
360 app_launch_splash_screen_actor_->UpdateAppLaunchState( 381 app_launch_splash_screen_actor_->UpdateAppLaunchState(
361 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_WAITING_APP_WINDOW); 382 AppLaunchSplashScreenActor::APP_LAUNCH_STATE_WAITING_APP_WINDOW);
362 383
363 DCHECK(!app_window_watcher_); 384 DCHECK(!app_window_watcher_);
364 app_window_watcher_.reset(new AppWindowWatcher(this)); 385 app_window_watcher_.reset(new AppWindowWatcher(this, app_id_));
365 } 386 }
366 387
367 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) { 388 void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) {
368 LOG(ERROR) << "Kiosk launch failed. Will now shut down." 389 LOG(ERROR) << "Kiosk launch failed. Will now shut down."
369 << ", error=" << error; 390 << ", error=" << error;
370 DCHECK_NE(KioskAppLaunchError::NONE, error); 391 DCHECK_NE(KioskAppLaunchError::NONE, error);
371 392
372 // Saves the error and ends the session to go back to login screen. 393 // Saves the error and ends the session to go back to login screen.
373 KioskAppLaunchError::Save(error); 394 KioskAppLaunchError::Save(error);
374 chrome::AttemptUserExit(); 395 chrome::AttemptUserExit();
375 CleanUp(); 396 CleanUp();
376 } 397 }
377 398
378 } // namespace chromeos 399 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698