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

Side by Side Diff: remoting/protocol/protocol_test_client.cc

Issue 8493020: Move code in src/remoting to the new callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix win and mac Created 9 years, 1 month 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
OLDNEW
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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if !defined(OS_WIN) 7 #if !defined(OS_WIN)
8 extern "C" { 8 extern "C" {
9 #include <unistd.h> 9 #include <unistd.h>
10 } 10 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 session_.reset(session); 122 session_.reset(session);
123 } 123 }
124 124
125 void ProtocolTestConnection::Write(const std::string& str) { 125 void ProtocolTestConnection::Write(const std::string& str) {
126 if (str.empty()) 126 if (str.empty())
127 return; 127 return;
128 128
129 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(str.length())); 129 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(str.length()));
130 memcpy(buf->data(), str.c_str(), str.length()); 130 memcpy(buf->data(), str.c_str(), str.length());
131 message_loop_->PostTask( 131 message_loop_->PostTask(
132 FROM_HERE, NewRunnableMethod( 132 FROM_HERE, base::Bind(&ProtocolTestConnection::DoWrite,
133 this, &ProtocolTestConnection::DoWrite, buf, str.length())); 133 this, buf, str.length()));
134 } 134 }
135 135
136 void ProtocolTestConnection::DoWrite( 136 void ProtocolTestConnection::DoWrite(
137 scoped_refptr<net::IOBuffer> buf, int size) { 137 scoped_refptr<net::IOBuffer> buf, int size) {
138 if (pending_write_) { 138 if (pending_write_) {
139 LOG(ERROR) << "Cannot write because there is another pending write."; 139 LOG(ERROR) << "Cannot write because there is another pending write.";
140 return; 140 return;
141 } 141 }
142 142
143 net::Socket* channel = session_->event_channel(); 143 net::Socket* channel = session_->event_channel();
144 if (channel != NULL) { 144 if (channel != NULL) {
145 int result = channel->Write(buf, size, &write_cb_); 145 int result = channel->Write(buf, size, &write_cb_);
146 if (result < 0) { 146 if (result < 0) {
147 if (result == net::ERR_IO_PENDING) 147 if (result == net::ERR_IO_PENDING)
148 pending_write_ = true; 148 pending_write_ = true;
149 else 149 else
150 LOG(ERROR) << "Write() returned error " << result; 150 LOG(ERROR) << "Write() returned error " << result;
151 } 151 }
152 } else { 152 } else {
153 LOG(ERROR) << "Cannot write because the channel isn't intialized yet."; 153 LOG(ERROR) << "Cannot write because the channel isn't intialized yet.";
154 } 154 }
155 } 155 }
156 156
157 void ProtocolTestConnection::Read() { 157 void ProtocolTestConnection::Read() {
158 message_loop_->PostTask( 158 message_loop_->PostTask(
159 FROM_HERE, NewRunnableMethod( 159 FROM_HERE, base::Bind(&ProtocolTestConnection::DoRead, this));
160 this, &ProtocolTestConnection::DoRead));
161 } 160 }
162 161
163 void ProtocolTestConnection::DoRead() { 162 void ProtocolTestConnection::DoRead() {
164 read_buffer_ = new net::IOBuffer(kBufferSize); 163 read_buffer_ = new net::IOBuffer(kBufferSize);
165 while (true) { 164 while (true) {
166 int result = session_->event_channel()->Read( 165 int result = session_->event_channel()->Read(
167 read_buffer_, kBufferSize, &read_cb_); 166 read_buffer_, kBufferSize, &read_cb_);
168 if (result < 0) { 167 if (result < 0) {
169 if (result != net::ERR_IO_PENDING) 168 if (result != net::ERR_IO_PENDING)
170 LOG(ERROR) << "Read failed: " << result; 169 LOG(ERROR) << "Read failed: " << result;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 std::string auth_service("oauth2"); 358 std::string auth_service("oauth2");
360 if (cmd_line->HasSwitch("auth_service")) 359 if (cmd_line->HasSwitch("auth_service"))
361 auth_service = cmd_line->GetSwitchValueASCII("auth_service"); 360 auth_service = cmd_line->GetSwitchValueASCII("auth_service");
362 361
363 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); 362 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient());
364 363
365 client->Run(username, auth_token, host_jid, auth_service); 364 client->Run(username, auth_token, host_jid, auth_service);
366 365
367 return 0; 366 return 0;
368 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698