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

Side by Side Diff: services/ui/view_manager/view_associate_table.h

Issue 1949233002: Create a RegisterViewAssociate method in ViewManager (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add tests to mojo tests Created 4 years, 7 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 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 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h"
17 18
18 namespace view_manager { 19 namespace view_manager {
19 20
20 // Maintains a table of all connected view associates. 21 // Maintains a table of all connected view associates.
21 class ViewAssociateTable { 22 class ViewAssociateTable : public mojo::ui::ViewAssociateOwner {
22 public: 23 public:
23 using AssociateConnectionErrorCallback = 24 using AssociateConnectionErrorCallback =
24 base::Callback<void(const std::string&)>; 25 base::Callback<void(const std::string&)>;
25 26
26 ViewAssociateTable(); 27 ViewAssociateTable();
27 ~ViewAssociateTable(); 28 ~ViewAssociateTable() override;
28 29
29 // Begins connecting to the view associates. 30 void RegisterViewAssociate(
30 // Invokes |connection_error_callback| if an associate connection fails
31 // and provides the associate's url.
32 void ConnectAssociates(
33 mojo::ApplicationImpl* app_impl,
34 mojo::ui::ViewInspector* inspector, 31 mojo::ui::ViewInspector* inspector,
35 const std::vector<std::string>& urls, 32 mojo::ui::ViewAssociatePtr associate,
36 const AssociateConnectionErrorCallback& connection_error_callback); 33 mojo::InterfaceRequest<mojo::ui::ViewAssociateOwner> view_associate_owner,
34 const mojo::String& label);
35
36 void FinishedRegisteringViewAssociates();
37 37
38 // Connects to services offered by the view associates. 38 // Connects to services offered by the view associates.
39 void ConnectToViewService(mojo::ui::ViewTokenPtr view_token, 39 void ConnectToViewService(mojo::ui::ViewTokenPtr view_token,
40 const mojo::String& service_name, 40 const mojo::String& service_name,
41 mojo::ScopedMessagePipeHandle client_handle); 41 mojo::ScopedMessagePipeHandle client_handle);
42 void ConnectToViewTreeService(mojo::ui::ViewTreeTokenPtr view_tree_token, 42 void ConnectToViewTreeService(mojo::ui::ViewTreeTokenPtr view_tree_token,
43 const mojo::String& service_name, 43 const mojo::String& service_name,
44 mojo::ScopedMessagePipeHandle client_handle); 44 mojo::ScopedMessagePipeHandle client_handle);
45 45
46 void OnConnected(uint32_t index, mojo::ui::ViewAssociateInfoPtr info); 46 void OnConnected(uint32_t index, mojo::ui::ViewAssociateInfoPtr info);
47 47
48 void CompleteDeferredWork(); 48 size_t associate_count();
49 49
50 private: 50 private:
51 struct AssociateData { 51 struct AssociateData {
52 AssociateData(const std::string& url, mojo::ui::ViewInspector* inspector); 52 AssociateData(const std::string& label,
53 mojo::ui::ViewAssociatePtr associate,
54 mojo::ui::ViewAssociateOwner* associate_owner_impl,
55 mojo::ui::ViewInspector* inspector);
53 ~AssociateData(); 56 ~AssociateData();
54 57
55 const std::string url; 58 void BindOwner(mojo::InterfaceRequest<mojo::ui::ViewAssociateOwner>
59 view_associate_owner_request);
60
61 const std::string label;
56 mojo::ui::ViewAssociatePtr associate; 62 mojo::ui::ViewAssociatePtr associate;
63 mojo::Binding<mojo::ui::ViewAssociateOwner> associate_owner;
57 mojo::ui::ViewAssociateInfoPtr info; 64 mojo::ui::ViewAssociateInfoPtr info;
58 mojo::Binding<mojo::ui::ViewInspector> inspector_binding; 65 mojo::Binding<mojo::ui::ViewInspector> inspector_binding;
59 }; 66 };
60 67
68 bool RemoveAssociateData(AssociateData* associate_data, std::string& label);
69 void CompleteDeferredWorkIfReady();
70 void OnAssociateOwnerConnectionError(AssociateData* associate_data);
71 void OnAssociateConnectionError(AssociateData* associate_data);
72
61 std::vector<std::unique_ptr<AssociateData>> associates_; 73 std::vector<std::unique_ptr<AssociateData>> associates_;
62 74
63 uint32_t pending_connection_count_ = 0u; 75 uint32_t pending_connection_count_ = 0u;
76 bool waiting_to_register_associates_ = true;
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_
OLDNEW
« no previous file with comments | « services/ui/view_manager/tests/view_manager_test_base.cc ('k') | services/ui/view_manager/view_associate_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698