forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_window_waiter.cc
89 lines (68 loc) · 2.32 KB
/
app_window_waiter.cc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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 "apps/test/app_window_waiter.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/native_app_window.h"
namespace apps {
AppWindowWaiter::AppWindowWaiter(extensions::AppWindowRegistry* registry,
const std::string& app_id)
: registry_(registry), app_id_(app_id) {
registry_->AddObserver(this);
}
AppWindowWaiter::~AppWindowWaiter() {
registry_->RemoveObserver(this);
}
extensions::AppWindow* AppWindowWaiter::Wait() {
window_ = registry_->GetCurrentAppWindowForApp(app_id_);
if (window_)
return window_;
wait_type_ = WAIT_FOR_ADDED;
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
return window_;
}
extensions::AppWindow* AppWindowWaiter::WaitForShown() {
window_ = registry_->GetCurrentAppWindowForApp(app_id_);
if (window_ && !window_->is_hidden())
return window_;
wait_type_ = WAIT_FOR_SHOWN;
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
return window_;
}
extensions::AppWindow* AppWindowWaiter::WaitForActivated() {
window_ = registry_->GetCurrentAppWindowForApp(app_id_);
if (window_ && window_->GetBaseWindow()->IsActive())
return window_;
wait_type_ = WAIT_FOR_ACTIVATED;
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
return window_;
}
void AppWindowWaiter::OnAppWindowAdded(extensions::AppWindow* app_window) {
if (wait_type_ != WAIT_FOR_ADDED || !run_loop_ || !run_loop_->running())
return;
if (app_window->extension_id() == app_id_) {
window_ = app_window;
run_loop_->Quit();
}
}
void AppWindowWaiter::OnAppWindowShown(extensions::AppWindow* app_window,
bool was_hidden) {
if (wait_type_ != WAIT_FOR_SHOWN || !run_loop_ || !run_loop_->running())
return;
if (app_window->extension_id() == app_id_) {
window_ = app_window;
run_loop_->Quit();
}
}
void AppWindowWaiter::OnAppWindowActivated(extensions::AppWindow* app_window) {
if (wait_type_ != WAIT_FOR_ACTIVATED || !run_loop_ || !run_loop_->running())
return;
if (app_window->extension_id() == app_id_) {
window_ = app_window;
run_loop_->Quit();
}
}
} // namespace apps