OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "remoting/client/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "ppapi/c/pp_input_event.h" | 13 #include "ppapi/c/pp_input_event.h" |
14 #include "ppapi/cpp/completion_callback.h" | 14 #include "ppapi/cpp/completion_callback.h" |
15 #include "ppapi/cpp/rect.h" | 15 #include "ppapi/cpp/rect.h" |
16 #include "remoting/client/client_config.h" | 16 #include "remoting/client/client_config.h" |
17 #include "remoting/client/client_util.h" | 17 #include "remoting/client/client_util.h" |
18 #include "remoting/client/chromoting_client.h" | 18 #include "remoting/client/chromoting_client.h" |
19 #include "remoting/client/rectangle_update_decoder.h" | 19 #include "remoting/client/rectangle_update_decoder.h" |
20 #include "remoting/client/plugin/chromoting_scriptable_object.h" | 20 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
21 #include "remoting/client/plugin/pepper_input_handler.h" | 21 #include "remoting/client/plugin/pepper_input_handler.h" |
22 #include "remoting/client/plugin/pepper_view.h" | 22 #include "remoting/client/plugin/pepper_view.h" |
| 23 #include "remoting/client/plugin/pepper_view_proxy.h" |
23 #include "remoting/jingle_glue/jingle_thread.h" | 24 #include "remoting/jingle_glue/jingle_thread.h" |
24 #include "remoting/protocol/connection_to_host.h" | 25 #include "remoting/protocol/connection_to_host.h" |
25 #include "remoting/protocol/jingle_connection_to_host.h" | 26 #include "remoting/protocol/jingle_connection_to_host.h" |
26 | 27 |
27 namespace remoting { | 28 namespace remoting { |
28 | 29 |
29 const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting"; | 30 const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting"; |
30 | 31 |
31 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) | 32 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) |
32 : pp::Instance(pp_instance), | 33 : pp::Instance(pp_instance), |
33 pepper_main_loop_dont_post_to_me_(NULL) { | 34 pepper_main_loop_dont_post_to_me_(NULL) { |
34 } | 35 } |
35 | 36 |
36 ChromotingInstance::~ChromotingInstance() { | 37 ChromotingInstance::~ChromotingInstance() { |
37 if (client_.get()) { | 38 if (client_.get()) { |
38 client_->Stop(); | 39 client_->Stop(); |
39 } | 40 } |
40 | 41 |
41 // TODO(ajwong): We need to ensure all objects have actually stopped posting | 42 // Stopping the context shutdown all chromoting threads. This is a requirement |
42 // to the message loop before this point. Right now, we don't have a well | 43 // before we can call Detach() on |view_proxy_|. |
43 // defined stop for the plugin process, and the thread shutdown is likely a | |
44 // race condition. | |
45 context_.Stop(); | 44 context_.Stop(); |
| 45 |
| 46 view_proxy_->Detach(); |
46 } | 47 } |
47 | 48 |
48 bool ChromotingInstance::Init(uint32_t argc, | 49 bool ChromotingInstance::Init(uint32_t argc, |
49 const char* argn[], | 50 const char* argn[], |
50 const char* argv[]) { | 51 const char* argv[]) { |
51 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); | 52 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); |
52 | 53 |
53 // Record the current thread. This function should only be invoked by the | 54 // Record the current thread. This function should only be invoked by the |
54 // plugin thread, so we capture the current message loop and assume it is | 55 // plugin thread, so we capture the current message loop and assume it is |
55 // indeed the plugin thread. | 56 // indeed the plugin thread. |
56 // | 57 // |
57 // We're abusing the pepper API slightly here. We know we're running as an | 58 // We're abusing the pepper API slightly here. We know we're running as an |
58 // internal plugin, and thus we are on the pepper main thread that uses a | 59 // internal plugin, and thus we are on the pepper main thread that uses a |
59 // message loop. | 60 // message loop. |
60 // | 61 // |
61 // TODO(ajwong): See if there is a method for querying what thread we're on | 62 // TODO(ajwong): See if there is a method for querying what thread we're on |
62 // from inside the pepper API. | 63 // from inside the pepper API. |
63 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); | 64 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); |
64 VLOG(1) << "Started ChromotingInstance::Init"; | 65 VLOG(1) << "Started ChromotingInstance::Init"; |
65 | 66 |
66 // Start all the threads. | 67 // Start all the threads. |
67 context_.Start(); | 68 context_.Start(); |
68 | 69 |
69 // Create the chromoting objects. | 70 // Create the chromoting objects. |
70 host_connection_.reset(new protocol::JingleConnectionToHost( | 71 host_connection_.reset(new protocol::JingleConnectionToHost( |
71 context_.jingle_thread())); | 72 context_.jingle_thread())); |
72 view_.reset(new PepperView(this, &context_)); | 73 view_.reset(new PepperView(this, &context_)); |
| 74 view_proxy_ = new PepperViewProxy(this, view_.get()); |
73 rectangle_decoder_.reset( | 75 rectangle_decoder_.reset( |
74 new RectangleUpdateDecoder(context_.decode_message_loop(), view_.get())); | 76 new RectangleUpdateDecoder(context_.decode_message_loop(), |
| 77 view_proxy_)); |
75 input_handler_.reset(new PepperInputHandler(&context_, | 78 input_handler_.reset(new PepperInputHandler(&context_, |
76 host_connection_.get(), | 79 host_connection_.get(), |
77 view_.get())); | 80 view_proxy_)); |
78 | 81 |
79 // Default to a medium grey. | 82 // Default to a medium grey. |
80 view_->SetSolidFill(0xFFCDCDCD); | 83 view_->SetSolidFill(0xFFCDCDCD); |
81 | 84 |
82 return true; | 85 return true; |
83 } | 86 } |
84 | 87 |
85 void ChromotingInstance::Connect(const ClientConfig& config) { | 88 void ChromotingInstance::Connect(const ClientConfig& config) { |
86 DCHECK(CurrentlyOnPluginThread()); | 89 DCHECK(CurrentlyOnPluginThread()); |
87 | 90 |
88 client_.reset(new ChromotingClient(config, | 91 client_.reset(new ChromotingClient(config, |
89 &context_, | 92 &context_, |
90 host_connection_.get(), | 93 host_connection_.get(), |
91 view_.get(), | 94 view_proxy_, |
92 rectangle_decoder_.get(), | 95 rectangle_decoder_.get(), |
93 input_handler_.get(), | 96 input_handler_.get(), |
94 NULL)); | 97 NULL)); |
95 | 98 |
96 // Kick off the connection. | 99 // Kick off the connection. |
97 client_->Start(); | 100 client_->Start(); |
98 | 101 |
99 GetScriptableObject()->SetConnectionInfo(STATUS_INITIALIZING, | 102 GetScriptableObject()->SetConnectionInfo(STATUS_INITIALIZING, |
100 QUALITY_UNKNOWN); | 103 QUALITY_UNKNOWN); |
101 } | 104 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 object->Init(); | 186 object->Init(); |
184 | 187 |
185 // The pp::Var takes ownership of object here. | 188 // The pp::Var takes ownership of object here. |
186 instance_object_ = pp::Var(this, object); | 189 instance_object_ = pp::Var(this, object); |
187 } | 190 } |
188 | 191 |
189 return instance_object_; | 192 return instance_object_; |
190 } | 193 } |
191 | 194 |
192 } // namespace remoting | 195 } // namespace remoting |
OLD | NEW |