Chromium Code Reviews| 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 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ | 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ | 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "mojo/common/binding_set.h" | 14 #include "mojo/common/binding_set.h" |
| 15 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
| 16 #include "mojo/services/ui/views/interfaces/view_associates.mojom.h" | 16 #include "mojo/services/ui/views/interfaces/view_associates.mojom.h" |
| 17 | 17 |
| 18 namespace view_manager { | 18 namespace view_manager { |
| 19 | 19 |
| 20 namespace test { | |
| 21 class ViewAssociateTableTest; | |
| 22 } | |
| 23 | |
| 20 // Maintains a table of all connected view associates. | 24 // Maintains a table of all connected view associates. |
| 21 class ViewAssociateTable { | 25 class ViewAssociateTable { |
| 26 friend class test::ViewAssociateTableTest; | |
|
jeffbrown
2016/05/11 23:44:20
should be in the private section, but I think you
mikejurka
2016/05/16 23:35:18
why should it be in the private section?
| |
| 27 | |
| 22 public: | 28 public: |
| 23 using AssociateConnectionErrorCallback = | 29 using AssociateConnectionErrorCallback = |
| 24 base::Callback<void(const std::string&)>; | 30 base::Callback<void(const std::string&)>; |
| 25 | 31 |
| 26 ViewAssociateTable(); | 32 ViewAssociateTable(); |
| 27 ~ViewAssociateTable(); | 33 ~ViewAssociateTable(); |
| 28 | 34 |
| 29 // Begins connecting to the view associates. | 35 // Begins connecting to the view associates. |
| 30 // Invokes |connection_error_callback| if an associate connection fails | 36 // Invokes |connection_error_callback| if an associate connection fails |
| 31 // and provides the associate's url. | 37 // and provides the associate's url. |
| 32 void ConnectAssociates( | 38 void ConnectAssociates( |
| 33 mojo::ApplicationImpl* app_impl, | 39 mojo::ApplicationImpl* app_impl, |
| 34 mojo::ui::ViewInspector* inspector, | 40 mojo::ui::ViewInspector* inspector, |
| 35 const std::vector<std::string>& urls, | 41 const std::vector<std::string>& urls, |
| 36 const AssociateConnectionErrorCallback& connection_error_callback); | 42 const AssociateConnectionErrorCallback& connection_error_callback); |
| 37 | 43 |
| 44 void RegisterViewAssociate( | |
| 45 mojo::ui::ViewInspector* inspector, | |
| 46 mojo::ui::ViewAssociatePtr associate, | |
| 47 const AssociateConnectionErrorCallback& connection_error_callback); | |
| 48 | |
| 38 // Connects to services offered by the view associates. | 49 // Connects to services offered by the view associates. |
| 39 void ConnectToViewService(mojo::ui::ViewTokenPtr view_token, | 50 void ConnectToViewService(mojo::ui::ViewTokenPtr view_token, |
| 40 const mojo::String& service_name, | 51 const mojo::String& service_name, |
| 41 mojo::ScopedMessagePipeHandle client_handle); | 52 mojo::ScopedMessagePipeHandle client_handle); |
| 42 void ConnectToViewTreeService(mojo::ui::ViewTreeTokenPtr view_tree_token, | 53 void ConnectToViewTreeService(mojo::ui::ViewTreeTokenPtr view_tree_token, |
| 43 const mojo::String& service_name, | 54 const mojo::String& service_name, |
| 44 mojo::ScopedMessagePipeHandle client_handle); | 55 mojo::ScopedMessagePipeHandle client_handle); |
| 45 | 56 |
| 46 void OnConnected(uint32_t index, mojo::ui::ViewAssociateInfoPtr info); | 57 void OnConnected(uint32_t index, mojo::ui::ViewAssociateInfoPtr info); |
| 47 | 58 |
| 48 void CompleteDeferredWork(); | 59 void CompleteDeferredWork(); |
| 49 | 60 |
| 50 private: | 61 private: |
| 51 struct AssociateData { | 62 struct AssociateData { |
| 52 AssociateData(const std::string& url, mojo::ui::ViewInspector* inspector); | 63 AssociateData(mojo::ui::ViewAssociatePtr associate, |
| 64 mojo::ui::ViewInspector* inspector); | |
| 53 ~AssociateData(); | 65 ~AssociateData(); |
| 54 | 66 |
| 55 const std::string url; | |
| 56 mojo::ui::ViewAssociatePtr associate; | 67 mojo::ui::ViewAssociatePtr associate; |
| 57 mojo::ui::ViewAssociateInfoPtr info; | 68 mojo::ui::ViewAssociateInfoPtr info; |
| 58 mojo::Binding<mojo::ui::ViewInspector> inspector_binding; | 69 mojo::Binding<mojo::ui::ViewInspector> inspector_binding; |
| 59 }; | 70 }; |
| 60 | 71 |
| 72 void OnAssociateConnectionError(AssociateData* associate_data); | |
| 73 | |
| 61 std::vector<std::unique_ptr<AssociateData>> associates_; | 74 std::vector<std::unique_ptr<AssociateData>> associates_; |
| 62 | 75 |
| 63 uint32_t pending_connection_count_ = 0u; | 76 uint32_t pending_connection_count_ = 0u; |
| 64 std::vector<base::Closure> deferred_work_; | 77 std::vector<base::Closure> deferred_work_; |
| 65 | 78 |
| 66 DISALLOW_COPY_AND_ASSIGN(ViewAssociateTable); | 79 DISALLOW_COPY_AND_ASSIGN(ViewAssociateTable); |
| 67 }; | 80 }; |
| 68 | 81 |
| 69 } // namespace view_manager | 82 } // namespace view_manager |
| 70 | 83 |
| 71 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ | 84 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_ASSOCIATE_TABLE_H_ |
| OLD | NEW |