Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: remoting/client/chromoting_client.cc

Issue 2861047: Refactor the client code. Move all x11-related code into X11View and create... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/chromoting_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/chromoting_client.h" 5 #include "remoting/client/chromoting_client.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "remoting/client/chromoting_view.h" 8 #include "remoting/client/chromoting_view.h"
9 #include "remoting/client/client_config.h"
10 #include "remoting/client/client_context.h"
9 #include "remoting/client/host_connection.h" 11 #include "remoting/client/host_connection.h"
12 #include "remoting/client/input_handler.h"
10 13
11 static const uint32 kCreatedColor = 0xffccccff; 14 static const uint32 kCreatedColor = 0xffccccff;
12 static const uint32 kDisconnectedColor = 0xff00ccff; 15 static const uint32 kDisconnectedColor = 0xff00ccff;
13 static const uint32 kFailedColor = 0xffcc00ff; 16 static const uint32 kFailedColor = 0xffcc00ff;
14 17
15 namespace remoting { 18 namespace remoting {
16 19
17 ChromotingClient::ChromotingClient(MessageLoop* message_loop, 20 ChromotingClient::ChromotingClient(ClientConfig* config,
21 ClientContext* context,
18 HostConnection* connection, 22 HostConnection* connection,
19 ChromotingView* view) 23 ChromotingView* view,
20 : message_loop_(message_loop), 24 InputHandler* input_handler,
21 state_(CREATED), 25 CancelableTask* client_done)
22 host_connection_(connection), 26 : config_(config),
23 view_(view) { 27 context_(context),
28 connection_(connection),
29 view_(view),
30 input_handler_(input_handler),
31 client_done_(client_done),
32 state_(CREATED) {
24 } 33 }
25 34
26 ChromotingClient::~ChromotingClient() { 35 ChromotingClient::~ChromotingClient() {
27 } 36 }
28 37
38 void ChromotingClient::Start() {
39 if (message_loop() != MessageLoop::current()) {
40 message_loop()->PostTask(
41 FROM_HERE,
42 NewRunnableMethod(this, &ChromotingClient::Start));
43 return;
44 }
45
46 connection_->Connect(config_, this);
47
48 if (!view_->Initialize()) {
49 ClientDone();
50 }
51
awong 2010/07/19 21:50:10 remove extra newline.
52 }
53
54 void ChromotingClient::Stop() {
55 if (message_loop() != MessageLoop::current()) {
56 message_loop()->PostTask(
57 FROM_HERE,
58 NewRunnableMethod(this, &ChromotingClient::Stop));
59 return;
60 }
61
62 connection_->Disconnect();
63
64 view_->TearDown();
65
66 // Quit the current message loop.
67 message_loop()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
68 }
69
70 void ChromotingClient::ClientDone() {
71 if (client_done_ != NULL) {
72 message_loop()->PostTask(FROM_HERE, client_done_);
73 }
74 }
75
29 void ChromotingClient::Repaint() { 76 void ChromotingClient::Repaint() {
30 message_loop()->PostTask( 77 if (message_loop() != MessageLoop::current()) {
31 FROM_HERE, 78 message_loop()->PostTask(
32 NewRunnableMethod(this, &ChromotingClient::DoRepaint)); 79 FROM_HERE,
80 NewRunnableMethod(this, &ChromotingClient::Repaint));
81 return;
82 }
83
84 view_->Paint();
33 } 85 }
34 86
35 void ChromotingClient::SetViewport(int x, int y, int width, int height) { 87 void ChromotingClient::SetViewport(int x, int y, int width, int height) {
36 message_loop()->PostTask( 88 if (message_loop() != MessageLoop::current()) {
37 FROM_HERE, 89 message_loop()->PostTask(
38 NewRunnableMethod(this, &ChromotingClient::DoSetViewport, 90 FROM_HERE,
39 x, y, width, height)); 91 NewRunnableMethod(this, &ChromotingClient::SetViewport,
92 x, y, width, height));
93 return;
94 }
95
96 view_->SetViewport(x, y, width, height);
40 } 97 }
41 98
42 void ChromotingClient::HandleMessages(HostConnection* conn, 99 void ChromotingClient::HandleMessages(HostConnection* conn,
43 HostMessageList* messages) { 100 HostMessageList* messages) {
101 if (message_loop() != MessageLoop::current()) {
102 message_loop()->PostTask(
103 FROM_HERE,
104 NewRunnableMethod(this, &ChromotingClient::HandleMessages,
105 conn, messages));
106 return;
107 }
108
44 for (size_t i = 0; i < messages->size(); ++i) { 109 for (size_t i = 0; i < messages->size(); ++i) {
45 HostMessage* msg = (*messages)[i]; 110 HostMessage* msg = (*messages)[i];
46 // TODO(ajwong): Consider creating a macro similar to the IPC message 111 // TODO(ajwong): Consider creating a macro similar to the IPC message
47 // mappings. Also reconsider the lifetime of the message object. 112 // mappings. Also reconsider the lifetime of the message object.
48 if (msg->has_init_client()) { 113 if (msg->has_init_client()) {
49 message_loop()->PostTask( 114 InitClient(msg);
50 FROM_HERE,
51 NewRunnableMethod(this, &ChromotingClient::DoInitClient, msg));
52 } else if (msg->has_begin_update_stream()) { 115 } else if (msg->has_begin_update_stream()) {
53 message_loop()->PostTask( 116 BeginUpdate(msg);
54 FROM_HERE,
55 NewRunnableMethod(this, &ChromotingClient::DoBeginUpdate, msg));
56 } else if (msg->has_update_stream_packet()) { 117 } else if (msg->has_update_stream_packet()) {
57 message_loop()->PostTask( 118 HandleUpdate(msg);
58 FROM_HERE,
59 NewRunnableMethod(this, &ChromotingClient::DoHandleUpdate, msg));
60 } else if (msg->has_end_update_stream()) { 119 } else if (msg->has_end_update_stream()) {
61 message_loop()->PostTask( 120 EndUpdate(msg);
62 FROM_HERE,
63 NewRunnableMethod(this, &ChromotingClient::DoEndUpdate, msg));
64 } else { 121 } else {
65 NOTREACHED() << "Unknown message received"; 122 NOTREACHED() << "Unknown message received";
66 } 123 }
67 } 124 }
68 // Assume we have processed all the messages. 125 // Assume we have processed all the messages.
69 messages->clear(); 126 messages->clear();
70 } 127 }
71 128
72 void ChromotingClient::OnConnectionOpened(HostConnection* conn) { 129 void ChromotingClient::OnConnectionOpened(HostConnection* conn) {
73 LOG(INFO) << "ChromotingClient::OnConnectionOpened"; 130 LOG(INFO) << "ChromotingClient::OnConnectionOpened";
74 SetState(CONNECTED); 131 SetState(CONNECTED);
75 } 132 }
76 133
77 void ChromotingClient::OnConnectionClosed(HostConnection* conn) { 134 void ChromotingClient::OnConnectionClosed(HostConnection* conn) {
78 LOG(INFO) << "ChromotingClient::OnConnectionClosed"; 135 LOG(INFO) << "ChromotingClient::OnConnectionClosed";
79 SetState(DISCONNECTED); 136 SetState(DISCONNECTED);
80 } 137 }
81 138
82 void ChromotingClient::OnConnectionFailed(HostConnection* conn) { 139 void ChromotingClient::OnConnectionFailed(HostConnection* conn) {
83 LOG(INFO) << "ChromotingClient::OnConnectionFailed"; 140 LOG(INFO) << "ChromotingClient::OnConnectionFailed";
84 SetState(FAILED); 141 SetState(FAILED);
85 } 142 }
86 143
87 MessageLoop* ChromotingClient::message_loop() { 144 MessageLoop* ChromotingClient::message_loop() {
88 return message_loop_; 145 return context_->jingle_thread()->message_loop();
89 } 146 }
90 147
91 void ChromotingClient::SetState(State s) { 148 void ChromotingClient::SetState(State s) {
92 // TODO(ajwong): We actually may want state to be a shared variable. Think 149 // TODO(ajwong): We actually may want state to be a shared variable. Think
93 // through later. 150 // through later.
94 message_loop()->PostTask( 151 if (message_loop() != MessageLoop::current()) {
95 FROM_HERE, 152 message_loop()->PostTask(
96 NewRunnableMethod(this, &ChromotingClient::DoSetState, s)); 153 FROM_HERE,
97 } 154 NewRunnableMethod(this, &ChromotingClient::SetState, s));
98 155 return;
99 void ChromotingClient::DoSetState(State s) { 156 }
100 DCHECK_EQ(message_loop(), MessageLoop::current());
101 157
102 state_ = s; 158 state_ = s;
103 switch (state_) { 159 switch (state_) {
104 case CREATED: 160 case CREATED:
105 view_->SetSolidFill(kCreatedColor); 161 view_->SetSolidFill(kCreatedColor);
106 break; 162 break;
107 163
108 case CONNECTED: 164 case CONNECTED:
109 view_->UnsetSolidFill(); 165 view_->UnsetSolidFill();
110 break; 166 break;
111 167
112 case DISCONNECTED: 168 case DISCONNECTED:
113 view_->SetSolidFill(kDisconnectedColor); 169 view_->SetSolidFill(kDisconnectedColor);
114 break; 170 break;
115 171
116 case FAILED: 172 case FAILED:
117 view_->SetSolidFill(kFailedColor); 173 view_->SetSolidFill(kFailedColor);
118 break; 174 break;
119 } 175 }
120 176
121 DoRepaint(); 177 Repaint();
122 } 178 }
123 179
124 void ChromotingClient::DoRepaint() { 180 void ChromotingClient::InitClient(HostMessage* msg) {
125 DCHECK_EQ(message_loop(), MessageLoop::current());
126
127 view_->Paint();
128 }
129
130 void ChromotingClient::DoSetViewport(int x, int y, int width, int height) {
131 DCHECK_EQ(message_loop(), MessageLoop::current());
132
133 view_->SetViewport(x, y, width, height);
134 }
135
136 void ChromotingClient::DoInitClient(HostMessage* msg) {
137 DCHECK_EQ(message_loop(), MessageLoop::current()); 181 DCHECK_EQ(message_loop(), MessageLoop::current());
138 DCHECK(msg->has_init_client()); 182 DCHECK(msg->has_init_client());
139 scoped_ptr<HostMessage> deleter(msg); 183 scoped_ptr<HostMessage> deleter(msg);
140 184
141 // Saves the dimension and resize the window. 185 // Resize the window.
142 int width = msg->init_client().width(); 186 int width = msg->init_client().width();
143 int height = msg->init_client().height(); 187 int height = msg->init_client().height();
144 LOG(INFO) << "Init client received geometry: " << width << "x" << height; 188 LOG(INFO) << "Init client received geometry: " << width << "x" << height;
145 189
146 view_->SetBackingStoreSize(width, height); 190 view_->SetHostScreenSize(width, height);
191
192 // Schedule the input handler to process the event queue.
193 input_handler_->Initialize();
147 } 194 }
148 195
149 void ChromotingClient::DoBeginUpdate(HostMessage* msg) { 196 void ChromotingClient::BeginUpdate(HostMessage* msg) {
150 DCHECK_EQ(message_loop(), MessageLoop::current()); 197 DCHECK_EQ(message_loop(), MessageLoop::current());
151 DCHECK(msg->has_begin_update_stream()); 198 DCHECK(msg->has_begin_update_stream());
152 199
153 view_->HandleBeginUpdateStream(msg); 200 view_->HandleBeginUpdateStream(msg);
154 } 201 }
155 202
156 void ChromotingClient::DoHandleUpdate(HostMessage* msg) { 203 void ChromotingClient::HandleUpdate(HostMessage* msg) {
157 DCHECK_EQ(message_loop(), MessageLoop::current()); 204 DCHECK_EQ(message_loop(), MessageLoop::current());
158 DCHECK(msg->has_update_stream_packet()); 205 DCHECK(msg->has_update_stream_packet());
159 206
160 view_->HandleUpdateStreamPacket(msg); 207 view_->HandleUpdateStreamPacket(msg);
161 } 208 }
162 209
163 void ChromotingClient::DoEndUpdate(HostMessage* msg) { 210 void ChromotingClient::EndUpdate(HostMessage* msg) {
164 DCHECK_EQ(message_loop(), MessageLoop::current()); 211 DCHECK_EQ(message_loop(), MessageLoop::current());
165 DCHECK(msg->has_end_update_stream()); 212 DCHECK(msg->has_end_update_stream());
166 213
167 view_->HandleEndUpdateStream(msg); 214 view_->HandleEndUpdateStream(msg);
168 } 215 }
169 216
170 } // namespace remoting 217 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/chromoting_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698