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