OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BLIMP_CLIENT_CORE_CONTEXT_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
6 #define BLIMP_CLIENT_CORE_CONTEXT_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 #include <unordered_map> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/single_thread_task_runner.h" | |
16 #include "base/threading/thread.h" | |
17 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
18 #include "blimp/client/core/context/assignment_fetcher.h" | |
19 #include "blimp/client/core/session/client_network_components.h" | |
20 #include "blimp/client/core/session/connection_status.h" | |
21 #include "blimp/client/core/settings/blimp_settings_delegate.h" | |
22 #include "blimp/client/public/blimp_client_context.h" | |
23 #include "blimp/client/public/contents/blimp_contents.h" | |
24 #include "blimp/client/public/session/assignment.h" | |
25 #include "blimp/net/pipe_manager.h" | |
26 #include "url/gurl.h" | |
27 | |
28 namespace blimp { | |
29 namespace client { | |
30 | |
31 class BlimpCompositorDependencies; | |
32 class BlimpContentsManager; | |
33 class BlobChannelFeature; | |
34 class CompositorDependencies; | |
35 class GeolocationFeature; | |
36 class ImeFeature; | |
37 class NavigationFeature; | |
38 class RenderWidgetFeature; | |
39 class SettingsFeature; | |
40 class Settings; | |
41 class TabControlFeature; | |
42 | |
43 // BlimpClientContextImpl is the implementation of the main context-class for | |
44 // the blimp client. | |
45 class BlimpClientContextImpl | |
46 : public BlimpClientContext, | |
47 public BlimpSettingsDelegate, | |
48 public BlobImageSerializationProcessor::ErrorDelegate, | |
49 public NetworkEventObserver { | |
50 public: | |
51 // The |io_thread_task_runner| must be the task runner to use for IO | |
52 // operations. | |
53 // The |file_thread_task_runner| must be the task runner to use for file | |
54 // operations. | |
55 // |pipe_manager| is an optional override. If it's null, a default pipe | |
56 // manager will be created. | |
57 BlimpClientContextImpl( | |
58 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | |
59 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
60 std::unique_ptr<CompositorDependencies> compositor_dependencies, | |
61 std::unique_ptr<Settings> settings, | |
62 std::unique_ptr<PipeManager> pipe_manager); | |
63 ~BlimpClientContextImpl() override; | |
64 | |
65 // BlimpClientContext implementation. | |
66 void SetDelegate(BlimpClientContextDelegate* delegate) override; | |
67 std::unique_ptr<BlimpContents> CreateBlimpContents( | |
68 gfx::NativeWindow window) override; | |
69 void Connect() override; | |
70 void ConnectWithAssignment(const Assignment& assignment) override; | |
71 | |
72 // Creates a data object containing data about Blimp to be used for feedback. | |
73 std::unordered_map<std::string, std::string> CreateFeedbackData(); | |
74 | |
75 protected: | |
76 // Returns the URL to use for connections to the assigner. Used to construct | |
77 // the AssignmentSource. | |
78 virtual GURL GetAssignerURL(); | |
79 | |
80 // BlimpSettingsDelegate implementation. | |
81 IdentitySource* GetIdentitySource() override; | |
82 ConnectionStatus* GetConnectionStatus() override; | |
83 | |
84 Settings* settings() { return settings_.get(); } | |
85 | |
86 private: | |
87 // Called when the AssignmentSource is finished getting an Assignment. Will | |
88 // then call |ConnectWithAssignment| to initiate the actual connection. | |
89 virtual void OnAssignmentReceived(AssignmentRequestResult result, | |
90 const Assignment& assignment); | |
91 | |
92 void RegisterFeatures(); | |
93 void InitializeSettings(); | |
94 | |
95 // Terminates the active connection held by |net_connections_|. | |
96 // May be called on any thread. | |
97 void DropConnection(); | |
98 | |
99 // BlobImageSerializationProcessor::ErrorDelegate implementation. | |
100 void OnImageDecodeError() override; | |
101 | |
102 // NetworkEventObserver implementation. | |
103 void OnConnected() override; | |
104 void OnDisconnected(int result) override; | |
105 | |
106 // Provides functionality from the embedder. | |
107 BlimpClientContextDelegate* delegate_ = nullptr; | |
108 | |
109 // The task runner to use for IO operations. | |
110 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; | |
111 | |
112 // The task runner to use for file operations. | |
113 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | |
114 | |
115 // A set of dependencies required by all BlimpCompositor instances. | |
116 std::unique_ptr<BlimpCompositorDependencies> blimp_compositor_dependencies_; | |
117 | |
118 // Through this settings are set and retrieved. This should be initialized | |
119 // before settings_feature_. | |
120 std::unique_ptr<Settings> settings_; | |
121 | |
122 // Features to handle all incoming and outgoing protobuf messages. | |
123 std::unique_ptr<BlobChannelFeature> blob_channel_feature_; | |
124 std::unique_ptr<GeolocationFeature> geolocation_feature_; | |
125 std::unique_ptr<ImeFeature> ime_feature_; | |
126 std::unique_ptr<NavigationFeature> navigation_feature_; | |
127 std::unique_ptr<RenderWidgetFeature> render_widget_feature_; | |
128 std::unique_ptr<SettingsFeature> settings_feature_; | |
129 std::unique_ptr<TabControlFeature> tab_control_feature_; | |
130 | |
131 std::unique_ptr<BlimpContentsManager> blimp_contents_manager_; | |
132 | |
133 // Container struct for network components. | |
134 // Must be deleted on the IO thread. | |
135 std::unique_ptr<ClientNetworkComponents> net_components_; | |
136 | |
137 std::unique_ptr<PipeManager> pipe_manager_; | |
138 | |
139 std::unique_ptr<AssignmentFetcher> assignment_fetcher_; | |
140 | |
141 // Connection status to the engine. | |
142 ConnectionStatus connection_status_; | |
143 | |
144 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); | |
147 }; | |
148 | |
149 } // namespace client | |
150 } // namespace blimp | |
151 | |
152 #endif // BLIMP_CLIENT_CORE_CONTEXT_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
OLD | NEW |