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

Side by Side Diff: components/mus/ws/window_manager_factory_registry.cc

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include Created 4 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "components/mus/ws/window_manager_factory_registry.h"
6
7 #include "components/mus/ws/user_id_tracker_observer.h"
8 #include "components/mus/ws/window_manager_factory_registry_observer.h"
9 #include "components/mus/ws/window_manager_factory_service.h"
10 #include "components/mus/ws/window_server.h"
11
12 namespace mus {
13 namespace ws {
14
15 WindowManagerFactoryRegistry::WindowManagerFactoryRegistry(
16 WindowServer* window_server,
17 UserIdTracker* id_tracker)
18 : id_tracker_(id_tracker), window_server_(window_server) {
19 id_tracker_->AddObserver(this);
20 }
21
22 WindowManagerFactoryRegistry::~WindowManagerFactoryRegistry() {
23 id_tracker_->RemoveObserver(this);
24 }
25
26 void WindowManagerFactoryRegistry::Register(
27 const UserId& user_id,
28 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) {
29 if (ContainsServiceForUser(user_id))
30 return;
31
32 std::unique_ptr<WindowManagerFactoryService> service(
33 new WindowManagerFactoryService(this, user_id, std::move(request)));
34 AddServiceImpl(std::move(service));
35 }
36
37 std::vector<WindowManagerFactoryService*>
38 WindowManagerFactoryRegistry::GetServices() {
39 std::vector<WindowManagerFactoryService*> result;
40 for (auto& service_ptr : services_)
41 result.push_back(service_ptr.get());
42 return result;
43 }
44
45 void WindowManagerFactoryRegistry::AddObserver(
46 WindowManagerFactoryRegistryObserver* observer) {
47 observers_.AddObserver(observer);
48 }
49
50 void WindowManagerFactoryRegistry::RemoveObserver(
51 WindowManagerFactoryRegistryObserver* observer) {
52 observers_.RemoveObserver(observer);
53 }
54
55 void WindowManagerFactoryRegistry::AddServiceImpl(
56 std::unique_ptr<WindowManagerFactoryService> service) {
57 services_.push_back(std::move(service));
58 }
59
60 bool WindowManagerFactoryRegistry::ContainsServiceForUser(
61 const UserId& user_id) const {
62 for (auto& service_ptr : services_) {
63 if (service_ptr->user_id() == user_id) {
64 LOG(ERROR) << "WindowManagerFactoryService already registered for "
65 << user_id;
66 return true;
67 }
68 }
69 return false;
70 }
71
72 void WindowManagerFactoryRegistry::OnWindowManagerFactoryConnectionLost(
73 WindowManagerFactoryService* service) {
74 for (auto it = services_.begin(); it != services_.end(); ++it) {
75 if (it->get() == service) {
76 services_.erase(it);
77 return;
78 }
79 }
80 }
81
82 void WindowManagerFactoryRegistry::OnWindowManagerFactorySet(
83 WindowManagerFactoryService* service) {
84 DCHECK(service->window_manager_factory());
85 const bool is_first_valid_factory = !got_valid_factory_;
86 got_valid_factory_ = true;
87 FOR_EACH_OBSERVER(WindowManagerFactoryRegistryObserver, observers_,
88 OnWindowManagerFactorySet(service));
89
90 // Notify after other observers as WindowServer triggers other
91 // observers being added, which will have already processed the add.
92 if (is_first_valid_factory)
93 window_server_->OnFirstWindowManagerFactorySet();
94 }
95
96 void WindowManagerFactoryRegistry::OnActiveUserIdChanged(
97 const UserId& previously_active_id,
98 const UserId& active_id) {}
99
100 void WindowManagerFactoryRegistry::OnUserIdAdded(const UserId& id) {}
101
102 void WindowManagerFactoryRegistry::OnUserIdRemoved(const UserId& id) {
103 for (auto iter = services_.begin(); iter != services_.end(); ++iter) {
104 if ((*iter)->user_id() == id) {
105 services_.erase(iter);
106 return;
107 }
108 }
109 }
110
111 } // namespace ws
112 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_manager_factory_registry.h ('k') | components/mus/ws/window_manager_factory_registry_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698