| OLD | NEW |
| (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_window_tree_factory_set.h" |
| 6 |
| 7 #include "components/mus/ws/user_id_tracker_observer.h" |
| 8 #include "components/mus/ws/window_manager_window_tree_factory.h" |
| 9 #include "components/mus/ws/window_manager_window_tree_factory_set_observer.h" |
| 10 #include "components/mus/ws/window_server.h" |
| 11 |
| 12 namespace mus { |
| 13 namespace ws { |
| 14 |
| 15 WindowManagerWindowTreeFactorySet::WindowManagerWindowTreeFactorySet( |
| 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 WindowManagerWindowTreeFactorySet::~WindowManagerWindowTreeFactorySet() { |
| 23 id_tracker_->RemoveObserver(this); |
| 24 } |
| 25 |
| 26 WindowManagerWindowTreeFactory* WindowManagerWindowTreeFactorySet::Add( |
| 27 const UserId& user_id, |
| 28 mojo::InterfaceRequest<mojom::WindowManagerWindowTreeFactory> request) { |
| 29 if (ContainsFactoryForUser(user_id)) { |
| 30 DVLOG(1) << "can only have one factory per user"; |
| 31 return nullptr; |
| 32 } |
| 33 |
| 34 std::unique_ptr<WindowManagerWindowTreeFactory> factory_ptr( |
| 35 new WindowManagerWindowTreeFactory(this, user_id, std::move(request))); |
| 36 WindowManagerWindowTreeFactory* factory = factory_ptr.get(); |
| 37 factories_.push_back(std::move(factory_ptr)); |
| 38 return factory; |
| 39 } |
| 40 |
| 41 void WindowManagerWindowTreeFactorySet::DeleteFactoryAssociatedWithTree( |
| 42 WindowTree* window_tree) { |
| 43 for (auto it = factories_.begin(); it != factories_.end(); ++it) { |
| 44 if ((*it)->window_tree() == window_tree) { |
| 45 factories_.erase(it); |
| 46 return; |
| 47 } |
| 48 } |
| 49 } |
| 50 |
| 51 std::vector<WindowManagerWindowTreeFactory*> |
| 52 WindowManagerWindowTreeFactorySet::GetFactories() { |
| 53 std::vector<WindowManagerWindowTreeFactory*> result; |
| 54 for (auto& factory : factories_) |
| 55 result.push_back(factory.get()); |
| 56 return result; |
| 57 } |
| 58 |
| 59 void WindowManagerWindowTreeFactorySet::AddObserver( |
| 60 WindowManagerWindowTreeFactorySetObserver* observer) { |
| 61 observers_.AddObserver(observer); |
| 62 } |
| 63 |
| 64 void WindowManagerWindowTreeFactorySet::RemoveObserver( |
| 65 WindowManagerWindowTreeFactorySetObserver* observer) { |
| 66 observers_.RemoveObserver(observer); |
| 67 } |
| 68 |
| 69 bool WindowManagerWindowTreeFactorySet::ContainsFactoryForUser( |
| 70 const UserId& user_id) const { |
| 71 for (auto& factory : factories_) { |
| 72 if (factory->user_id() == user_id) |
| 73 return true; |
| 74 } |
| 75 return false; |
| 76 } |
| 77 |
| 78 void WindowManagerWindowTreeFactorySet::OnWindowManagerWindowTreeFactoryReady( |
| 79 WindowManagerWindowTreeFactory* factory) { |
| 80 const bool is_first_valid_factory = !got_valid_factory_; |
| 81 got_valid_factory_ = true; |
| 82 FOR_EACH_OBSERVER(WindowManagerWindowTreeFactorySetObserver, observers_, |
| 83 OnWindowManagerWindowTreeFactoryReady(factory)); |
| 84 |
| 85 // Notify after other observers as WindowServer triggers other |
| 86 // observers being added, which will have already processed the add. |
| 87 if (is_first_valid_factory) |
| 88 window_server_->OnFirstWindowManagerWindowTreeFactoryReady(); |
| 89 } |
| 90 |
| 91 void WindowManagerWindowTreeFactorySet::OnActiveUserIdChanged( |
| 92 const UserId& previously_active_id, |
| 93 const UserId& active_id) {} |
| 94 |
| 95 void WindowManagerWindowTreeFactorySet::OnUserIdAdded(const UserId& id) {} |
| 96 |
| 97 void WindowManagerWindowTreeFactorySet::OnUserIdRemoved(const UserId& id) { |
| 98 for (auto iter = factories_.begin(); iter != factories_.end(); ++iter) { |
| 99 if ((*iter)->user_id() == id) { |
| 100 factories_.erase(iter); |
| 101 return; |
| 102 } |
| 103 } |
| 104 } |
| 105 |
| 106 } // namespace ws |
| 107 } // namespace mus |
| OLD | NEW |