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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/app_launch_controller.cc
diff --git a/chrome/browser/chromeos/login/app_launch_controller.cc b/chrome/browser/chromeos/login/app_launch_controller.cc
index ad559da372cfdb3e3a5d3a83a61b65354fa5767e..3feeec110c62eb051ab8250e6fd142c4011d4d70 100644
--- a/chrome/browser/chromeos/login/app_launch_controller.cc
+++ b/chrome/browser/chromeos/login/app_launch_controller.cc
@@ -4,10 +4,14 @@
#include "chrome/browser/chromeos/login/app_launch_controller.h"
+#include "apps/shell_window.h"
#include "apps/shell_window_registry.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
@@ -53,10 +57,21 @@ AppLaunchController::ReturnBoolCallback*
class AppLaunchController::AppWindowWatcher
: public apps::ShellWindowRegistry::Observer {
public:
- explicit AppWindowWatcher(AppLaunchController* controller)
+ explicit AppWindowWatcher(AppLaunchController* controller,
+ const std::string& app_id)
: controller_(controller),
- window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)) {
- window_registry_->AddObserver(this);
+ app_id_(app_id),
+ window_registry_(apps::ShellWindowRegistry::Get(controller->profile_)),
+ weak_factory_(this) {
+ if (!window_registry_->GetShellWindowsForApp(app_id).empty()) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&AppWindowWatcher::NotifyAppWindowCreated,
+ weak_factory_.GetWeakPtr()));
+ return;
+ } else {
+ window_registry_->AddObserver(this);
+ }
}
virtual ~AppWindowWatcher() {
window_registry_->RemoveObserver(this);
@@ -65,17 +80,23 @@ class AppLaunchController::AppWindowWatcher
private:
// apps::ShellWindowRegistry::Observer overrides:
virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE {
- if (controller_) {
- controller_->OnAppWindowCreated();
- controller_= NULL;
+ if (shell_window->extension_id() == app_id_) {
+ window_registry_->RemoveObserver(this);
+ NotifyAppWindowCreated();
}
}
virtual void OnShellWindowIconChanged(
apps::ShellWindow* shell_window) OVERRIDE {}
virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE {}
+ void NotifyAppWindowCreated() {
+ controller_->OnAppWindowCreated();
+ }
+
AppLaunchController* controller_;
+ std::string app_id_;
apps::ShellWindowRegistry* window_registry_;
+ base::WeakPtrFactory<AppWindowWatcher> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AppWindowWatcher);
};
@@ -361,7 +382,7 @@ void AppLaunchController::OnLaunchSucceeded() {
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_WAITING_APP_WINDOW);
DCHECK(!app_window_watcher_);
- app_window_watcher_.reset(new AppWindowWatcher(this));
+ app_window_watcher_.reset(new AppWindowWatcher(this, app_id_));
}
void AppLaunchController::OnLaunchFailed(KioskAppLaunchError::Error error) {
« 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