| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_H_ | |
| 6 #define BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_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/threading/thread.h" | |
| 15 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
| 16 #include "blimp/client/core/session/assignment_source.h" | |
| 17 #include "blimp/client/core/session/network_event_observer.h" | |
| 18 #include "blimp/client/public/session/assignment.h" | |
| 19 #include "blimp/common/proto/blimp_message.pb.h" | |
| 20 #include "blimp/net/blimp_message_processor.h" | |
| 21 | |
| 22 namespace net { | |
| 23 class IPEndPoint; | |
| 24 } | |
| 25 | |
| 26 namespace blimp { | |
| 27 | |
| 28 class BlimpMessageProcessor; | |
| 29 class BlimpMessageThreadPipe; | |
| 30 class BlobChannelReceiver; | |
| 31 class BrowserConnectionHandler; | |
| 32 class ClientConnectionManager; | |
| 33 class HeliumBlobReceiverDelegate; | |
| 34 class ThreadPipeManager; | |
| 35 | |
| 36 namespace client { | |
| 37 | |
| 38 class ClientNetworkComponents; | |
| 39 class GeolocationFeature; | |
| 40 class NavigationFeature; | |
| 41 class ImeFeature; | |
| 42 class RenderWidgetFeature; | |
| 43 class SettingsFeature; | |
| 44 class TabControlFeature; | |
| 45 | |
| 46 // BlimpClientSession represents a single active session of Blimp on the client | |
| 47 // regardless of whether or not the client application is in the background or | |
| 48 // foreground. The only time this session is invalid is during initialization | |
| 49 // and shutdown of this particular client process (or Activity on Android). | |
| 50 // | |
| 51 // This session glues together the feature proxy components and the network | |
| 52 // layer. The network components must be interacted with on the IO thread. The | |
| 53 // feature proxies must be interacted with on the UI thread. | |
| 54 class BlimpClientSession | |
| 55 : public NetworkEventObserver, | |
| 56 public BlobImageSerializationProcessor::ErrorDelegate { | |
| 57 public: | |
| 58 explicit BlimpClientSession(const GURL& assigner_endpoint); | |
| 59 | |
| 60 // Uses the AssignmentSource to get an Assignment and then uses the assignment | |
| 61 // configuration to connect to the Blimplet. | |
| 62 // |client_auth_token| is the OAuth2 access token to use when querying | |
| 63 // for an assignment. This token needs the OAuth2 scope of userinfo.email and | |
| 64 // only needs to be an access token, not a refresh token. | |
| 65 void Connect(const std::string& client_auth_token); | |
| 66 | |
| 67 TabControlFeature* GetTabControlFeature() const; | |
| 68 NavigationFeature* GetNavigationFeature() const; | |
| 69 ImeFeature* GetImeFeature() const; | |
| 70 RenderWidgetFeature* GetRenderWidgetFeature() const; | |
| 71 SettingsFeature* GetSettingsFeature() const; | |
| 72 | |
| 73 // The AssignmentCallback for when an assignment is ready. This will trigger | |
| 74 // a connection to the engine. | |
| 75 virtual void ConnectWithAssignment(AssignmentRequestResult result, | |
| 76 const Assignment& assignment); | |
| 77 | |
| 78 protected: | |
| 79 ~BlimpClientSession() override; | |
| 80 | |
| 81 // Notified every time the AssignmentSource returns the result of an attempted | |
| 82 // assignment request. | |
| 83 virtual void OnAssignmentConnectionAttempted(AssignmentRequestResult result, | |
| 84 const Assignment& assignment); | |
| 85 | |
| 86 private: | |
| 87 void RegisterFeatures(); | |
| 88 | |
| 89 // Terminates the active connection held by |net_connections_| on the IO | |
| 90 // thread. Should be called on the main thread. | |
| 91 void DropConnection(); | |
| 92 | |
| 93 // NetworkEventObserver implementation. | |
| 94 void OnConnected() override; | |
| 95 void OnDisconnected(int result) override; | |
| 96 | |
| 97 // BlobImageSerializationProcessor::ErrorDelegate implementation. | |
| 98 void OnImageDecodeError() override; | |
| 99 | |
| 100 base::Thread io_thread_; | |
| 101 | |
| 102 // Receives blob BlimpMessages and relays them to BlobChannelReceiver. | |
| 103 // Owned by BlobChannelReceiver, therefore stored as a raw pointer here. | |
| 104 HeliumBlobReceiverDelegate* blob_delegate_ = nullptr; | |
| 105 | |
| 106 // Retrieves and decodes image data from |blob_receiver_|. Must outlive | |
| 107 // |blob_receiver_|. | |
| 108 BlobImageSerializationProcessor blob_image_processor_; | |
| 109 | |
| 110 std::unique_ptr<BlobChannelReceiver> blob_receiver_; | |
| 111 std::unique_ptr<GeolocationFeature> geolocation_feature_; | |
| 112 std::unique_ptr<TabControlFeature> tab_control_feature_; | |
| 113 std::unique_ptr<NavigationFeature> navigation_feature_; | |
| 114 std::unique_ptr<ImeFeature> ime_feature_; | |
| 115 std::unique_ptr<RenderWidgetFeature> render_widget_feature_; | |
| 116 std::unique_ptr<SettingsFeature> settings_feature_; | |
| 117 | |
| 118 // The AssignmentSource is used when the user of BlimpClientSession calls | |
| 119 // Connect() to get a valid assignment and later connect to the engine. | |
| 120 std::unique_ptr<AssignmentSource> assignment_source_; | |
| 121 | |
| 122 // Container struct for network components. | |
| 123 // Must be deleted on the IO thread. | |
| 124 std::unique_ptr<ClientNetworkComponents> net_components_; | |
| 125 | |
| 126 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; | |
| 127 | |
| 128 base::WeakPtrFactory<BlimpClientSession> weak_factory_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(BlimpClientSession); | |
| 131 }; | |
| 132 | |
| 133 } // namespace client | |
| 134 } // namespace blimp | |
| 135 | |
| 136 #endif // BLIMP_CLIENT_SESSION_BLIMP_CLIENT_SESSION_H_ | |
| OLD | NEW |