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

Side by Side Diff: remoting/host/token_validator_factory_impl.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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/token_validator_factory_impl.h" 5 #include "remoting/host/token_validator_factory_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "crypto/random.h" 21 #include "crypto/random.h"
21 #include "net/base/elements_upload_data_stream.h" 22 #include "net/base/elements_upload_data_stream.h"
22 #include "net/base/escape.h" 23 #include "net/base/escape.h"
23 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
24 #include "net/base/request_priority.h" 25 #include "net/base/request_priority.h"
25 #include "net/base/upload_bytes_element_reader.h" 26 #include "net/base/upload_bytes_element_reader.h"
26 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 key_pair_->SignMessage(token), true) + 86 key_pair_->SignMessage(token), true) +
86 "&grant_type=authorization_code"; 87 "&grant_type=authorization_code";
87 88
88 request_ = request_context_getter_->GetURLRequestContext()->CreateRequest( 89 request_ = request_context_getter_->GetURLRequestContext()->CreateRequest(
89 third_party_auth_config_.token_validation_url, net::DEFAULT_PRIORITY, 90 third_party_auth_config_.token_validation_url, net::DEFAULT_PRIORITY,
90 this); 91 this);
91 request_->SetExtraRequestHeaderByName( 92 request_->SetExtraRequestHeaderByName(
92 net::HttpRequestHeaders::kContentType, 93 net::HttpRequestHeaders::kContentType,
93 "application/x-www-form-urlencoded", true); 94 "application/x-www-form-urlencoded", true);
94 request_->set_method("POST"); 95 request_->set_method("POST");
95 scoped_ptr<net::UploadElementReader> reader( 96 std::unique_ptr<net::UploadElementReader> reader(
96 new net::UploadBytesElementReader( 97 new net::UploadBytesElementReader(post_body_.data(), post_body_.size()));
97 post_body_.data(), post_body_.size()));
98 request_->set_upload( 98 request_->set_upload(
99 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); 99 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0));
100 request_->Start(); 100 request_->Start();
101 } 101 }
102 102
103 std::string TokenValidatorImpl::CreateScope( 103 std::string TokenValidatorImpl::CreateScope(
104 const std::string& local_jid, 104 const std::string& local_jid,
105 const std::string& remote_jid) { 105 const std::string& remote_jid) {
106 std::string nonce_bytes; 106 std::string nonce_bytes;
107 crypto::RandBytes(base::WriteInto(&nonce_bytes, kNonceLength + 1), 107 crypto::RandBytes(base::WriteInto(&nonce_bytes, kNonceLength + 1),
108 kNonceLength); 108 kNonceLength);
109 std::string nonce; 109 std::string nonce;
110 base::Base64Encode(nonce_bytes, &nonce); 110 base::Base64Encode(nonce_bytes, &nonce);
111 return "client:" + remote_jid + " host:" + local_jid + " nonce:" + nonce; 111 return "client:" + remote_jid + " host:" + local_jid + " nonce:" + nonce;
112 } 112 }
113 113
114 TokenValidatorFactoryImpl::TokenValidatorFactoryImpl( 114 TokenValidatorFactoryImpl::TokenValidatorFactoryImpl(
115 const ThirdPartyAuthConfig& third_party_auth_config, 115 const ThirdPartyAuthConfig& third_party_auth_config,
116 scoped_refptr<RsaKeyPair> key_pair, 116 scoped_refptr<RsaKeyPair> key_pair,
117 scoped_refptr<net::URLRequestContextGetter> request_context_getter) 117 scoped_refptr<net::URLRequestContextGetter> request_context_getter)
118 : third_party_auth_config_(third_party_auth_config), 118 : third_party_auth_config_(third_party_auth_config),
119 key_pair_(key_pair), 119 key_pair_(key_pair),
120 request_context_getter_(request_context_getter) { 120 request_context_getter_(request_context_getter) {
121 } 121 }
122 122
123 TokenValidatorFactoryImpl::~TokenValidatorFactoryImpl() { 123 TokenValidatorFactoryImpl::~TokenValidatorFactoryImpl() {
124 } 124 }
125 125
126 scoped_ptr<protocol::TokenValidator> 126 std::unique_ptr<protocol::TokenValidator>
127 TokenValidatorFactoryImpl::CreateTokenValidator( 127 TokenValidatorFactoryImpl::CreateTokenValidator(const std::string& local_jid,
128 const std::string& local_jid, 128 const std::string& remote_jid) {
129 const std::string& remote_jid) { 129 return base::WrapUnique(
130 return make_scoped_ptr( 130 new TokenValidatorImpl(third_party_auth_config_, key_pair_, local_jid,
131 new TokenValidatorImpl(third_party_auth_config_, 131 remote_jid, request_context_getter_));
132 key_pair_, local_jid, remote_jid,
133 request_context_getter_));
134 } 132 }
135 133
136 } // namespace remoting 134 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/token_validator_factory_impl.h ('k') | remoting/host/token_validator_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698