Commit 88df6da7 authored by mnissler@chromium.org's avatar mnissler@chromium.org

Fix race condition on kiosk app launch.

The previous code would fail for the case of the app window already
present before the observer gets registered.

BUG=chromium:343540

Review URL: https://codereview.chromium.org/163493002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251088 0039d316-1c4b-4281-b951-d872f2087c98
parent 7356e8ce
......@@ -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);
};
......@@ -368,7 +389,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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment