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

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host.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: Created 5 years 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/it2me/it2me_native_messaging_host.h" 5 #include "remoting/host/it2me/it2me_native_messaging_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 25 matching lines...) Expand all
36 {kError, "ERROR"}, 36 {kError, "ERROR"},
37 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, 37 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"},
38 }; 38 };
39 39
40 } // namespace 40 } // namespace
41 41
42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( 42 It2MeNativeMessagingHost::It2MeNativeMessagingHost(
43 scoped_ptr<ChromotingHostContext> context, 43 scoped_ptr<ChromotingHostContext> context,
44 scoped_ptr<It2MeHostFactory> factory) 44 scoped_ptr<It2MeHostFactory> factory)
45 : client_(nullptr), 45 : client_(nullptr),
46 host_context_(context.Pass()), 46 host_context_(std::move(context)),
47 factory_(factory.Pass()), 47 factory_(std::move(factory)),
48 weak_factory_(this) { 48 weak_factory_(this) {
49 weak_ptr_ = weak_factory_.GetWeakPtr(); 49 weak_ptr_ = weak_factory_.GetWeakPtr();
50 50
51 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); 51 const ServiceUrls* service_urls = ServiceUrls::GetInstance();
52 const bool xmpp_server_valid = 52 const bool xmpp_server_valid =
53 net::ParseHostAndPort(service_urls->xmpp_server_address(), 53 net::ParseHostAndPort(service_urls->xmpp_server_address(),
54 &xmpp_server_config_.host, 54 &xmpp_server_config_.host,
55 &xmpp_server_config_.port); 55 &xmpp_server_config_.port);
56 DCHECK(xmpp_server_valid); 56 DCHECK(xmpp_server_valid);
57 57
(...skipping 25 matching lines...) Expand all
83 static_cast<base::DictionaryValue*>(message_value.release())); 83 static_cast<base::DictionaryValue*>(message_value.release()));
84 84
85 // If the client supplies an ID, it will expect it in the response. This 85 // If the client supplies an ID, it will expect it in the response. This
86 // might be a string or a number, so cope with both. 86 // might be a string or a number, so cope with both.
87 const base::Value* id; 87 const base::Value* id;
88 if (message_dict->Get("id", &id)) 88 if (message_dict->Get("id", &id))
89 response->Set("id", id->DeepCopy()); 89 response->Set("id", id->DeepCopy());
90 90
91 std::string type; 91 std::string type;
92 if (!message_dict->GetString("type", &type)) { 92 if (!message_dict->GetString("type", &type)) {
93 SendErrorAndExit(response.Pass(), "'type' not found in request."); 93 SendErrorAndExit(std::move(response), "'type' not found in request.");
94 return; 94 return;
95 } 95 }
96 96
97 response->SetString("type", type + "Response"); 97 response->SetString("type", type + "Response");
98 98
99 if (type == "hello") { 99 if (type == "hello") {
100 ProcessHello(*message_dict, response.Pass()); 100 ProcessHello(*message_dict, std::move(response));
101 } else if (type == "connect") { 101 } else if (type == "connect") {
102 ProcessConnect(*message_dict, response.Pass()); 102 ProcessConnect(*message_dict, std::move(response));
103 } else if (type == "disconnect") { 103 } else if (type == "disconnect") {
104 ProcessDisconnect(*message_dict, response.Pass()); 104 ProcessDisconnect(*message_dict, std::move(response));
105 } else { 105 } else {
106 SendErrorAndExit(response.Pass(), "Unsupported request type: " + type); 106 SendErrorAndExit(std::move(response), "Unsupported request type: " + type);
107 } 107 }
108 } 108 }
109 109
110 void It2MeNativeMessagingHost::Start(Client* client) { 110 void It2MeNativeMessagingHost::Start(Client* client) {
111 DCHECK(task_runner()->BelongsToCurrentThread()); 111 DCHECK(task_runner()->BelongsToCurrentThread());
112 client_ = client; 112 client_ = client;
113 #if !defined(OS_CHROMEOS) 113 #if !defined(OS_CHROMEOS)
114 log_message_handler_.reset( 114 log_message_handler_.reset(
115 new LogMessageHandler( 115 new LogMessageHandler(
116 base::Bind(&It2MeNativeMessagingHost::SendMessageToClient, 116 base::Bind(&It2MeNativeMessagingHost::SendMessageToClient,
(...skipping 13 matching lines...) Expand all
130 const base::DictionaryValue& message, 130 const base::DictionaryValue& message,
131 scoped_ptr<base::DictionaryValue> response) const { 131 scoped_ptr<base::DictionaryValue> response) const {
132 DCHECK(task_runner()->BelongsToCurrentThread()); 132 DCHECK(task_runner()->BelongsToCurrentThread());
133 133
134 response->SetString("version", STRINGIZE(VERSION)); 134 response->SetString("version", STRINGIZE(VERSION));
135 135
136 // This list will be populated when new features are added. 136 // This list will be populated when new features are added.
137 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); 137 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
138 response->Set("supportedFeatures", supported_features_list.release()); 138 response->Set("supportedFeatures", supported_features_list.release());
139 139
140 SendMessageToClient(response.Pass()); 140 SendMessageToClient(std::move(response));
141 } 141 }
142 142
143 void It2MeNativeMessagingHost::ProcessConnect( 143 void It2MeNativeMessagingHost::ProcessConnect(
144 const base::DictionaryValue& message, 144 const base::DictionaryValue& message,
145 scoped_ptr<base::DictionaryValue> response) { 145 scoped_ptr<base::DictionaryValue> response) {
146 DCHECK(task_runner()->BelongsToCurrentThread()); 146 DCHECK(task_runner()->BelongsToCurrentThread());
147 147
148 if (it2me_host_.get()) { 148 if (it2me_host_.get()) {
149 SendErrorAndExit(response.Pass(), 149 SendErrorAndExit(std::move(response),
150 "Connect can be called only when disconnected."); 150 "Connect can be called only when disconnected.");
151 return; 151 return;
152 } 152 }
153 153
154 XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_; 154 XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_;
155 155
156 if (!message.GetString("userName", &xmpp_config.username)) { 156 if (!message.GetString("userName", &xmpp_config.username)) {
157 SendErrorAndExit(response.Pass(), "'userName' not found in request."); 157 SendErrorAndExit(std::move(response), "'userName' not found in request.");
158 return; 158 return;
159 } 159 }
160 160
161 std::string auth_service_with_token; 161 std::string auth_service_with_token;
162 if (!message.GetString("authServiceWithToken", &auth_service_with_token)) { 162 if (!message.GetString("authServiceWithToken", &auth_service_with_token)) {
163 SendErrorAndExit(response.Pass(), 163 SendErrorAndExit(std::move(response),
164 "'authServiceWithToken' not found in request."); 164 "'authServiceWithToken' not found in request.");
165 return; 165 return;
166 } 166 }
167 167
168 // For backward compatibility the webapp still passes OAuth service as part of 168 // For backward compatibility the webapp still passes OAuth service as part of
169 // the authServiceWithToken field. But auth service part is always expected to 169 // the authServiceWithToken field. But auth service part is always expected to
170 // be set to oauth2. 170 // be set to oauth2.
171 const char kOAuth2ServicePrefix[] = "oauth2:"; 171 const char kOAuth2ServicePrefix[] = "oauth2:";
172 if (!base::StartsWith(auth_service_with_token, kOAuth2ServicePrefix, 172 if (!base::StartsWith(auth_service_with_token, kOAuth2ServicePrefix,
173 base::CompareCase::SENSITIVE)) { 173 base::CompareCase::SENSITIVE)) {
174 SendErrorAndExit(response.Pass(), "Invalid 'authServiceWithToken': " + 174 SendErrorAndExit(std::move(response), "Invalid 'authServiceWithToken': " +
175 auth_service_with_token); 175 auth_service_with_token);
176 return; 176 return;
177 } 177 }
178 178
179 xmpp_config.auth_token = 179 xmpp_config.auth_token =
180 auth_service_with_token.substr(strlen(kOAuth2ServicePrefix)); 180 auth_service_with_token.substr(strlen(kOAuth2ServicePrefix));
181 181
182 #if !defined(NDEBUG) 182 #if !defined(NDEBUG)
183 std::string address; 183 std::string address;
184 if (!message.GetString("xmppServerAddress", &address)) { 184 if (!message.GetString("xmppServerAddress", &address)) {
185 SendErrorAndExit(response.Pass(), 185 SendErrorAndExit(std::move(response),
186 "'xmppServerAddress' not found in request."); 186 "'xmppServerAddress' not found in request.");
187 return; 187 return;
188 } 188 }
189 189
190 if (!net::ParseHostAndPort( 190 if (!net::ParseHostAndPort(address, &xmpp_server_config_.host,
191 address, &xmpp_server_config_.host, &xmpp_server_config_.port)) { 191 &xmpp_server_config_.port)) {
192 SendErrorAndExit(response.Pass(), 192 SendErrorAndExit(std::move(response),
193 "Invalid 'xmppServerAddress': " + address); 193 "Invalid 'xmppServerAddress': " + address);
194 return; 194 return;
195 } 195 }
196 196
197 if (!message.GetBoolean("xmppServerUseTls", &xmpp_server_config_.use_tls)) { 197 if (!message.GetBoolean("xmppServerUseTls", &xmpp_server_config_.use_tls)) {
198 SendErrorAndExit(response.Pass(), 198 SendErrorAndExit(std::move(response),
199 "'xmppServerUseTls' not found in request."); 199 "'xmppServerUseTls' not found in request.");
200 return; 200 return;
201 } 201 }
202 202
203 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { 203 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) {
204 SendErrorAndExit(response.Pass(), 204 SendErrorAndExit(std::move(response),
205 "'directoryBotJid' not found in request."); 205 "'directoryBotJid' not found in request.");
206 return; 206 return;
207 } 207 }
208 #endif // !defined(NDEBUG) 208 #endif // !defined(NDEBUG)
209 209
210 // Create the It2Me host and start connecting. 210 // Create the It2Me host and start connecting.
211 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), 211 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(),
212 weak_ptr_, 212 weak_ptr_,
213 xmpp_config, 213 xmpp_config,
214 directory_bot_jid_); 214 directory_bot_jid_);
215 it2me_host_->Connect(); 215 it2me_host_->Connect();
216 216
217 SendMessageToClient(response.Pass()); 217 SendMessageToClient(std::move(response));
218 } 218 }
219 219
220 void It2MeNativeMessagingHost::ProcessDisconnect( 220 void It2MeNativeMessagingHost::ProcessDisconnect(
221 const base::DictionaryValue& message, 221 const base::DictionaryValue& message,
222 scoped_ptr<base::DictionaryValue> response) { 222 scoped_ptr<base::DictionaryValue> response) {
223 DCHECK(task_runner()->BelongsToCurrentThread()); 223 DCHECK(task_runner()->BelongsToCurrentThread());
224 224
225 if (it2me_host_.get()) { 225 if (it2me_host_.get()) {
226 it2me_host_->Disconnect(); 226 it2me_host_->Disconnect();
227 it2me_host_ = nullptr; 227 it2me_host_ = nullptr;
228 } 228 }
229 SendMessageToClient(response.Pass()); 229 SendMessageToClient(std::move(response));
230 } 230 }
231 231
232 void It2MeNativeMessagingHost::SendErrorAndExit( 232 void It2MeNativeMessagingHost::SendErrorAndExit(
233 scoped_ptr<base::DictionaryValue> response, 233 scoped_ptr<base::DictionaryValue> response,
234 const std::string& description) const { 234 const std::string& description) const {
235 DCHECK(task_runner()->BelongsToCurrentThread()); 235 DCHECK(task_runner()->BelongsToCurrentThread());
236 236
237 LOG(ERROR) << description; 237 LOG(ERROR) << description;
238 238
239 response->SetString("type", "error"); 239 response->SetString("type", "error");
240 response->SetString("description", description); 240 response->SetString("description", description);
241 SendMessageToClient(response.Pass()); 241 SendMessageToClient(std::move(response));
242 242
243 // Trigger a host shutdown by sending an empty message. 243 // Trigger a host shutdown by sending an empty message.
244 client_->CloseChannel(std::string()); 244 client_->CloseChannel(std::string());
245 } 245 }
246 246
247 void It2MeNativeMessagingHost::OnStateChanged( 247 void It2MeNativeMessagingHost::OnStateChanged(
248 It2MeHostState state, 248 It2MeHostState state,
249 const std::string& error_message) { 249 const std::string& error_message) {
250 DCHECK(task_runner()->BelongsToCurrentThread()); 250 DCHECK(task_runner()->BelongsToCurrentThread());
251 251
(...skipping 24 matching lines...) Expand all
276 // "error" message so that errors that occur before the "connect" message 276 // "error" message so that errors that occur before the "connect" message
277 // is sent can be communicated. 277 // is sent can be communicated.
278 message->SetString("type", "error"); 278 message->SetString("type", "error");
279 message->SetString("description", error_message); 279 message->SetString("description", error_message);
280 break; 280 break;
281 281
282 default: 282 default:
283 ; 283 ;
284 } 284 }
285 285
286 SendMessageToClient(message.Pass()); 286 SendMessageToClient(std::move(message));
287 } 287 }
288 288
289 void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) { 289 void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
290 DCHECK(task_runner()->BelongsToCurrentThread()); 290 DCHECK(task_runner()->BelongsToCurrentThread());
291 291
292 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue()); 292 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue());
293 293
294 message->SetString("type", "natPolicyChanged"); 294 message->SetString("type", "natPolicyChanged");
295 message->SetBoolean("natTraversalEnabled", nat_traversal_enabled); 295 message->SetBoolean("natTraversalEnabled", nat_traversal_enabled);
296 SendMessageToClient(message.Pass()); 296 SendMessageToClient(std::move(message));
297 } 297 }
298 298
299 // Stores the Access Code for the web-app to query. 299 // Stores the Access Code for the web-app to query.
300 void It2MeNativeMessagingHost::OnStoreAccessCode( 300 void It2MeNativeMessagingHost::OnStoreAccessCode(
301 const std::string& access_code, 301 const std::string& access_code,
302 base::TimeDelta access_code_lifetime) { 302 base::TimeDelta access_code_lifetime) {
303 DCHECK(task_runner()->BelongsToCurrentThread()); 303 DCHECK(task_runner()->BelongsToCurrentThread());
304 304
305 access_code_ = access_code; 305 access_code_ = access_code;
306 access_code_lifetime_ = access_code_lifetime; 306 access_code_lifetime_ = access_code_lifetime;
(...skipping 12 matching lines...) Expand all
319 return host_context_->ui_task_runner(); 319 return host_context_->ui_task_runner();
320 } 320 }
321 321
322 /* static */ 322 /* static */
323 std::string It2MeNativeMessagingHost::HostStateToString( 323 std::string It2MeNativeMessagingHost::HostStateToString(
324 It2MeHostState host_state) { 324 It2MeHostState host_state) {
325 return ValueToName(kIt2MeHostStates, host_state); 325 return ValueToName(kIt2MeHostStates, host_state);
326 } 326 }
327 327
328 } // namespace remoting 328 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698