 Chromium Code Reviews
 Chromium Code Reviews Issue 1534193004:
  Use std::move() instead of scoped_ptr<>::Pass().  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1534193004:
  Use std::move() instead of scoped_ptr<>::Pass().  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/protocol/fake_authenticator.h" | 5 #include "remoting/protocol/fake_authenticator.h" | 
| 6 | 6 | 
| 7 #include "base/base64.h" | 7 #include "base/base64.h" | 
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" | 
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" | 
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 did_write_bytes_(false), | 26 did_write_bytes_(false), | 
| 27 weak_factory_(this) { | 27 weak_factory_(this) { | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 FakeChannelAuthenticator::~FakeChannelAuthenticator() { | 30 FakeChannelAuthenticator::~FakeChannelAuthenticator() { | 
| 31 } | 31 } | 
| 32 | 32 | 
| 33 void FakeChannelAuthenticator::SecureAndAuthenticate( | 33 void FakeChannelAuthenticator::SecureAndAuthenticate( | 
| 34 scoped_ptr<P2PStreamSocket> socket, | 34 scoped_ptr<P2PStreamSocket> socket, | 
| 35 const DoneCallback& done_callback) { | 35 const DoneCallback& done_callback) { | 
| 36 socket_ = socket.Pass(); | 36 socket_ = std::move(socket); | 
| 37 | 37 | 
| 38 if (async_) { | 38 if (async_) { | 
| 39 done_callback_ = done_callback; | 39 done_callback_ = done_callback; | 
| 40 | 40 | 
| 41 if (result_ != net::OK) { | 41 if (result_ != net::OK) { | 
| 42 // Don't write anything if we are going to reject auth to make test | 42 // Don't write anything if we are going to reject auth to make test | 
| 43 // ordering deterministic. | 43 // ordering deterministic. | 
| 44 did_write_bytes_ = true; | 44 did_write_bytes_ = true; | 
| 45 } else { | 45 } else { | 
| 46 scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); | 46 scoped_refptr<net::IOBuffer> write_buf = new net::IOBuffer(1); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 EXPECT_EQ(1, result); | 80 EXPECT_EQ(1, result); | 
| 81 EXPECT_FALSE(did_read_bytes_); | 81 EXPECT_FALSE(did_read_bytes_); | 
| 82 did_read_bytes_ = true; | 82 did_read_bytes_ = true; | 
| 83 if (did_write_bytes_) | 83 if (did_write_bytes_) | 
| 84 CallDoneCallback(); | 84 CallDoneCallback(); | 
| 85 } | 85 } | 
| 86 | 86 | 
| 87 void FakeChannelAuthenticator::CallDoneCallback() { | 87 void FakeChannelAuthenticator::CallDoneCallback() { | 
| 88 if (result_ != net::OK) | 88 if (result_ != net::OK) | 
| 89 socket_.reset(); | 89 socket_.reset(); | 
| 90 base::ResetAndReturn(&done_callback_).Run(result_, socket_.Pass()); | 90 base::ResetAndReturn(&done_callback_).Run(result_, std::move(socket_)); | 
| 91 } | 91 } | 
| 92 | 92 | 
| 93 FakeAuthenticator::FakeAuthenticator(Type type, | 93 FakeAuthenticator::FakeAuthenticator(Type type, | 
| 94 int round_trips, | 94 int round_trips, | 
| 95 Action action, | 95 Action action, | 
| 96 bool async) | 96 bool async) | 
| 97 : type_(type), | 97 : type_(type), | 
| 98 round_trips_(round_trips), | 98 round_trips_(round_trips), | 
| 99 action_(action), | 99 action_(action), | 
| 100 async_(async), | 100 async_(async), | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 auth_key_ = base::RandBytesAsString(16); | 178 auth_key_ = base::RandBytesAsString(16); | 
| 179 buzz::XmlElement* key = new buzz::XmlElement( | 179 buzz::XmlElement* key = new buzz::XmlElement( | 
| 180 buzz::QName(kChromotingXmlNamespace, "key")); | 180 buzz::QName(kChromotingXmlNamespace, "key")); | 
| 181 std::string key_base64; | 181 std::string key_base64; | 
| 182 base::Base64Encode(auth_key_, &key_base64); | 182 base::Base64Encode(auth_key_, &key_base64); | 
| 183 key->AddText(key_base64); | 183 key->AddText(key_base64); | 
| 184 result->AddElement(key); | 184 result->AddElement(key); | 
| 185 } | 185 } | 
| 186 | 186 | 
| 187 ++messages_; | 187 ++messages_; | 
| 188 return result.Pass(); | 188 return result; | 
| 189 } | 189 } | 
| 190 | 190 | 
| 191 const std::string& FakeAuthenticator::GetAuthKey() const { | 191 const std::string& FakeAuthenticator::GetAuthKey() const { | 
| 192 EXPECT_EQ(ACCEPTED, state()); | 192 EXPECT_EQ(ACCEPTED, state()); | 
| 193 return auth_key_; | 193 return auth_key_; | 
| 194 } | 194 } | 
| 195 | 195 | 
| 196 scoped_ptr<ChannelAuthenticator> | 196 scoped_ptr<ChannelAuthenticator> | 
| 197 FakeAuthenticator::CreateChannelAuthenticator() const { | 197 FakeAuthenticator::CreateChannelAuthenticator() const { | 
| 198 EXPECT_EQ(ACCEPTED, state()); | 198 EXPECT_EQ(ACCEPTED, state()); | 
| 199 return make_scoped_ptr( | 199 return make_scoped_ptr( | 
| 200 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); | 200 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); | 
| 201 } | 201 } | 
| 202 | 202 | 
| 203 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( | 203 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( | 
| 204 int round_trips, int messages_till_started, | 204 int round_trips, int messages_till_started, | 
| 205 FakeAuthenticator::Action action, bool async) | 205 FakeAuthenticator::Action action, bool async) | 
| 206 : round_trips_(round_trips), | 206 : round_trips_(round_trips), | 
| 207 messages_till_started_(messages_till_started), | 207 messages_till_started_(messages_till_started), | 
| 208 action_(action), async_(async) { | 208 action_(action), async_(async) { | 
| 209 } | 209 } | 
| 210 | 210 | 
| 211 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { | 211 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { | 
| 212 } | 212 } | 
| 213 | 213 | 
| 214 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 214 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 
| 215 const std::string& local_jid, | 215 const std::string& local_jid, | 
| 216 const std::string& remote_jid, | 216 const std::string& remote_jid, | 
| 217 const buzz::XmlElement* first_message) { | 217 const buzz::XmlElement* first_message) { | 
| 218 FakeAuthenticator* authenticator = new FakeAuthenticator( | 218 scoped_ptr<FakeAuthenticator> authenticator(new FakeAuthenticator( | 
| 219 FakeAuthenticator::HOST, round_trips_, action_, async_); | 219 FakeAuthenticator::HOST, round_trips_, action_, async_)); | 
| 220 authenticator->set_messages_till_started(messages_till_started_); | 220 authenticator->set_messages_till_started(messages_till_started_); | 
| 221 | 221 return std::move(authenticator); | 
| 
Jamie
2015/12/22 12:23:36
I don't think you need move here (https://www.chro
 
Sergey Ulanov
2015/12/22 18:07:35
This return statement requires upcast from FakeAut
 | |
| 222 scoped_ptr<Authenticator> result(authenticator); | |
| 223 return result.Pass(); | |
| 224 } | 222 } | 
| 225 | 223 | 
| 226 } // namespace protocol | 224 } // namespace protocol | 
| 227 } // namespace remoting | 225 } // namespace remoting | 
| OLD | NEW |