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

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host.cc

Issue 138833009: For C++ readability review. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing CR feedback. Created 6 years, 10 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 | Annotate | Revision Log
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 factory_(factory.Pass()), 47 factory_(factory.Pass()),
48 weak_factory_(this) { 48 weak_factory_(this) {
49 weak_ptr_ = weak_factory_.GetWeakPtr(); 49 weak_ptr_ = weak_factory_.GetWeakPtr();
50 50
51 // Initialize the host context to manage the threads for the it2me host. 51 // Initialize the host context to manage the threads for the it2me host.
52 // The native messaging host, rather than the It2MeHost object, owns and 52 // The native messaging host, rather than the It2MeHost object, owns and
53 // maintains the lifetime of the host context. 53 // maintains the lifetime of the host context.
54 54
55 host_context_.reset(ChromotingHostContext::Create(task_runner).release()); 55 host_context_.reset(ChromotingHostContext::Create(task_runner).release());
56 56
57 ServiceUrls* service_urls = ServiceUrls::GetInstance(); 57 const ServiceUrls* const service_urls = ServiceUrls::GetInstance();
nadav 2014/02/19 16:21:53 That's probably too many consts. Unless you really
weitao 2014/02/19 17:52:18 Done.
58 bool xmpp_server_valid = 58 const bool xmpp_server_valid =
59 net::ParseHostAndPort(service_urls->xmpp_server_address(), 59 net::ParseHostAndPort(service_urls->xmpp_server_address(),
60 &xmpp_server_config_.host, 60 &xmpp_server_config_.host,
61 &xmpp_server_config_.port); 61 &xmpp_server_config_.port);
62 DCHECK(xmpp_server_valid); 62 DCHECK(xmpp_server_valid);
63 63
64 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); 64 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls();
65 directory_bot_jid_ = service_urls->directory_bot_jid(); 65 directory_bot_jid_ = service_urls->directory_bot_jid();
66 } 66 }
67 67
68 It2MeNativeMessagingHost::~It2MeNativeMessagingHost() { 68 It2MeNativeMessagingHost::~It2MeNativeMessagingHost() {
69 DCHECK(task_runner()->BelongsToCurrentThread()); 69 DCHECK(task_runner()->BelongsToCurrentThread());
70 70
71 if (it2me_host_.get()) { 71 if (it2me_host_.get()) {
72 it2me_host_->Disconnect(); 72 it2me_host_->Disconnect();
73 it2me_host_ = NULL; 73 it2me_host_ = NULL;
74 } 74 }
75 } 75 }
76 76
77 void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) { 77 void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) const {
78 DCHECK(task_runner()->BelongsToCurrentThread()); 78 DCHECK(task_runner()->BelongsToCurrentThread());
79 79
80 channel_->Start( 80 channel_->Start(
81 base::Bind(&It2MeNativeMessagingHost::ProcessMessage, weak_ptr_), 81 base::Bind(&It2MeNativeMessagingHost::ProcessMessage, weak_ptr_),
82 quit_closure); 82 quit_closure);
83 } 83 }
84 84
85 void It2MeNativeMessagingHost::ProcessMessage( 85 void It2MeNativeMessagingHost::ProcessMessage(
86 scoped_ptr<base::DictionaryValue> message) { 86 scoped_ptr<base::DictionaryValue> message) {
87 DCHECK(task_runner()->BelongsToCurrentThread()); 87 DCHECK(task_runner()->BelongsToCurrentThread());
(...skipping 20 matching lines...) Expand all
108 ProcessConnect(*message, response.Pass()); 108 ProcessConnect(*message, response.Pass());
109 } else if (type == "disconnect") { 109 } else if (type == "disconnect") {
110 ProcessDisconnect(*message, response.Pass()); 110 ProcessDisconnect(*message, response.Pass());
111 } else { 111 } else {
112 SendErrorAndExit(response.Pass(), "Unsupported request type: " + type); 112 SendErrorAndExit(response.Pass(), "Unsupported request type: " + type);
113 } 113 }
114 } 114 }
115 115
116 void It2MeNativeMessagingHost::ProcessHello( 116 void It2MeNativeMessagingHost::ProcessHello(
117 const base::DictionaryValue& message, 117 const base::DictionaryValue& message,
118 scoped_ptr<base::DictionaryValue> response) { 118 scoped_ptr<base::DictionaryValue> response) const {
119 DCHECK(task_runner()->BelongsToCurrentThread()); 119 DCHECK(task_runner()->BelongsToCurrentThread());
120 120
121 response->SetString("version", STRINGIZE(VERSION)); 121 response->SetString("version", STRINGIZE(VERSION));
122 122
123 // This list will be populated when new features are added. 123 // This list will be populated when new features are added.
124 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); 124 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
125 response->Set("supportedFeatures", supported_features_list.release()); 125 response->Set("supportedFeatures", supported_features_list.release());
126 126
127 channel_->SendMessage(response.Pass()); 127 channel_->SendMessage(response.Pass());
128 } 128 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 if (it2me_host_.get()) { 209 if (it2me_host_.get()) {
210 it2me_host_->Disconnect(); 210 it2me_host_->Disconnect();
211 it2me_host_ = NULL; 211 it2me_host_ = NULL;
212 } 212 }
213 channel_->SendMessage(response.Pass()); 213 channel_->SendMessage(response.Pass());
214 } 214 }
215 215
216 void It2MeNativeMessagingHost::SendErrorAndExit( 216 void It2MeNativeMessagingHost::SendErrorAndExit(
217 scoped_ptr<base::DictionaryValue> response, 217 scoped_ptr<base::DictionaryValue> response,
218 const std::string& description) { 218 const std::string& description) const {
219 DCHECK(task_runner()->BelongsToCurrentThread()); 219 DCHECK(task_runner()->BelongsToCurrentThread());
220 220
221 LOG(ERROR) << description; 221 LOG(ERROR) << description;
222 222
223 response->SetString("type", "error"); 223 response->SetString("type", "error");
224 response->SetString("description", description); 224 response->SetString("description", description);
225 channel_->SendMessage(response.Pass()); 225 channel_->SendMessage(response.Pass());
226 226
227 // Trigger a host shutdown by sending a NULL message. 227 // Trigger a host shutdown by sending a NULL message.
228 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); 228 channel_->SendMessage(scoped_ptr<base::DictionaryValue>());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 282 }
283 283
284 // Stores the client user's name for the web-app to query. 284 // Stores the client user's name for the web-app to query.
285 void It2MeNativeMessagingHost::OnClientAuthenticated( 285 void It2MeNativeMessagingHost::OnClientAuthenticated(
286 const std::string& client_username) { 286 const std::string& client_username) {
287 DCHECK(task_runner()->BelongsToCurrentThread()); 287 DCHECK(task_runner()->BelongsToCurrentThread());
288 288
289 client_username_ = client_username; 289 client_username_ = client_username;
290 } 290 }
291 291
292 scoped_refptr<AutoThreadTaskRunner> It2MeNativeMessagingHost::task_runner() { 292 scoped_refptr<AutoThreadTaskRunner>
293 It2MeNativeMessagingHost::task_runner() const {
293 return host_context_->ui_task_runner(); 294 return host_context_->ui_task_runner();
294 } 295 }
295 296
296 /* static */ 297 /* static */
297 std::string It2MeNativeMessagingHost::HostStateToString( 298 std::string It2MeNativeMessagingHost::HostStateToString(
298 It2MeHostState host_state) { 299 It2MeHostState host_state) {
299 return ValueToName(kIt2MeHostStates, host_state); 300 return ValueToName(kIt2MeHostStates, host_state);
300 } 301 }
301 302
302 } // namespace remoting 303 } // namespace remoting
304
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host.h ('k') | remoting/host/it2me/it2me_native_messaging_host_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698