OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/mus/ws/window_manager_factory_registry.h" | 5 #include "components/mus/ws/window_manager_factory_registry.h" |
6 | 6 |
7 #include "components/mus/ws/connection_manager.h" | 7 #include "components/mus/ws/connection_manager.h" |
8 #include "components/mus/ws/user_id_tracker_observer.h" | 8 #include "components/mus/ws/user_id_tracker_observer.h" |
9 #include "components/mus/ws/window_manager_factory_registry_observer.h" | 9 #include "components/mus/ws/window_manager_factory_registry_observer.h" |
10 #include "components/mus/ws/window_manager_factory_service.h" | 10 #include "components/mus/ws/window_manager_factory_service.h" |
11 | 11 |
12 namespace mus { | 12 namespace mus { |
13 namespace ws { | 13 namespace ws { |
14 | 14 |
15 WindowManagerFactoryRegistry::WindowManagerFactoryRegistry( | 15 WindowManagerFactoryRegistry::WindowManagerFactoryRegistry( |
16 ConnectionManager* connection_manager, | 16 ConnectionManager* connection_manager, |
17 UserIdTracker* id_tracker) | 17 UserIdTracker* id_tracker) |
18 : id_tracker_(id_tracker), connection_manager_(connection_manager) { | 18 : id_tracker_(id_tracker), connection_manager_(connection_manager) { |
19 id_tracker_->AddObserver(this); | 19 id_tracker_->AddObserver(this); |
20 } | 20 } |
21 | 21 |
22 WindowManagerFactoryRegistry::~WindowManagerFactoryRegistry() { | 22 WindowManagerFactoryRegistry::~WindowManagerFactoryRegistry() { |
23 id_tracker_->RemoveObserver(this); | 23 id_tracker_->RemoveObserver(this); |
24 } | 24 } |
25 | 25 |
26 void WindowManagerFactoryRegistry::Register( | 26 void WindowManagerFactoryRegistry::Register( |
27 UserId user_id, | 27 const UserId& user_id, |
28 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) { | 28 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) { |
29 if (ContainsServiceForUser(user_id)) | 29 if (ContainsServiceForUser(user_id)) |
30 return; | 30 return; |
31 | 31 |
32 scoped_ptr<WindowManagerFactoryService> service( | 32 scoped_ptr<WindowManagerFactoryService> service( |
33 new WindowManagerFactoryService(this, user_id, std::move(request))); | 33 new WindowManagerFactoryService(this, user_id, std::move(request))); |
34 AddServiceImpl(std::move(service)); | 34 AddServiceImpl(std::move(service)); |
35 } | 35 } |
36 | 36 |
37 std::vector<WindowManagerFactoryService*> | 37 std::vector<WindowManagerFactoryService*> |
(...skipping 13 matching lines...) Expand all Loading... |
51 WindowManagerFactoryRegistryObserver* observer) { | 51 WindowManagerFactoryRegistryObserver* observer) { |
52 observers_.RemoveObserver(observer); | 52 observers_.RemoveObserver(observer); |
53 } | 53 } |
54 | 54 |
55 void WindowManagerFactoryRegistry::AddServiceImpl( | 55 void WindowManagerFactoryRegistry::AddServiceImpl( |
56 scoped_ptr<WindowManagerFactoryService> service) { | 56 scoped_ptr<WindowManagerFactoryService> service) { |
57 services_.push_back(std::move(service)); | 57 services_.push_back(std::move(service)); |
58 } | 58 } |
59 | 59 |
60 bool WindowManagerFactoryRegistry::ContainsServiceForUser( | 60 bool WindowManagerFactoryRegistry::ContainsServiceForUser( |
61 UserId user_id) const { | 61 const UserId& user_id) const { |
62 for (auto& service_ptr : services_) { | 62 for (auto& service_ptr : services_) { |
63 if (service_ptr->user_id() == user_id) { | 63 if (service_ptr->user_id() == user_id) { |
64 LOG(ERROR) << "WindowManagerFactoryService already registered for " | 64 LOG(ERROR) << "WindowManagerFactoryService already registered for " |
65 << user_id; | 65 << user_id; |
66 return true; | 66 return true; |
67 } | 67 } |
68 } | 68 } |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
(...skipping 14 matching lines...) Expand all Loading... |
86 got_valid_factory_ = true; | 86 got_valid_factory_ = true; |
87 FOR_EACH_OBSERVER(WindowManagerFactoryRegistryObserver, observers_, | 87 FOR_EACH_OBSERVER(WindowManagerFactoryRegistryObserver, observers_, |
88 OnWindowManagerFactorySet(service)); | 88 OnWindowManagerFactorySet(service)); |
89 | 89 |
90 // Notify after other observers as ConnectionManager triggers other | 90 // Notify after other observers as ConnectionManager triggers other |
91 // observers being added, which will have already processed the add. | 91 // observers being added, which will have already processed the add. |
92 if (is_first_valid_factory) | 92 if (is_first_valid_factory) |
93 connection_manager_->OnFirstWindowManagerFactorySet(); | 93 connection_manager_->OnFirstWindowManagerFactorySet(); |
94 } | 94 } |
95 | 95 |
96 void WindowManagerFactoryRegistry::OnActiveUserIdChanged(UserId id) {} | 96 void WindowManagerFactoryRegistry::OnActiveUserIdChanged(const UserId& id) {} |
97 | 97 |
98 void WindowManagerFactoryRegistry::OnUserIdAdded(UserId id) {} | 98 void WindowManagerFactoryRegistry::OnUserIdAdded(const UserId& id) {} |
99 | 99 |
100 void WindowManagerFactoryRegistry::OnUserIdRemoved(UserId id) { | 100 void WindowManagerFactoryRegistry::OnUserIdRemoved(const UserId& id) { |
101 for (auto iter = services_.begin(); iter != services_.end(); ++iter) { | 101 for (auto iter = services_.begin(); iter != services_.end(); ++iter) { |
102 if ((*iter)->user_id() == id) { | 102 if ((*iter)->user_id() == id) { |
103 services_.erase(iter); | 103 services_.erase(iter); |
104 return; | 104 return; |
105 } | 105 } |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 } // namespace ws | 109 } // namespace ws |
110 } // namespace mus | 110 } // namespace mus |
OLD | NEW |