OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/login/test/app_window_waiter.h" | |
6 | |
7 #include "extensions/browser/app_window/app_window.h" | |
8 | |
9 namespace chromeos { | |
10 | |
11 AppWindowWaiter::AppWindowWaiter(extensions::AppWindowRegistry* registry, | |
12 const std::string& app_id) | |
13 : registry_(registry), app_id_(app_id) { | |
14 registry_->AddObserver(this); | |
15 } | |
16 | |
17 AppWindowWaiter::~AppWindowWaiter() { | |
18 registry_->RemoveObserver(this); | |
19 } | |
20 | |
21 extensions::AppWindow* AppWindowWaiter::Wait() { | |
22 window_ = registry_->GetCurrentAppWindowForApp(app_id_); | |
23 if (window_) | |
24 return window_; | |
25 | |
26 wait_type_ = WAIT_FOR_ADDED; | |
27 run_loop_.reset(new base::RunLoop); | |
28 run_loop_->Run(); | |
29 | |
30 return window_; | |
31 } | |
32 | |
33 extensions::AppWindow* AppWindowWaiter::WaitForShown() { | |
34 window_ = registry_->GetCurrentAppWindowForApp(app_id_); | |
35 if (window_ && !window_->is_hidden()) | |
36 return window_; | |
37 | |
38 wait_type_ = WAIT_FOR_SHOWN; | |
39 run_loop_.reset(new base::RunLoop); | |
40 run_loop_->Run(); | |
41 | |
42 return window_; | |
43 } | |
44 | |
45 void AppWindowWaiter::OnAppWindowAdded(extensions::AppWindow* app_window) { | |
46 if (wait_type_ != WAIT_FOR_ADDED || !run_loop_ || !run_loop_->running()) | |
47 return; | |
48 | |
49 if (app_window->extension_id() == app_id_) { | |
50 window_ = app_window; | |
51 run_loop_->Quit(); | |
52 } | |
53 } | |
54 | |
55 void AppWindowWaiter::OnAppWindowShown(extensions::AppWindow* app_window, | |
56 bool was_hidden) { | |
57 if (wait_type_ != WAIT_FOR_SHOWN || !run_loop_ || !run_loop_->running()) | |
58 return; | |
59 | |
60 if (app_window->extension_id() == app_id_) { | |
61 window_ = app_window; | |
62 run_loop_->Quit(); | |
63 } | |
64 } | |
65 | |
66 } // namespace chromeos | |
OLD | NEW |