Convert Chromoting logging to appear in client debug-info div.
[chromium-blink-merge.git] / remoting / client / plugin / chromoting_instance.h
blob45d250b86a909b259f46aa0c0e4d9c346bc4d4b3
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
3 // found in the LICENSE file.
5 // TODO(ajwong): We need to come up with a better description of the
6 // responsibilities for each thread.
8 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_
9 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_
11 #include <string>
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/pp_rect.h"
17 #include "ppapi/c/pp_resource.h"
18 #include "ppapi/cpp/instance.h"
19 #include "ppapi/cpp/var.h"
20 #include "remoting/client/client_context.h"
21 #include "remoting/client/plugin/chromoting_scriptable_object.h"
22 #include "remoting/client/plugin/pepper_client_logger.h"
23 #include "remoting/protocol/connection_to_host.h"
25 class MessageLoop;
26 struct PP_InputEvent;
28 namespace base {
29 class Thread;
30 } // namespace base
32 namespace pp {
33 class Module;
34 } // namespace pp
36 namespace remoting {
38 namespace protocol {
39 class ConnectionToHost;
40 } // namespace protocol
42 class ChromotingClient;
43 class ChromotingStats;
44 class ClientContext;
45 class InputHandler;
46 class JingleThread;
47 class PepperView;
48 class PepperViewProxy;
49 class RectangleUpdateDecoder;
51 struct ClientConfig;
53 namespace protocol {
54 class HostConnection;
55 } // namespace protocol
57 class ChromotingInstance : public pp::Instance {
58 public:
59 // The mimetype for which this plugin is registered.
60 static const char *kMimeType;
62 explicit ChromotingInstance(PP_Instance instance);
63 virtual ~ChromotingInstance();
65 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
66 virtual void Connect(const ClientConfig& config);
67 virtual void ConnectSandboxed(const std::string& your_jid,
68 const std::string& host_jid,
69 const std::string& nonce);
70 virtual bool HandleInputEvent(const PP_InputEvent& event);
71 virtual void Disconnect();
72 virtual pp::Var GetInstanceObject();
73 virtual void ViewChanged(const pp::Rect& position, const pp::Rect& clip);
75 // pp::Instance interface.
76 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip)
77 OVERRIDE;
79 // Convenience wrapper to get the ChromotingScriptableObject.
80 ChromotingScriptableObject* GetScriptableObject();
82 // Called by ChromotingScriptableObject to provide username and password.
83 void SubmitLoginInfo(const std::string& username,
84 const std::string& password);
86 // Called by ChromotingScriptableObject to set scale-to-fit.
87 void SetScaleToFit(bool scale_to_fit);
89 void Log(int severity, const char* format, ...);
90 void VLog(int verboselevel, const char* format, ...);
92 // Return statistics record by ChromotingClient.
93 // If no connection is currently active then NULL will be returned.
94 ChromotingStats* GetStats();
96 private:
97 FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
99 bool initialized_;
101 ClientContext context_;
102 scoped_ptr<protocol::ConnectionToHost> host_connection_;
103 scoped_ptr<PepperView> view_;
105 // PepperViewProxy is refcounted and used to interface between chromoting
106 // objects and PepperView and perform thread switching. It wraps around
107 // |view_| and receives method calls on chromoting threads. These method
108 // calls are then delegates on the pepper thread. During destruction of
109 // ChromotingInstance we need to detach PepperViewProxy from PepperView since
110 // both ChromotingInstance and PepperView are destroyed and there will be
111 // outstanding tasks on the pepper message loo.
112 scoped_refptr<PepperViewProxy> view_proxy_;
113 scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_;
114 scoped_ptr<InputHandler> input_handler_;
115 scoped_ptr<ChromotingClient> client_;
117 // XmppProxy is a refcounted interface used to perform thread-switching and
118 // detaching between objects whose lifetimes are controlled by pepper, and
119 // jingle_glue objects. This is used when if we start a sandboxed jingle
120 // connection.
121 scoped_refptr<PepperXmppProxy> xmpp_proxy_;
123 PepperClientLogger logger_;
125 // JavaScript interface to control this instance.
126 // This wraps a ChromotingScriptableObject in a pp::Var.
127 pp::Var instance_object_;
129 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance);
132 } // namespace remoting
134 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_