Add debug logging to Chromoting client UI.
[chromium-blink-merge.git] / remoting / client / plugin / chromoting_instance.h
blob9e1c2d34a08024e92ec15bda01d8764410499e83
1 // Copyright (c) 2010 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/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/protocol/connection_to_host.h"
24 class MessageLoop;
25 struct PP_InputEvent;
27 namespace base {
28 class Thread;
29 } // namespace base
31 namespace pp {
32 class Module;
33 } // namespace pp
35 namespace remoting {
37 namespace protocol {
38 class ConnectionToHost;
39 } // namespace protocol
41 class ChromotingClient;
42 class ClientContext;
43 class InputHandler;
44 class JingleThread;
45 class PepperView;
46 class PepperViewProxy;
47 class RectangleUpdateDecoder;
49 struct ClientConfig;
51 namespace protocol {
52 class HostConnection;
53 } // namespace protocol
55 class ChromotingInstance : public pp::Instance {
56 public:
57 // The mimetype for which this plugin is registered.
58 static const char *kMimeType;
60 explicit ChromotingInstance(PP_Instance instance);
61 virtual ~ChromotingInstance();
63 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
64 virtual void Connect(const ClientConfig& config);
65 virtual bool HandleInputEvent(const PP_InputEvent& event);
66 virtual void Disconnect();
67 virtual pp::Var GetInstanceObject();
68 virtual void ViewChanged(const pp::Rect& position, const pp::Rect& clip);
70 virtual bool CurrentlyOnPluginThread() const;
72 // Convenience wrapper to get the ChromotingScriptableObject.
73 ChromotingScriptableObject* GetScriptableObject();
75 // Called by ChromotingScriptableObject to provide username and password.
76 void SubmitLoginInfo(const std::string& username,
77 const std::string& password);
79 void LogDebugInfo(const std::string& info);
81 private:
82 FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
84 // Since we're an internal plugin, we can just grab the message loop during
85 // init to figure out which thread we're on. This should only be used to
86 // sanity check which thread we're executing on. Do not post task here!
87 // Instead, use PPB_Core:CallOnMainThread() in the pepper api.
89 // TODO(ajwong): Think if there is a better way to safeguard this.
90 MessageLoop* pepper_main_loop_dont_post_to_me_;
92 ClientContext context_;
93 scoped_ptr<protocol::ConnectionToHost> host_connection_;
94 scoped_ptr<PepperView> view_;
96 // PepperViewProxy is refcounted and used to interface between shromoting
97 // objects and PepperView and perform thread switching. It wraps around
98 // |view_| and receives method calls on chromoting threads. These method
99 // calls are then delegates on the pepper thread. During destruction of
100 // ChromotingInstance we need to detach PepperViewProxy from PepperView since
101 // both ChromotingInstance and PepperView are destroyed and there will be
102 // outstanding tasks on the pepper message loo.
103 scoped_refptr<PepperViewProxy> view_proxy_;
104 scoped_ptr<RectangleUpdateDecoder> rectangle_decoder_;
105 scoped_ptr<InputHandler> input_handler_;
106 scoped_ptr<ChromotingClient> client_;
108 // JavaScript interface to control this instance.
109 // This wraps a ChromotingScriptableObject in a pp::Var.
110 pp::Var instance_object_;
112 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance);
115 } // namespace remoting
117 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_INSTANCE_H_