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

Side by Side Diff: mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.cc

Issue 911073005: Drop all uses of //base except ObserverList from view mgr client lib (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: gn check Created 5 years, 10 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 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 "view_manager/public/cpp/lib/view_manager_client_impl.h" 5 #include "view_manager/public/cpp/lib/view_manager_client_impl.h"
6 6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "mojo/public/cpp/application/application_impl.h" 7 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/public/cpp/application/connect.h" 8 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/application/service_provider_impl.h" 9 #include "mojo/public/cpp/application/service_provider_impl.h"
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" 10 #include "mojo/public/interfaces/application/service_provider.mojom.h"
14 #include "mojo/public/interfaces/application/shell.mojom.h" 11 #include "mojo/public/interfaces/application/shell.mojom.h"
15 #include "view_manager/public/cpp/lib/view_private.h" 12 #include "view_manager/public/cpp/lib/view_private.h"
16 #include "view_manager/public/cpp/util.h" 13 #include "view_manager/public/cpp/util.h"
17 #include "view_manager/public/cpp/view_manager_delegate.h" 14 #include "view_manager/public/cpp/view_manager_delegate.h"
18 #include "view_manager/public/cpp/view_observer.h" 15 #include "view_manager/public/cpp/view_observer.h"
19 16
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void OnViewDestroyed(View* view) override { 80 void OnViewDestroyed(View* view) override {
84 DCHECK_EQ(view, root_); 81 DCHECK_EQ(view, root_);
85 static_cast<ViewManagerClientImpl*>(root_->view_manager()) 82 static_cast<ViewManagerClientImpl*>(root_->view_manager())
86 ->RootDestroyed(root_); 83 ->RootDestroyed(root_);
87 view->RemoveObserver(this); 84 view->RemoveObserver(this);
88 delete this; 85 delete this;
89 } 86 }
90 87
91 View* root_; 88 View* root_;
92 89
93 DISALLOW_COPY_AND_ASSIGN(RootObserver); 90 MOJO_DISALLOW_COPY_AND_ASSIGN(RootObserver);
94 }; 91 };
95 92
96 ViewManagerClientImpl::ViewManagerClientImpl( 93 ViewManagerClientImpl::ViewManagerClientImpl(
97 ViewManagerDelegate* delegate, 94 ViewManagerDelegate* delegate,
98 Shell* shell, 95 Shell* shell,
99 InterfaceRequest<ViewManagerClient> request, 96 InterfaceRequest<ViewManagerClient> request,
100 bool delete_on_error) 97 bool delete_on_error)
101 : connection_id_(0), 98 : connection_id_(0),
102 next_id_(1), 99 next_id_(1),
103 delegate_(delegate), 100 delegate_(delegate),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 DCHECK(!service_); 226 DCHECK(!service_);
230 DCHECK(service); 227 DCHECK(service);
231 service_ = service.Pass(); 228 service_ = service.Pass();
232 } 229 }
233 //////////////////////////////////////////////////////////////////////////////// 230 ////////////////////////////////////////////////////////////////////////////////
234 // ViewManagerClientImpl, ViewManager implementation: 231 // ViewManagerClientImpl, ViewManager implementation:
235 232
236 Id ViewManagerClientImpl::CreateViewOnServer() { 233 Id ViewManagerClientImpl::CreateViewOnServer() {
237 DCHECK(service_); 234 DCHECK(service_);
238 const Id view_id = MakeTransportId(connection_id_, ++next_id_); 235 const Id view_id = MakeTransportId(connection_id_, ++next_id_);
239 service_->CreateView(view_id, ActionCompletedCallbackWithErrorCode()); 236 service_->CreateView(view_id, [this](ErrorCode code) {
237 OnActionCompleted(code == ERROR_CODE_NONE);
238 });
240 return view_id; 239 return view_id;
241 } 240 }
242 241
243 const std::string& ViewManagerClientImpl::GetEmbedderURL() const { 242 const std::string& ViewManagerClientImpl::GetEmbedderURL() const {
244 return creator_url_; 243 return creator_url_;
245 } 244 }
246 245
247 View* ViewManagerClientImpl::GetRoot() { 246 View* ViewManagerClientImpl::GetRoot() {
248 return root_; 247 return root_;
249 } 248 }
(...skipping 29 matching lines...) Expand all
279 service_ = view_manager_service.Pass(); 278 service_ = view_manager_service.Pass();
280 } 279 }
281 connection_id_ = connection_id; 280 connection_id_ = connection_id;
282 creator_url_ = String::From(creator_url); 281 creator_url_ = String::From(creator_url);
283 282
284 DCHECK(!root_); 283 DCHECK(!root_);
285 root_ = AddViewToViewManager(this, nullptr, root_data); 284 root_ = AddViewToViewManager(this, nullptr, root_data);
286 root_->AddObserver(new RootObserver(root_)); 285 root_->AddObserver(new RootObserver(root_));
287 286
288 window_manager_.Bind(window_manager_pipe.Pass()); 287 window_manager_.Bind(window_manager_pipe.Pass());
289 // base::Unretained() is safe here as |window_manager_| is bound to our
290 // lifetime.
291 WindowManagerObserverPtr observer; 288 WindowManagerObserverPtr observer;
292 wm_observer_binding_.Bind(GetProxy(&observer)); 289 wm_observer_binding_.Bind(GetProxy(&observer));
290 // binding to |this| is safe here as |window_manager_| is bound to our
291 // lifetime.
293 window_manager_->GetFocusedAndActiveViews( 292 window_manager_->GetFocusedAndActiveViews(
294 observer.Pass(), 293 observer.Pass(),
295 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, 294 [this](uint32_t capture_view_id, uint32_t focused_view_id,
296 base::Unretained(this))); 295 uint32_t active_view_id) {
296 if (GetViewById(capture_view_id) != capture_view_)
297 OnCaptureChanged(capture_view_id);
298 if (GetViewById(focused_view_id) != focused_view_)
299 OnFocusChanged(focused_view_id);
300 if (GetViewById(active_view_id) != activated_view_)
301 OnActiveWindowChanged(active_view_id);
302 });
297 303
298 delegate_->OnEmbed(root_, services.Pass(), exposed_services.Pass()); 304 delegate_->OnEmbed(root_, services.Pass(), exposed_services.Pass());
299 } 305 }
300 306
301 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) { 307 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) {
302 View* view = GetViewById(view_id); 308 View* view = GetViewById(view_id);
303 if (view) { 309 if (view) {
304 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), 310 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(),
305 OnViewEmbeddedAppDisconnected(view)); 311 OnViewEmbeddedAppDisconnected(view));
306 } 312 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 void ViewManagerClientImpl::RootDestroyed(View* root) { 482 void ViewManagerClientImpl::RootDestroyed(View* root) {
477 DCHECK_EQ(root, root_); 483 DCHECK_EQ(root, root_);
478 root_ = nullptr; 484 root_ = nullptr;
479 } 485 }
480 486
481 void ViewManagerClientImpl::OnActionCompleted(bool success) { 487 void ViewManagerClientImpl::OnActionCompleted(bool success) {
482 if (!change_acked_callback_.is_null()) 488 if (!change_acked_callback_.is_null())
483 change_acked_callback_.Run(); 489 change_acked_callback_.Run();
484 } 490 }
485 491
486 void ViewManagerClientImpl::OnActionCompletedWithErrorCode(ErrorCode code) { 492 Callback<void(bool)> ViewManagerClientImpl::ActionCompletedCallback() {
487 OnActionCompleted(code == ERROR_CODE_NONE); 493 return [this](bool success) { OnActionCompleted(success); };
488 }
489
490 base::Callback<void(bool)> ViewManagerClientImpl::ActionCompletedCallback() {
491 return base::Bind(&ViewManagerClientImpl::OnActionCompleted,
492 base::Unretained(this));
493 }
494
495 base::Callback<void(ErrorCode)>
496 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() {
497 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode,
498 base::Unretained(this));
499 }
500
501 void ViewManagerClientImpl::OnGotFocusedAndActiveViews(
502 uint32_t capture_view_id,
503 uint32_t focused_view_id,
504 uint32_t active_view_id) {
505 if (GetViewById(capture_view_id) != capture_view_)
506 OnCaptureChanged(capture_view_id);
507 if (GetViewById(focused_view_id) != focused_view_)
508 OnFocusChanged(focused_view_id);
509 if (GetViewById(active_view_id) != activated_view_)
510 OnActiveWindowChanged(active_view_id);
511 } 494 }
512 495
513 } // namespace mojo 496 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698