| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/view_manager/public/cpp/view_manager_init.h" | 5 #include "components/view_manager/public/cpp/view_manager_init.h" |
| 6 | 6 |
| 7 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h" | 7 #include "components/view_manager/public/cpp/lib/view_tree_client_impl.h" |
| 8 #include "components/view_manager/public/cpp/view_manager_delegate.h" | 8 #include "components/view_manager/public/cpp/view_manager_delegate.h" |
| 9 #include "mojo/application/public/cpp/application_impl.h" | 9 #include "mojo/application/public/cpp/application_impl.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 class ViewManagerInit::ClientFactory | 13 class ViewManagerInit::ClientFactory |
| 14 : public InterfaceFactory<ViewManagerClient> { | 14 : public InterfaceFactory<ViewTreeClient> { |
| 15 public: | 15 public: |
| 16 ClientFactory(ViewManagerInit* init) : init_(init) {} | 16 ClientFactory(ViewManagerInit* init) : init_(init) {} |
| 17 ~ClientFactory() override {} | 17 ~ClientFactory() override {} |
| 18 | 18 |
| 19 // InterfaceFactory<ViewManagerClient> implementation. | 19 // InterfaceFactory<ViewTreeClient> implementation. |
| 20 void Create(ApplicationConnection* connection, | 20 void Create(ApplicationConnection* connection, |
| 21 InterfaceRequest<ViewManagerClient> request) override { | 21 InterfaceRequest<ViewTreeClient> request) override { |
| 22 init_->OnCreate(request.Pass()); | 22 init_->OnCreate(request.Pass()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 ViewManagerInit* init_; | 26 ViewManagerInit* init_; |
| 27 | 27 |
| 28 DISALLOW_COPY_AND_ASSIGN(ClientFactory); | 28 DISALLOW_COPY_AND_ASSIGN(ClientFactory); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 ViewManagerInit::ViewManagerInit(ApplicationImpl* app, | 31 ViewManagerInit::ViewManagerInit(ApplicationImpl* app, |
| 32 ViewManagerDelegate* delegate, | 32 ViewManagerDelegate* delegate, |
| 33 ViewManagerRootClient* root_client) | 33 ViewManagerRootClient* root_client) |
| 34 : app_(app), | 34 : app_(app), |
| 35 connection_(nullptr), | 35 connection_(nullptr), |
| 36 delegate_(delegate), | 36 delegate_(delegate), |
| 37 client_factory_(new ClientFactory(this)) { | 37 client_factory_(new ClientFactory(this)) { |
| 38 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 38 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 39 request->url = mojo::String::From("mojo:view_manager"); | 39 request->url = mojo::String::From("mojo:view_manager"); |
| 40 connection_ = app_->ConnectToApplication(request.Pass()); | 40 connection_ = app_->ConnectToApplication(request.Pass()); |
| 41 | 41 |
| 42 // The view_manager will request a ViewManagerClient service for each | 42 // The view_manager will request a ViewTreeClient service for each |
| 43 // ViewManagerRoot created. | 43 // ViewManagerRoot created. |
| 44 connection_->AddService<ViewManagerClient>(client_factory_.get()); | 44 connection_->AddService<ViewTreeClient>(client_factory_.get()); |
| 45 connection_->ConnectToService(&view_manager_root_); | 45 connection_->ConnectToService(&view_manager_root_); |
| 46 | 46 |
| 47 if (root_client) { | 47 if (root_client) { |
| 48 root_client_binding_.reset(new Binding<ViewManagerRootClient>(root_client)); | 48 root_client_binding_.reset(new Binding<ViewManagerRootClient>(root_client)); |
| 49 ViewManagerRootClientPtr root_client_ptr; | 49 ViewManagerRootClientPtr root_client_ptr; |
| 50 root_client_binding_->Bind(GetProxy(&root_client_ptr)); | 50 root_client_binding_->Bind(GetProxy(&root_client_ptr)); |
| 51 view_manager_root_->SetViewManagerRootClient(root_client_ptr.Pass()); | 51 view_manager_root_->SetViewManagerRootClient(root_client_ptr.Pass()); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 ViewManagerInit::~ViewManagerInit() {} | 55 ViewManagerInit::~ViewManagerInit() {} |
| 56 | 56 |
| 57 void ViewManagerInit::OnCreate(InterfaceRequest<ViewManagerClient> request) { | 57 void ViewManagerInit::OnCreate(InterfaceRequest<ViewTreeClient> request) { |
| 58 // TODO(sky): straighten out lifetime. | 58 // TODO(sky): straighten out lifetime. |
| 59 ViewManager::Create(delegate_, request.Pass()); | 59 ViewManager::Create(delegate_, request.Pass()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace mojo | 62 } // namespace mojo |
| OLD | NEW |