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

Side by Side Diff: ash/shelf/shelf_window_watcher.cc

Issue 2185743002: Remove ash::ScopedObserverWithDuplicatedSources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/shelf/shelf_window_watcher.h" 5 #include "ash/shelf/shelf_window_watcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/aura/wm_window_aura.h" 10 #include "ash/aura/wm_window_aura.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(HasShelfItemForWindow(window)); 98 DCHECK(HasShelfItemForWindow(window));
99 window_watcher_->FinishObservingRemovedWindow(window); 99 window_watcher_->FinishObservingRemovedWindow(window);
100 } 100 }
101 101
102 ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model) 102 ShelfWindowWatcher::ShelfWindowWatcher(ShelfModel* model)
103 : model_(model), 103 : model_(model),
104 root_window_observer_(this), 104 root_window_observer_(this),
105 removed_window_observer_(this), 105 removed_window_observer_(this),
106 observed_windows_(this), 106 observed_windows_(this),
107 observed_root_windows_(&root_window_observer_), 107 observed_root_windows_(&root_window_observer_),
108 observed_removed_windows_(&removed_window_observer_), 108 observed_removed_windows_(&removed_window_observer_) {
109 observed_activation_clients_(this) { 109 Shell::GetInstance()->activation_client()->AddObserver(this);
James Cook 2016/07/26 17:48:31 This will get converted to WmShell in my next CL.
110 // We can't assume all RootWindows have the same ActivationClient.
111 // Add a RootWindow and its ActivationClient to the observed list.
112 for (aura::Window* root : Shell::GetAllRootWindows()) 110 for (aura::Window* root : Shell::GetAllRootWindows())
113 OnRootWindowAdded(WmWindowAura::Get(root)); 111 OnRootWindowAdded(WmWindowAura::Get(root));
114 112
115 display::Screen::GetScreen()->AddObserver(this); 113 display::Screen::GetScreen()->AddObserver(this);
116 } 114 }
117 115
118 ShelfWindowWatcher::~ShelfWindowWatcher() { 116 ShelfWindowWatcher::~ShelfWindowWatcher() {
119 display::Screen::GetScreen()->RemoveObserver(this); 117 display::Screen::GetScreen()->RemoveObserver(this);
118 Shell::GetInstance()->activation_client()->RemoveObserver(this);
120 } 119 }
121 120
122 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) { 121 void ShelfWindowWatcher::AddShelfItem(aura::Window* window) {
123 const ShelfItemDetails* item_details = GetShelfItemDetailsForWindow(window); 122 const ShelfItemDetails* item_details = GetShelfItemDetailsForWindow(window);
124 ShelfItem item; 123 ShelfItem item;
125 ShelfID id = model_->next_id(); 124 ShelfID id = model_->next_id();
126 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE : STATUS_RUNNING; 125 item.status = wm::IsActiveWindow(window) ? STATUS_ACTIVE : STATUS_RUNNING;
127 SetShelfItemDetailsForShelfItem(&item, *item_details); 126 SetShelfItemDetailsForShelfItem(&item, *item_details);
128 SetShelfIDForWindow(id, window); 127 SetShelfIDForWindow(id, window);
129 std::unique_ptr<ShelfItemDelegate> item_delegate( 128 std::unique_ptr<ShelfItemDelegate> item_delegate(
130 new ShelfWindowWatcherItemDelegate(window)); 129 new ShelfWindowWatcherItemDelegate(window));
131 model_->SetShelfItemDelegate(id, std::move(item_delegate)); 130 model_->SetShelfItemDelegate(id, std::move(item_delegate));
132 model_->Add(item); 131 model_->Add(item);
133 } 132 }
134 133
135 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) { 134 void ShelfWindowWatcher::RemoveShelfItem(aura::Window* window) {
136 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window))); 135 model_->RemoveItemAt(model_->ItemIndexByID(GetShelfIDForWindow(window)));
137 SetShelfIDForWindow(kInvalidShelfID, window); 136 SetShelfIDForWindow(kInvalidShelfID, window);
138 } 137 }
139 138
140 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) { 139 void ShelfWindowWatcher::OnRootWindowAdded(WmWindow* root_window_wm) {
141 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm); 140 aura::Window* root_window = WmWindowAura::GetAuraWindow(root_window_wm);
142 // |observed_activation_clients_| can have the same ActivationClient multiple
143 // times - which would be handled by the |observed_activation_clients_|.
144 observed_activation_clients_.Add(
145 aura::client::GetActivationClient(root_window));
146 observed_root_windows_.Add(root_window); 141 observed_root_windows_.Add(root_window);
147 142
148 aura::Window* default_container = 143 aura::Window* default_container =
149 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); 144 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer);
150 observed_windows_.Add(default_container); 145 observed_windows_.Add(default_container);
151 for (size_t i = 0; i < default_container->children().size(); ++i) 146 for (size_t i = 0; i < default_container->children().size(); ++i)
152 observed_windows_.Add(default_container->children()[i]); 147 observed_windows_.Add(default_container->children()[i]);
153 } 148 }
154 149
155 void ShelfWindowWatcher::OnRootWindowRemoved(aura::Window* root_window) { 150 void ShelfWindowWatcher::OnRootWindowRemoved(aura::Window* root_window) {
156 observed_root_windows_.Remove(root_window); 151 observed_root_windows_.Remove(root_window);
157 observed_activation_clients_.Remove(
158 aura::client::GetActivationClient(root_window));
159 } 152 }
160 153
161 void ShelfWindowWatcher::UpdateShelfItemStatus(aura::Window* window, 154 void ShelfWindowWatcher::UpdateShelfItemStatus(aura::Window* window,
162 bool is_active) { 155 bool is_active) {
163 int index = GetShelfItemIndexForWindow(window); 156 int index = GetShelfItemIndexForWindow(window);
164 DCHECK_GE(index, 0); 157 DCHECK_GE(index, 0);
165 158
166 ShelfItem item = model_->items()[index]; 159 ShelfItem item = model_->items()[index];
167 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING; 160 item.status = is_active ? STATUS_ACTIVE : STATUS_RUNNING;
168 model_->Set(index, item); 161 model_->Set(index, item);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // When this is called, RootWindow of |old_display| is already removed. 265 // When this is called, RootWindow of |old_display| is already removed.
273 // Instead, we remove an observer from RootWindow and ActivationClient in the 266 // Instead, we remove an observer from RootWindow and ActivationClient in the
274 // OnRootWindowDestroyed(). 267 // OnRootWindowDestroyed().
275 // Do nothing here. 268 // Do nothing here.
276 } 269 }
277 270
278 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&, 271 void ShelfWindowWatcher::OnDisplayMetricsChanged(const display::Display&,
279 uint32_t) {} 272 uint32_t) {}
280 273
281 } // namespace ash 274 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher.h ('k') | chrome/browser/ui/ash/launcher/browser_status_monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698