| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(ajwong): We need to come up with a better description of the | 5 // TODO(ajwong): We need to come up with a better description of the |
| 6 // responsibilities for each thread. | 6 // responsibilities for each thread. |
| 7 | 7 |
| 8 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ | 8 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ |
| 9 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ | 9 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "ppapi/c/dev/ppp_policy_update_dev.h" | 15 #include "ppapi/c/dev/ppp_policy_update_dev.h" |
| 16 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_rect.h" | 17 #include "ppapi/c/pp_rect.h" |
| 18 #include "ppapi/c/pp_resource.h" | 18 #include "ppapi/c/pp_resource.h" |
| 19 #include "ppapi/c/pp_var.h" | 19 #include "ppapi/c/pp_var.h" |
| 20 #include "ppapi/cpp/var.h" | 20 #include "ppapi/cpp/var.h" |
| 21 #include "ppapi/cpp/private/instance_private.h" | 21 #include "ppapi/cpp/private/instance_private.h" |
| 22 #include "remoting/client/client_context.h" | 22 #include "remoting/client/client_context.h" |
| 23 #include "remoting/client/plugin/chromoting_scriptable_object.h" | 23 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
| 24 #include "remoting/client/plugin/pepper_client_logger.h" | |
| 25 #include "remoting/protocol/connection_to_host.h" | 24 #include "remoting/protocol/connection_to_host.h" |
| 26 | 25 |
| 27 class MessageLoop; | |
| 28 | |
| 29 namespace base { | 26 namespace base { |
| 30 class Thread; | 27 class Thread; |
| 31 } // namespace base | 28 } // namespace base |
| 32 | 29 |
| 33 namespace pp { | 30 namespace pp { |
| 34 class InputEvent; | 31 class InputEvent; |
| 35 class Module; | 32 class Module; |
| 36 } // namespace pp | 33 } // namespace pp |
| 37 | 34 |
| 38 namespace remoting { | 35 namespace remoting { |
| 39 | 36 |
| 40 namespace protocol { | 37 namespace protocol { |
| 41 class ConnectionToHost; | 38 class ConnectionToHost; |
| 42 } // namespace protocol | 39 } // namespace protocol |
| 43 | 40 |
| 44 class ChromotingClient; | 41 class ChromotingClient; |
| 45 class ChromotingStats; | 42 class ChromotingStats; |
| 46 class ClientContext; | 43 class ClientContext; |
| 47 class InputHandler; | 44 class InputHandler; |
| 48 class JingleThread; | 45 class JingleThread; |
| 49 class PepperView; | 46 class PepperView; |
| 50 class PepperViewProxy; | 47 class PepperViewProxy; |
| 51 class RectangleUpdateDecoder; | 48 class RectangleUpdateDecoder; |
| 49 class TaskThreadProxy; |
| 52 | 50 |
| 53 struct ClientConfig; | 51 struct ClientConfig; |
| 54 | 52 |
| 55 namespace protocol { | 53 namespace protocol { |
| 56 class HostConnection; | 54 class HostConnection; |
| 57 } // namespace protocol | 55 } // namespace protocol |
| 58 | 56 |
| 59 class ChromotingInstance : public pp::InstancePrivate { | 57 class ChromotingInstance : public pp::InstancePrivate { |
| 60 public: | 58 public: |
| 61 // The mimetype for which this plugin is registered. | 59 // The mimetype for which this plugin is registered. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 void Connect(const ClientConfig& config); | 79 void Connect(const ClientConfig& config); |
| 82 void Disconnect(); | 80 void Disconnect(); |
| 83 | 81 |
| 84 // Called by ChromotingScriptableObject to provide username and password. | 82 // Called by ChromotingScriptableObject to provide username and password. |
| 85 void SubmitLoginInfo(const std::string& username, | 83 void SubmitLoginInfo(const std::string& username, |
| 86 const std::string& password); | 84 const std::string& password); |
| 87 | 85 |
| 88 // Called by ChromotingScriptableObject to set scale-to-fit. | 86 // Called by ChromotingScriptableObject to set scale-to-fit. |
| 89 void SetScaleToFit(bool scale_to_fit); | 87 void SetScaleToFit(bool scale_to_fit); |
| 90 | 88 |
| 91 void Log(int severity, const char* format, ...); | |
| 92 void VLog(int verboselevel, const char* format, ...); | |
| 93 | |
| 94 // Return statistics record by ChromotingClient. | 89 // Return statistics record by ChromotingClient. |
| 95 // If no connection is currently active then NULL will be returned. | 90 // If no connection is currently active then NULL will be returned. |
| 96 ChromotingStats* GetStats(); | 91 ChromotingStats* GetStats(); |
| 97 | 92 |
| 98 void ReleaseAllKeys(); | 93 void ReleaseAllKeys(); |
| 99 | 94 |
| 100 bool DoScaling() const { return scale_to_fit_; } | 95 bool DoScaling() const { return scale_to_fit_; } |
| 101 | 96 |
| 97 // A Log Message Handler that is called after each LOG message has been |
| 98 // processed. This must be of type LogMessageHandlerFunction defined in |
| 99 // base/logging.h. |
| 100 static bool LogToUI(int severity, const char* file, int line, |
| 101 size_t message_start, const std::string& str); |
| 102 private: | 102 private: |
| 103 FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup); | 103 FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup); |
| 104 | 104 |
| 105 static PPP_PolicyUpdate_Dev kPolicyUpdatedInterface; | 105 static PPP_PolicyUpdate_Dev kPolicyUpdatedInterface; |
| 106 static void PolicyUpdatedThunk(PP_Instance pp_instance, | 106 static void PolicyUpdatedThunk(PP_Instance pp_instance, |
| 107 PP_Var pp_policy_json); | 107 PP_Var pp_policy_json); |
| 108 void SubscribeToNatTraversalPolicy(); | 108 void SubscribeToNatTraversalPolicy(); |
| 109 bool IsNatTraversalAllowed(const std::string& policy_json); | 109 bool IsNatTraversalAllowed(const std::string& policy_json); |
| 110 void HandlePolicyUpdate(const std::string policy_json); | 110 void HandlePolicyUpdate(const std::string policy_json); |
| 111 | 111 |
| 112 void ProcessLogToUI(const std::string& message); |
| 113 |
| 112 bool initialized_; | 114 bool initialized_; |
| 113 | 115 |
| 114 ClientContext context_; | 116 ClientContext context_; |
| 115 scoped_ptr<protocol::ConnectionToHost> host_connection_; | 117 scoped_ptr<protocol::ConnectionToHost> host_connection_; |
| 116 scoped_ptr<PepperView> view_; | 118 scoped_ptr<PepperView> view_; |
| 117 | 119 |
| 118 // True if scale to fit is enabled. | 120 // True if scale to fit is enabled. |
| 119 bool scale_to_fit_; | 121 bool scale_to_fit_; |
| 120 | 122 |
| 123 // A refcounted class to perform thread-switching for logging tasks. |
| 124 scoped_refptr<TaskThreadProxy> log_proxy_; |
| 125 |
| 121 // PepperViewProxy is refcounted and used to interface between chromoting | 126 // PepperViewProxy is refcounted and used to interface between chromoting |
| 122 // objects and PepperView and perform thread switching. It wraps around | 127 // objects and PepperView and perform thread switching. It wraps around |
| 123 // |view_| and receives method calls on chromoting threads. These method | 128 // |view_| and receives method calls on chromoting threads. These method |
| 124 // calls are then delegates on the pepper thread. During destruction of | 129 // calls are then delegates on the pepper thread. During destruction of |
| 125 // ChromotingInstance we need to detach PepperViewProxy from PepperView since | 130 // ChromotingInstance we need to detach PepperViewProxy from PepperView since |
| 126 // both ChromotingInstance and PepperView are destroyed and there will be | 131 // both ChromotingInstance and PepperView are destroyed and there will be |
| 127 // outstanding tasks on the pepper message loo. | 132 // outstanding tasks on the pepper message loop. |
| 128 scoped_refptr<PepperViewProxy> view_proxy_; | 133 scoped_refptr<PepperViewProxy> view_proxy_; |
| 129 scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_; | 134 scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_; |
| 130 scoped_ptr<InputHandler> input_handler_; | 135 scoped_ptr<InputHandler> input_handler_; |
| 131 scoped_ptr<ChromotingClient> client_; | 136 scoped_ptr<ChromotingClient> client_; |
| 132 | 137 |
| 133 // XmppProxy is a refcounted interface used to perform thread-switching and | 138 // XmppProxy is a refcounted interface used to perform thread-switching and |
| 134 // detaching between objects whose lifetimes are controlled by pepper, and | 139 // detaching between objects whose lifetimes are controlled by pepper, and |
| 135 // jingle_glue objects. This is used when if we start a sandboxed jingle | 140 // jingle_glue objects. This is used when if we start a sandboxed jingle |
| 136 // connection. | 141 // connection. |
| 137 scoped_refptr<PepperXmppProxy> xmpp_proxy_; | 142 scoped_refptr<PepperXmppProxy> xmpp_proxy_; |
| 138 | 143 |
| 139 PepperClientLogger logger_; | |
| 140 | |
| 141 // JavaScript interface to control this instance. | 144 // JavaScript interface to control this instance. |
| 142 // This wraps a ChromotingScriptableObject in a pp::Var. | 145 // This wraps a ChromotingScriptableObject in a pp::Var. |
| 143 pp::Var instance_object_; | 146 pp::Var instance_object_; |
| 144 | 147 |
| 145 // Controls if this instance of the plugin should attempt to bridge | 148 // Controls if this instance of the plugin should attempt to bridge |
| 146 // firewalls. | 149 // firewalls. |
| 147 bool enable_client_nat_traversal_; | 150 bool enable_client_nat_traversal_; |
| 148 | 151 |
| 149 // True when the initial policy is received. Used to avoid taking | 152 // True when the initial policy is received. Used to avoid taking |
| 150 // action before the browser has informed the plugin about its policy | 153 // action before the browser has informed the plugin about its policy |
| 151 // settings. | 154 // settings. |
| 152 bool initial_policy_received_; | 155 bool initial_policy_received_; |
| 153 | 156 |
| 154 ScopedRunnableMethodFactory<ChromotingInstance> task_factory_; | 157 ScopedRunnableMethodFactory<ChromotingInstance> task_factory_; |
| 155 scoped_ptr<Task> delayed_connect_; | 158 scoped_ptr<Task> delayed_connect_; |
| 156 | 159 |
| 157 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance); | 160 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance); |
| 158 }; | 161 }; |
| 159 | 162 |
| 160 } // namespace remoting | 163 } // namespace remoting |
| 161 | 164 |
| 162 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ | 165 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_ |
| OLD | NEW |