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

Side by Side Diff: mojo/services/view_manager/view_manager_service_impl.cc

Issue 699173003: Makes ViewManagerServiceImpl track a single root (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: comment Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/services/view_manager/view_manager_service_impl.h" 5 #include "mojo/services/view_manager/view_manager_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "mojo/converters/geometry/geometry_type_converters.h" 9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "mojo/converters/input_events/input_events_type_converters.h" 10 #include "mojo/converters/input_events/input_events_type_converters.h"
(...skipping 13 matching lines...) Expand all
24 const std::string& url, 24 const std::string& url,
25 const ViewId& root_id, 25 const ViewId& root_id,
26 InterfaceRequest<ServiceProvider> service_provider) 26 InterfaceRequest<ServiceProvider> service_provider)
27 : connection_manager_(connection_manager), 27 : connection_manager_(connection_manager),
28 id_(connection_manager_->GetAndAdvanceNextConnectionId()), 28 id_(connection_manager_->GetAndAdvanceNextConnectionId()),
29 url_(url), 29 url_(url),
30 creator_id_(creator_id), 30 creator_id_(creator_id),
31 creator_url_(creator_url), 31 creator_url_(creator_url),
32 service_provider_(service_provider.Pass()) { 32 service_provider_(service_provider.Pass()) {
33 CHECK(GetView(root_id)); 33 CHECK(GetView(root_id));
34 roots_.insert(ViewIdToTransportId(root_id)); 34 root_.reset(new ViewId(root_id));
35 if (root_id == RootViewId()) 35 if (root_id == RootViewId())
36 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); 36 access_policy_.reset(new WindowManagerAccessPolicy(id_, this));
37 else 37 else
38 access_policy_.reset(new DefaultAccessPolicy(id_, this)); 38 access_policy_.reset(new DefaultAccessPolicy(id_, this));
39 } 39 }
40 40
41 ViewManagerServiceImpl::~ViewManagerServiceImpl() { 41 ViewManagerServiceImpl::~ViewManagerServiceImpl() {
42 DestroyViews(); 42 DestroyViews();
43 } 43 }
44 44
45 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const { 45 const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const {
46 if (id_ == id.connection_id) { 46 if (id_ == id.connection_id) {
47 ViewMap::const_iterator i = view_map_.find(id.view_id); 47 ViewMap::const_iterator i = view_map_.find(id.view_id);
48 return i == view_map_.end() ? NULL : i->second; 48 return i == view_map_.end() ? NULL : i->second;
49 } 49 }
50 return connection_manager_->GetView(id); 50 return connection_manager_->GetView(id);
51 } 51 }
52 52
53 bool ViewManagerServiceImpl::HasRoot(const ViewId& id) const { 53 bool ViewManagerServiceImpl::IsRoot(const ViewId& id) const {
54 return roots_.find(ViewIdToTransportId(id)) != roots_.end(); 54 return root_.get() && *root_ == id;
55 } 55 }
56 56
57 void ViewManagerServiceImpl::OnWillDestroyViewManagerServiceImpl( 57 void ViewManagerServiceImpl::OnWillDestroyViewManagerServiceImpl(
58 ViewManagerServiceImpl* connection) { 58 ViewManagerServiceImpl* connection) {
59 if (creator_id_ == connection->id()) 59 if (creator_id_ == connection->id())
60 creator_id_ = kInvalidConnectionId; 60 creator_id_ = kInvalidConnectionId;
61 ViewId embedded_root_id; 61 if (connection->root_ && connection->root_->connection_id == id_ &&
62 if (ProvidesRoot(connection, &embedded_root_id)) 62 view_map_.count(connection->root_->view_id) > 0) {
63 client()->OnEmbeddedAppDisconnected(ViewIdToTransportId(embedded_root_id)); 63 client()->OnEmbeddedAppDisconnected(
64 ViewIdToTransportId(*connection->root_));
65 }
64 } 66 }
65 67
66 void ViewManagerServiceImpl::ProcessViewBoundsChanged( 68 void ViewManagerServiceImpl::ProcessViewBoundsChanged(
67 const ServerView* view, 69 const ServerView* view,
68 const gfx::Rect& old_bounds, 70 const gfx::Rect& old_bounds,
69 const gfx::Rect& new_bounds, 71 const gfx::Rect& new_bounds,
70 bool originated_change) { 72 bool originated_change) {
71 if (originated_change || !IsViewKnown(view)) 73 if (originated_change || !IsViewKnown(view))
72 return; 74 return;
73 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()), 75 client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 client()->OnViewReordered(ViewIdToTransportId(view->id()), 155 client()->OnViewReordered(ViewIdToTransportId(view->id()),
154 ViewIdToTransportId(relative_view->id()), 156 ViewIdToTransportId(relative_view->id()),
155 direction); 157 direction);
156 } 158 }
157 159
158 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view, 160 void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view,
159 bool originated_change) { 161 bool originated_change) {
160 view_map_.erase(view.view_id); 162 view_map_.erase(view.view_id);
161 163
162 const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0; 164 const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0;
163 roots_.erase(ViewIdToTransportId(view)); 165 if (IsRoot(view))
166 root_.reset();
164 167
165 if (originated_change) 168 if (originated_change)
166 return; 169 return;
167 170
168 if (in_known) { 171 if (in_known) {
169 client()->OnViewDeleted(ViewIdToTransportId(view)); 172 client()->OnViewDeleted(ViewIdToTransportId(view));
170 connection_manager_->OnConnectionMessagedClient(id_); 173 connection_manager_->OnConnectionMessagedClient(id_);
171 } 174 }
172 } 175 }
173 176
(...skipping 23 matching lines...) Expand all
197 } 200 }
198 201
199 void ViewManagerServiceImpl::OnConnectionError() { 202 void ViewManagerServiceImpl::OnConnectionError() {
200 connection_manager_->OnConnectionError(this); 203 connection_manager_->OnConnectionError(this);
201 } 204 }
202 205
203 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const { 206 bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const {
204 return known_views_.count(ViewIdToTransportId(view->id())) > 0; 207 return known_views_.count(ViewIdToTransportId(view->id())) > 0;
205 } 208 }
206 209
207 bool ViewManagerServiceImpl::ProvidesRoot(
208 const ViewManagerServiceImpl* connection,
209 ViewId* root_id) const {
210 for (Id transport_id : connection->roots()) {
211 const ViewId view_id(ViewIdFromTransportId(transport_id));
212 if (id_ == view_id.connection_id && view_map_.count(view_id.view_id) > 0) {
213 *root_id = view_id;
214 return true;
215 }
216 }
217 return false;
218 }
219
220 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view, 210 bool ViewManagerServiceImpl::CanReorderView(const ServerView* view,
221 const ServerView* relative_view, 211 const ServerView* relative_view,
222 OrderDirection direction) const { 212 OrderDirection direction) const {
223 if (!view || !relative_view) 213 if (!view || !relative_view)
224 return false; 214 return false;
225 215
226 if (!view->parent() || view->parent() != relative_view->parent()) 216 if (!view->parent() || view->parent() != relative_view->parent())
227 return false; 217 return false;
228 218
229 if (!access_policy_->CanReorderView(view, relative_view, direction)) 219 if (!access_policy_->CanReorderView(view, relative_view, direction))
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (local_views) 263 if (local_views)
274 local_views->push_back(GetView(view->id())); 264 local_views->push_back(GetView(view->id()));
275 return; 265 return;
276 } 266 }
277 known_views_.erase(ViewIdToTransportId(view->id())); 267 known_views_.erase(ViewIdToTransportId(view->id()));
278 std::vector<const ServerView*> children = view->GetChildren(); 268 std::vector<const ServerView*> children = view->GetChildren();
279 for (size_t i = 0; i < children.size(); ++i) 269 for (size_t i = 0; i < children.size(); ++i)
280 RemoveFromKnown(children[i], local_views); 270 RemoveFromKnown(children[i], local_views);
281 } 271 }
282 272
283 void ViewManagerServiceImpl::RemoveRoot(const ViewId& view_id) { 273 void ViewManagerServiceImpl::RemoveRoot() {
284 const Id transport_view_id(ViewIdToTransportId(view_id)); 274 CHECK(root_.get());
285 CHECK(roots_.count(transport_view_id) > 0); 275 const ViewId root_id(*root_);
286 276 root_.reset();
287 roots_.erase(transport_view_id);
288
289 // No need to do anything if we created the view. 277 // No need to do anything if we created the view.
290 if (view_id.connection_id == id_) 278 if (root_id.connection_id == id_)
291 return; 279 return;
292 280
293 client()->OnViewDeleted(transport_view_id); 281 client()->OnViewDeleted(ViewIdToTransportId(root_id));
294 connection_manager_->OnConnectionMessagedClient(id_); 282 connection_manager_->OnConnectionMessagedClient(id_);
295 283
296 // This connection no longer knows about the view. Unparent any views that 284 // This connection no longer knows about the view. Unparent any views that
297 // were parented to views in the root. 285 // were parented to views in the root.
298 std::vector<ServerView*> local_views; 286 std::vector<ServerView*> local_views;
299 RemoveFromKnown(GetView(view_id), &local_views); 287 RemoveFromKnown(GetView(root_id), &local_views);
300 for (size_t i = 0; i < local_views.size(); ++i) 288 for (size_t i = 0; i < local_views.size(); ++i)
301 local_views[i]->parent()->Remove(local_views[i]); 289 local_views[i]->parent()->Remove(local_views[i]);
302 } 290 }
303 291
304 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed( 292 void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed(
305 const ViewId& view_id) { 293 const ViewId& view_id) {
306 ServerView* view = GetView(view_id); 294 ServerView* view = GetView(view_id);
307 CHECK(view); 295 CHECK(view);
308 CHECK(view->id().connection_id == view_id.connection_id); 296 CHECK(view->id().connection_id == view_id.connection_id);
309 std::vector<ServerView*> children = view->GetChildren(); 297 std::vector<ServerView*> children = view->GetChildren();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (!access_policy_->CanDescendIntoViewForViewTree(view)) 337 if (!access_policy_->CanDescendIntoViewForViewTree(view))
350 return; 338 return;
351 339
352 std::vector<const ServerView*> children(view->GetChildren()); 340 std::vector<const ServerView*> children(view->GetChildren());
353 for (size_t i = 0 ; i < children.size(); ++i) 341 for (size_t i = 0 ; i < children.size(); ++i)
354 GetViewTreeImpl(children[i], views); 342 GetViewTreeImpl(children[i], views);
355 } 343 }
356 344
357 void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView* view, 345 void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView* view,
358 bool new_drawn_value) { 346 bool new_drawn_value) {
359 // Even though we don't know about view, it may be an ancestor of one of our 347 // Even though we don't know about view, it may be an ancestor of our root, in
360 // roots, in which case the change may effect our roots drawn state. 348 // which case the change may effect our roots drawn state.
361 for (ViewIdSet::iterator i = roots_.begin(); i != roots_.end(); ++i) { 349 if (!root_.get())
362 const ServerView* root = GetView(ViewIdFromTransportId(*i)); 350 return;
363 DCHECK(root); 351
364 if (view->Contains(root) && 352 const ServerView* root = GetView(*root_);
365 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) { 353 DCHECK(root);
366 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()), 354 if (view->Contains(root) &&
367 new_drawn_value); 355 (new_drawn_value != root->IsDrawn(connection_manager_->root()))) {
368 } 356 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()),
357 new_drawn_value);
369 } 358 }
370 } 359 }
371 360
372 void ViewManagerServiceImpl::DestroyViews() { 361 void ViewManagerServiceImpl::DestroyViews() {
373 if (!view_map_.empty()) { 362 if (!view_map_.empty()) {
374 ConnectionManager::ScopedChange change(this, connection_manager_, true); 363 ConnectionManager::ScopedChange change(this, connection_manager_, true);
375 // If we get here from the destructor we're not going to get 364 // If we get here from the destructor we're not going to get
376 // ProcessViewDeleted(). Copy the map and delete from the copy so that we 365 // ProcessViewDeleted(). Copy the map and delete from the copy so that we
377 // don't have to worry about whether |view_map_| changes or not. 366 // don't have to worry about whether |view_map_| changes or not.
378 ViewMap view_map_copy; 367 ViewMap view_map_copy;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // Only allow a node to be the root for one connection. 537 // Only allow a node to be the root for one connection.
549 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); 538 const ViewId view_id(ViewIdFromTransportId(transport_view_id));
550 ViewManagerServiceImpl* existing_owner = 539 ViewManagerServiceImpl* existing_owner =
551 connection_manager_->GetConnectionWithRoot(view_id); 540 connection_manager_->GetConnectionWithRoot(view_id);
552 541
553 ConnectionManager::ScopedChange change(this, connection_manager_, true); 542 ConnectionManager::ScopedChange change(this, connection_manager_, true);
554 RemoveChildrenAsPartOfEmbed(view_id); 543 RemoveChildrenAsPartOfEmbed(view_id);
555 if (existing_owner) { 544 if (existing_owner) {
556 // Never message the originating connection. 545 // Never message the originating connection.
557 connection_manager_->OnConnectionMessagedClient(id_); 546 connection_manager_->OnConnectionMessagedClient(id_);
558 existing_owner->RemoveRoot(view_id); 547 existing_owner->RemoveRoot();
559 } 548 }
560 connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass()); 549 connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass());
561 callback.Run(true); 550 callback.Run(true);
562 } 551 }
563 552
564 void ViewManagerServiceImpl::OnConnectionEstablished() { 553 void ViewManagerServiceImpl::OnConnectionEstablished() {
565 std::vector<const ServerView*> to_send; 554 std::vector<const ServerView*> to_send;
566 for (ViewIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) 555 if (root_.get())
567 GetUnknownViewsFrom(GetView(ViewIdFromTransportId(*i)), &to_send); 556 GetUnknownViewsFrom(GetView(*root_), &to_send);
568 557
569 MessagePipe pipe; 558 MessagePipe pipe;
570 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient( 559 connection_manager_->wm_internal()->CreateWindowManagerForViewManagerClient(
571 id_, pipe.handle1.Pass()); 560 id_, pipe.handle1.Pass());
572 client()->OnEmbed(id_, 561 client()->OnEmbed(id_,
573 creator_url_, 562 creator_url_,
574 ViewToViewData(to_send.front()), 563 ViewToViewData(to_send.front()),
575 service_provider_.Pass(), 564 service_provider_.Pass(),
576 pipe.handle0.Pass()); 565 pipe.handle0.Pass());
577 } 566 }
578 567
579 const base::hash_set<Id>& 568 bool ViewManagerServiceImpl::IsRootForAccessPolicy(const ViewId& id) const {
580 ViewManagerServiceImpl::GetRootsForAccessPolicy() const { 569 return IsRoot(id);
581 return roots_;
582 } 570 }
583 571
584 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy( 572 bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy(
585 const ServerView* view) const { 573 const ServerView* view) const {
586 return IsViewKnown(view); 574 return IsViewKnown(view);
587 } 575 }
588 576
589 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( 577 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy(
590 const ServerView* view) const { 578 const ServerView* view) const {
591 ViewManagerServiceImpl* connection = 579 ViewManagerServiceImpl* connection =
592 connection_manager_->GetConnectionWithRoot(view->id()); 580 connection_manager_->GetConnectionWithRoot(view->id());
593 return connection && connection != this; 581 return connection && connection != this;
594 } 582 }
595 583
596 } // namespace service 584 } // namespace service
597 } // namespace mojo 585 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_service_impl.h ('k') | mojo/services/view_manager/window_manager_access_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698