Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/public/cpp/view_manager/lib/view_manager_client_impl.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 view->RemoveObserver(this); | 85 view->RemoveObserver(this); |
| 86 delete this; | 86 delete this; |
| 87 } | 87 } |
| 88 | 88 |
| 89 View* root_; | 89 View* root_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(RootObserver); | 91 DISALLOW_COPY_AND_ASSIGN(RootObserver); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, | 94 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, |
| 95 Shell* shell) | 95 Shell* shell, |
| 96 : connected_(false), connection_id_(0), next_id_(1), delegate_(delegate) { | 96 ScopedMessagePipeHandle handle, |
| 97 bool delete_on_error) | |
| 98 : connected_(false), | |
| 99 connection_id_(0), | |
| 100 next_id_(1), | |
| 101 delegate_(delegate), | |
| 102 binding_(this, handle.Pass()), | |
| 103 delete_on_error_(delete_on_error) { | |
| 104 service_ = binding_.client(); | |
|
sky
2014/11/13 00:34:38
move to initializer list? You'll have to move serv
| |
| 97 } | 105 } |
| 98 | 106 |
| 99 ViewManagerClientImpl::~ViewManagerClientImpl() { | 107 ViewManagerClientImpl::~ViewManagerClientImpl() { |
| 100 std::vector<View*> non_owned; | 108 std::vector<View*> non_owned; |
| 101 while (!views_.empty()) { | 109 while (!views_.empty()) { |
| 102 IdToViewMap::iterator it = views_.begin(); | 110 IdToViewMap::iterator it = views_.begin(); |
| 103 if (OwnsView(it->second->id())) { | 111 if (OwnsView(it->second->id())) { |
| 104 it->second->Destroy(); | 112 it->second->Destroy(); |
| 105 } else { | 113 } else { |
| 106 non_owned.push_back(it->second); | 114 non_owned.push_back(it->second); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 const std::vector<View*>& ViewManagerClientImpl::GetRoots() const { | 233 const std::vector<View*>& ViewManagerClientImpl::GetRoots() const { |
| 226 return roots_; | 234 return roots_; |
| 227 } | 235 } |
| 228 | 236 |
| 229 View* ViewManagerClientImpl::GetViewById(Id id) { | 237 View* ViewManagerClientImpl::GetViewById(Id id) { |
| 230 IdToViewMap::const_iterator it = views_.find(id); | 238 IdToViewMap::const_iterator it = views_.find(id); |
| 231 return it != views_.end() ? it->second : NULL; | 239 return it != views_.end() ? it->second : NULL; |
| 232 } | 240 } |
| 233 | 241 |
| 234 //////////////////////////////////////////////////////////////////////////////// | 242 //////////////////////////////////////////////////////////////////////////////// |
| 235 // ViewManagerClientImpl, InterfaceImpl overrides: | |
| 236 | |
| 237 void ViewManagerClientImpl::OnConnectionEstablished() { | |
| 238 service_ = client(); | |
| 239 } | |
| 240 | |
| 241 //////////////////////////////////////////////////////////////////////////////// | |
| 242 // ViewManagerClientImpl, ViewManagerClient implementation: | 243 // ViewManagerClientImpl, ViewManagerClient implementation: |
| 243 | 244 |
| 244 void ViewManagerClientImpl::OnEmbed( | 245 void ViewManagerClientImpl::OnEmbed( |
| 245 ConnectionSpecificId connection_id, | 246 ConnectionSpecificId connection_id, |
| 246 const String& creator_url, | 247 const String& creator_url, |
| 247 ViewDataPtr root_data, | 248 ViewDataPtr root_data, |
| 248 InterfaceRequest<ServiceProvider> parent_services, | 249 InterfaceRequest<ServiceProvider> parent_services, |
| 249 ScopedMessagePipeHandle window_manager_pipe) { | 250 ScopedMessagePipeHandle window_manager_pipe) { |
| 250 if (!connected_) { | 251 if (!connected_) { |
| 251 connected_ = true; | 252 connected_ = true; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 FOR_EACH_OBSERVER(ViewObserver, | 390 FOR_EACH_OBSERVER(ViewObserver, |
| 390 *ViewPrivate(focused).observers(), | 391 *ViewPrivate(focused).observers(), |
| 391 OnViewFocusChanged(focused, blurred)); | 392 OnViewFocusChanged(focused, blurred)); |
| 392 } | 393 } |
| 393 } | 394 } |
| 394 | 395 |
| 395 void ViewManagerClientImpl::OnActiveWindowChanged(Id old_focused_window, | 396 void ViewManagerClientImpl::OnActiveWindowChanged(Id old_focused_window, |
| 396 Id new_focused_window) {} | 397 Id new_focused_window) {} |
| 397 | 398 |
| 398 //////////////////////////////////////////////////////////////////////////////// | 399 //////////////////////////////////////////////////////////////////////////////// |
| 400 // OnConnectionError, private: | |
| 401 void ViewManagerClientImpl::OnConnectionError() { | |
| 402 if (delete_on_error_) | |
| 403 delete this; | |
| 404 } | |
| 405 | |
| 406 //////////////////////////////////////////////////////////////////////////////// | |
| 399 // ViewManagerClientImpl, private: | 407 // ViewManagerClientImpl, private: |
| 400 | 408 |
| 401 void ViewManagerClientImpl::RemoveRoot(View* root) { | 409 void ViewManagerClientImpl::RemoveRoot(View* root) { |
| 402 std::vector<View*>::iterator it = | 410 std::vector<View*>::iterator it = |
| 403 std::find(roots_.begin(), roots_.end(), root); | 411 std::find(roots_.begin(), roots_.end(), root); |
| 404 if (it != roots_.end()) | 412 if (it != roots_.end()) |
| 405 roots_.erase(it); | 413 roots_.erase(it); |
| 406 } | 414 } |
| 407 | 415 |
| 408 void ViewManagerClientImpl::OnActionCompleted(bool success) { | 416 void ViewManagerClientImpl::OnActionCompleted(bool success) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 419 base::Unretained(this)); | 427 base::Unretained(this)); |
| 420 } | 428 } |
| 421 | 429 |
| 422 base::Callback<void(ErrorCode)> | 430 base::Callback<void(ErrorCode)> |
| 423 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 431 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
| 424 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 432 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
| 425 base::Unretained(this)); | 433 base::Unretained(this)); |
| 426 } | 434 } |
| 427 | 435 |
| 428 } // namespace mojo | 436 } // namespace mojo |
| OLD | NEW |