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

Side by Side Diff: remoting/host/native_messaging/native_messaging_reader.cc

Issue 1549493004: Use std::move() instead of .Pass() in remoting/host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass
Patch Set: include <utility> Created 4 years, 12 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/host/native_messaging/native_messaging_reader.h" 5 #include "remoting/host/native_messaging/native_messaging_reader.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/files/file.h" 13 #include "base/files/file.h"
13 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 scoped_refptr<base::SequencedTaskRunner> read_task_runner_; 64 scoped_refptr<base::SequencedTaskRunner> read_task_runner_;
64 65
65 DISALLOW_COPY_AND_ASSIGN(Core); 66 DISALLOW_COPY_AND_ASSIGN(Core);
66 }; 67 };
67 68
68 NativeMessagingReader::Core::Core( 69 NativeMessagingReader::Core::Core(
69 base::File file, 70 base::File file,
70 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 71 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
71 scoped_refptr<base::SequencedTaskRunner> read_task_runner, 72 scoped_refptr<base::SequencedTaskRunner> read_task_runner,
72 base::WeakPtr<NativeMessagingReader> reader) 73 base::WeakPtr<NativeMessagingReader> reader)
73 : read_stream_(file.Pass()), 74 : read_stream_(std::move(file)),
74 reader_(reader), 75 reader_(reader),
75 caller_task_runner_(caller_task_runner), 76 caller_task_runner_(caller_task_runner),
76 read_task_runner_(read_task_runner) { 77 read_task_runner_(read_task_runner) {
77 } 78 }
78 79
79 NativeMessagingReader::Core::~Core() {} 80 NativeMessagingReader::Core::~Core() {}
80 81
81 void NativeMessagingReader::Core::ReadMessage() { 82 void NativeMessagingReader::Core::ReadMessage() {
82 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); 83 DCHECK(read_task_runner_->RunsTasksOnCurrentThread());
83 84
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 caller_task_runner_->PostTask( 132 caller_task_runner_->PostTask(
132 FROM_HERE, 133 FROM_HERE,
133 base::Bind(&NativeMessagingReader::InvokeEofCallback, reader_)); 134 base::Bind(&NativeMessagingReader::InvokeEofCallback, reader_));
134 } 135 }
135 136
136 NativeMessagingReader::NativeMessagingReader(base::File file) 137 NativeMessagingReader::NativeMessagingReader(base::File file)
137 : reader_thread_("Reader"), 138 : reader_thread_("Reader"),
138 weak_factory_(this) { 139 weak_factory_(this) {
139 reader_thread_.Start(); 140 reader_thread_.Start();
140 read_task_runner_ = reader_thread_.task_runner(); 141 read_task_runner_ = reader_thread_.task_runner();
141 core_.reset(new Core(file.Pass(), base::ThreadTaskRunnerHandle::Get(), 142 core_.reset(new Core(std::move(file), base::ThreadTaskRunnerHandle::Get(),
142 read_task_runner_, weak_factory_.GetWeakPtr())); 143 read_task_runner_, weak_factory_.GetWeakPtr()));
143 } 144 }
144 145
145 NativeMessagingReader::~NativeMessagingReader() { 146 NativeMessagingReader::~NativeMessagingReader() {
146 read_task_runner_->DeleteSoon(FROM_HERE, core_.release()); 147 read_task_runner_->DeleteSoon(FROM_HERE, core_.release());
147 } 148 }
148 149
149 void NativeMessagingReader::Start(MessageCallback message_callback, 150 void NativeMessagingReader::Start(MessageCallback message_callback,
150 base::Closure eof_callback) { 151 base::Closure eof_callback) {
151 message_callback_ = message_callback; 152 message_callback_ = message_callback;
152 eof_callback_ = eof_callback; 153 eof_callback_ = eof_callback;
153 154
154 // base::Unretained is safe since |core_| is only deleted via the 155 // base::Unretained is safe since |core_| is only deleted via the
155 // DeleteSoon task which is posted from this class's dtor. 156 // DeleteSoon task which is posted from this class's dtor.
156 read_task_runner_->PostTask( 157 read_task_runner_->PostTask(
157 FROM_HERE, base::Bind(&NativeMessagingReader::Core::ReadMessage, 158 FROM_HERE, base::Bind(&NativeMessagingReader::Core::ReadMessage,
158 base::Unretained(core_.get()))); 159 base::Unretained(core_.get())));
159 } 160 }
160 161
161 void NativeMessagingReader::InvokeMessageCallback( 162 void NativeMessagingReader::InvokeMessageCallback(
162 scoped_ptr<base::Value> message) { 163 scoped_ptr<base::Value> message) {
163 message_callback_.Run(message.Pass()); 164 message_callback_.Run(std::move(message));
164 } 165 }
165 166
166 void NativeMessagingReader::InvokeEofCallback() { 167 void NativeMessagingReader::InvokeEofCallback() {
167 eof_callback_.Run(); 168 eof_callback_.Run();
168 } 169 }
169 170
170 } // namespace remoting 171 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698