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

Side by Side Diff: extensions/browser/api/cast_channel/cast_transport.cc

Issue 2036863002: Remove use of deprecated MessageLoop methods in extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_transport.h" 5 #include "extensions/browser/api/cast_channel/cast_transport.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/format_macros.h" 14 #include "base/format_macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/location.h"
16 #include "base/numerics/safe_conversions.h" 16 #include "base/numerics/safe_conversions.h"
17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h"
18 #include "extensions/browser/api/cast_channel/cast_framer.h" 20 #include "extensions/browser/api/cast_channel/cast_framer.h"
19 #include "extensions/browser/api/cast_channel/cast_message_util.h" 21 #include "extensions/browser/api/cast_channel/cast_message_util.h"
20 #include "extensions/browser/api/cast_channel/logger.h" 22 #include "extensions/browser/api/cast_channel/logger.h"
21 #include "extensions/browser/api/cast_channel/logger_util.h" 23 #include "extensions/browser/api/cast_channel/logger_util.h"
22 #include "extensions/common/api/cast_channel/cast_channel.pb.h" 24 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
23 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
24 #include "net/socket/socket.h" 26 #include "net/socket/socket.h"
25 27
26 #define VLOG_WITH_CONNECTION(level) \ 28 #define VLOG_WITH_CONNECTION(level) \
27 VLOG(level) << "[" << ip_endpoint_.ToString() << ", auth=" << channel_auth_ \ 29 VLOG(level) << "[" << ip_endpoint_.ToString() << ", auth=" << channel_auth_ \
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 DCHECK(delegate); 151 DCHECK(delegate);
150 delegate_ = std::move(delegate); 152 delegate_ = std::move(delegate);
151 if (started_) { 153 if (started_) {
152 delegate_->Start(); 154 delegate_->Start();
153 } 155 }
154 } 156 }
155 157
156 void CastTransportImpl::FlushWriteQueue() { 158 void CastTransportImpl::FlushWriteQueue() {
157 for (; !write_queue_.empty(); write_queue_.pop()) { 159 for (; !write_queue_.empty(); write_queue_.pop()) {
158 net::CompletionCallback& callback = write_queue_.front().callback; 160 net::CompletionCallback& callback = write_queue_.front().callback;
159 base::MessageLoop::current()->PostTask( 161 base::ThreadTaskRunnerHandle::Get()->PostTask(
160 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); 162 FROM_HERE, base::Bind(callback, net::ERR_FAILED));
161 callback.Reset(); 163 callback.Reset();
162 } 164 }
163 } 165 }
164 166
165 void CastTransportImpl::SendMessage(const CastMessage& message, 167 void CastTransportImpl::SendMessage(const CastMessage& message,
166 const net::CompletionCallback& callback) { 168 const net::CompletionCallback& callback) {
167 DCHECK(CalledOnValidThread()); 169 DCHECK(CalledOnValidThread());
168 std::string serialized_message; 170 std::string serialized_message;
169 if (!MessageFramer::Serialize(message, &serialized_message)) { 171 if (!MessageFramer::Serialize(message, &serialized_message)) {
170 logger_->LogSocketEventForMessage(channel_id_, proto::SEND_MESSAGE_FAILED, 172 logger_->LogSocketEventForMessage(channel_id_, proto::SEND_MESSAGE_FAILED,
171 message.namespace_(), 173 message.namespace_(),
172 "Error when serializing message."); 174 "Error when serializing message.");
173 base::MessageLoop::current()->PostTask( 175 base::ThreadTaskRunnerHandle::Get()->PostTask(
174 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); 176 FROM_HERE, base::Bind(callback, net::ERR_FAILED));
175 return; 177 return;
176 } 178 }
177 WriteRequest write_request( 179 WriteRequest write_request(
178 message.namespace_(), serialized_message, callback); 180 message.namespace_(), serialized_message, callback);
179 181
180 write_queue_.push(write_request); 182 write_queue_.push(write_request);
181 logger_->LogSocketEventForMessage( 183 logger_->LogSocketEventForMessage(
182 channel_id_, proto::MESSAGE_ENQUEUED, message.namespace_(), 184 channel_id_, proto::MESSAGE_ENQUEUED, message.namespace_(),
183 base::StringPrintf("Queue size: %" PRIuS, write_queue_.size())); 185 base::StringPrintf("Queue size: %" PRIuS, write_queue_.size()));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 320
319 int CastTransportImpl::DoWriteCallback() { 321 int CastTransportImpl::DoWriteCallback() {
320 VLOG_WITH_CONNECTION(2) << "DoWriteCallback"; 322 VLOG_WITH_CONNECTION(2) << "DoWriteCallback";
321 DCHECK(!write_queue_.empty()); 323 DCHECK(!write_queue_.empty());
322 324
323 WriteRequest& request = write_queue_.front(); 325 WriteRequest& request = write_queue_.front();
324 int bytes_consumed = request.io_buffer->BytesConsumed(); 326 int bytes_consumed = request.io_buffer->BytesConsumed();
325 logger_->LogSocketEventForMessage( 327 logger_->LogSocketEventForMessage(
326 channel_id_, proto::MESSAGE_WRITTEN, request.message_namespace, 328 channel_id_, proto::MESSAGE_WRITTEN, request.message_namespace,
327 base::StringPrintf("Bytes: %d", bytes_consumed)); 329 base::StringPrintf("Bytes: %d", bytes_consumed));
328 base::MessageLoop::current()->PostTask(FROM_HERE, 330 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
329 base::Bind(&base::DoNothing)); 331 base::Bind(&base::DoNothing));
330 base::MessageLoop::current()->PostTask(FROM_HERE, 332 base::ThreadTaskRunnerHandle::Get()->PostTask(
331 base::Bind(request.callback, net::OK)); 333 FROM_HERE, base::Bind(request.callback, net::OK));
332 334
333 write_queue_.pop(); 335 write_queue_.pop();
334 if (write_queue_.empty()) { 336 if (write_queue_.empty()) {
335 SetWriteState(WRITE_STATE_IDLE); 337 SetWriteState(WRITE_STATE_IDLE);
336 } else { 338 } else {
337 SetWriteState(WRITE_STATE_WRITE); 339 SetWriteState(WRITE_STATE_WRITE);
338 } 340 }
339 341
340 return net::OK; 342 return net::OK;
341 } 343 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 VLOG_WITH_CONNECTION(2) << "DoReadHandleError"; 470 VLOG_WITH_CONNECTION(2) << "DoReadHandleError";
469 DCHECK_NE(CHANNEL_ERROR_NONE, error_state_); 471 DCHECK_NE(CHANNEL_ERROR_NONE, error_state_);
470 DCHECK_LE(result, 0); 472 DCHECK_LE(result, 0);
471 SetReadState(READ_STATE_ERROR); 473 SetReadState(READ_STATE_ERROR);
472 return net::ERR_FAILED; 474 return net::ERR_FAILED;
473 } 475 }
474 476
475 } // namespace cast_channel 477 } // namespace cast_channel
476 } // namespace api 478 } // namespace api
477 } // namespace extensions 479 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_socket_unittest.cc ('k') | extensions/browser/api/hid/hid_device_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698