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_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
6 #define BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/single_thread_task_runner.h" | |
15 #include "base/threading/thread.h" | |
16 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
17 #include "blimp/client/core/session/client_network_components.h" | |
18 #include "blimp/client/core/session/connection_status.h" | |
19 #include "blimp/client/core/session/identity_source.h" | |
20 #include "blimp/client/core/settings/blimp_settings_delegate.h" | |
21 #include "blimp/client/public/blimp_client_context.h" | |
22 #include "blimp/client/public/contents/blimp_contents.h" | |
23 #include "blimp/client/public/session/assignment.h" | |
24 #include "blimp/net/thread_pipe_manager.h" | |
25 #include "url/gurl.h" | |
26 | |
27 namespace blimp { | |
28 namespace client { | |
29 | |
30 class BlimpCompositorDependencies; | |
31 class BlimpContentsManager; | |
32 class BlobChannelFeature; | |
33 class CompositorDependencies; | |
34 class GeolocationFeature; | |
35 class ImeFeature; | |
36 class NavigationFeature; | |
37 class RenderWidgetFeature; | |
38 class SettingsFeature; | |
39 class TabControlFeature; | |
40 | |
41 // BlimpClientContextImpl is the implementation of the main context-class for | |
42 // the blimp client. | |
43 class BlimpClientContextImpl | |
44 : public BlimpClientContext, | |
45 public BlimpSettingsDelegate, | |
46 public BlobImageSerializationProcessor::ErrorDelegate { | |
47 public: | |
48 // The |io_thread_task_runner| must be the task runner to use for IO | |
49 // operations. | |
50 // The |file_thread_task_runner| must be the task runner to use for file | |
51 // operations. | |
52 BlimpClientContextImpl( | |
53 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | |
54 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | |
55 std::unique_ptr<CompositorDependencies> compositor_dependencies); | |
56 ~BlimpClientContextImpl() override; | |
57 | |
58 // BlimpClientContext implementation. | |
59 void SetDelegate(BlimpClientContextDelegate* delegate) override; | |
60 std::unique_ptr<BlimpContents> CreateBlimpContents( | |
61 gfx::NativeWindow window) override; | |
62 void Connect() override; | |
63 void ConnectWithAssignment(const Assignment& assignment) override; | |
64 | |
65 protected: | |
66 // Returns the URL to use for connections to the assigner. Used to construct | |
67 // the AssignmentSource. | |
68 virtual GURL GetAssignerURL(); | |
69 | |
70 // BlimpSettingsDelegate implementation. | |
71 IdentitySource* GetIdentitySource() override; | |
72 ConnectionStatus* GetConnectionStatus() override; | |
73 | |
74 private: | |
75 // Called when an OAuth2 token is received. Will then ask the | |
76 // AssignmentSource for an Assignment with this token. | |
77 virtual void OnAuthTokenReceived(const std::string& client_auth_token); | |
78 | |
79 // Called when the AssignmentSource is finished getting an Assignment. Will | |
80 // then call |ConnectWithAssignment| to initiate the actual connection. | |
81 virtual void OnAssignmentReceived(AssignmentRequestResult result, | |
82 const Assignment& assignment); | |
83 | |
84 void RegisterFeatures(); | |
85 void InitializeSettings(); | |
86 | |
87 // Terminates the active connection held by |net_connections_|. | |
88 // May be called on any thread. | |
89 void DropConnection(); | |
90 | |
91 // Create IdentitySource which provides user sign in states and OAuth2 token | |
92 // service. | |
93 void CreateIdentitySource(); | |
94 | |
95 // BlobImageSerializationProcessor::ErrorDelegate implementation. | |
96 void OnImageDecodeError() override; | |
97 | |
98 // Provides functionality from the embedder. | |
99 BlimpClientContextDelegate* delegate_ = nullptr; | |
100 | |
101 // The task runner to use for IO operations. | |
102 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; | |
103 | |
104 // The task runner to use for file operations. | |
105 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner_; | |
106 | |
107 // The AssignmentSource is used when the user of BlimpClientContextImpl calls | |
108 // Connect() to get a valid assignment and later connect to the engine. | |
109 std::unique_ptr<AssignmentSource> assignment_source_; | |
110 | |
111 // A set of dependencies required by all BlimpCompositor instances. | |
112 std::unique_ptr<BlimpCompositorDependencies> blimp_compositor_dependencies_; | |
113 | |
114 // Features to handle all incoming and outgoing protobuf messages. | |
115 std::unique_ptr<BlobChannelFeature> blob_channel_feature_; | |
116 std::unique_ptr<GeolocationFeature> geolocation_feature_; | |
117 std::unique_ptr<ImeFeature> ime_feature_; | |
118 std::unique_ptr<NavigationFeature> navigation_feature_; | |
119 std::unique_ptr<RenderWidgetFeature> render_widget_feature_; | |
120 std::unique_ptr<SettingsFeature> settings_feature_; | |
121 std::unique_ptr<TabControlFeature> tab_control_feature_; | |
122 | |
123 std::unique_ptr<BlimpContentsManager> blimp_contents_manager_; | |
124 | |
125 // Container struct for network components. | |
126 // Must be deleted on the IO thread. | |
127 std::unique_ptr<ClientNetworkComponents> net_components_; | |
128 | |
129 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; | |
130 | |
131 // Provide OAuth2 token and propagate account sign in states change. | |
132 std::unique_ptr<IdentitySource> identity_source_; | |
133 | |
134 // Connection status to the engine. | |
135 ConnectionStatus connection_status_; | |
136 | |
137 base::WeakPtrFactory<BlimpClientContextImpl> weak_factory_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImpl); | |
140 }; | |
141 | |
142 } // namespace client | |
143 } // namespace blimp | |
144 | |
145 #endif // BLIMP_CLIENT_CORE_BLIMP_CLIENT_CONTEXT_IMPL_H_ | |
OLD | NEW |