summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/test/app_window_waiter.cc
blob: f9be212488b5d241543b8ec4bbeda8f039b37ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/login/test/app_window_waiter.h"

#include "apps/app_window.h"

namespace chromeos {

AppWindowWaiter::AppWindowWaiter(apps::AppWindowRegistry* registry,
                                 const std::string& app_id)
    : registry_(registry), app_id_(app_id), window_(NULL) {
  registry_->AddObserver(this);
}

AppWindowWaiter::~AppWindowWaiter() {
  registry_->RemoveObserver(this);
}

apps::AppWindow* AppWindowWaiter::Wait() {
  window_ = registry_->GetCurrentAppWindowForApp(app_id_);
  if (window_)
    return window_;

  run_loop_.Run();

  return window_;
}

void AppWindowWaiter::OnAppWindowAdded(apps::AppWindow* app_window) {
  if (!run_loop_.running())
    return;

  if (app_window->extension_id() == app_id_) {
    window_ = app_window;
    run_loop_.Quit();
  }
}

}  // namespace chromeos