Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringize_macros.h" | 16 #include "base/strings/stringize_macros.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 20 #include "remoting/base/auth_token_util.h" | 21 #include "remoting/base/auth_token_util.h" |
| 21 #include "remoting/base/service_urls.h" | 22 #include "remoting/base/service_urls.h" |
| 22 #include "remoting/host/chromoting_host_context.h" | 23 #include "remoting/host/chromoting_host_context.h" |
| 23 #include "remoting/host/host_exit_codes.h" | 24 #include "remoting/host/host_exit_codes.h" |
| 24 #include "remoting/protocol/name_value_map.h" | 25 #include "remoting/protocol/name_value_map.h" |
| 25 | 26 |
| 26 namespace remoting { | 27 namespace remoting { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { | 31 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { |
| 31 {kDisconnected, "DISCONNECTED"}, | 32 {kDisconnected, "DISCONNECTED"}, |
| 32 {kStarting, "STARTING"}, | 33 {kStarting, "STARTING"}, |
| 33 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"}, | 34 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"}, |
| 34 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"}, | 35 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"}, |
| 35 {kConnected, "CONNECTED"}, | 36 {kConnected, "CONNECTED"}, |
| 36 {kDisconnecting, "DISCONNECTING"}, | 37 {kDisconnecting, "DISCONNECTING"}, |
| 37 {kError, "ERROR"}, | 38 {kError, "ERROR"}, |
| 38 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, }; | 39 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, }; |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 43 // static | |
| 44 scoped_ptr<extensions::NativeMessageHost> It2MeNativeMessagingHost::Create() { | |
| 45 scoped_ptr<It2MeHostFactory> factory(new remoting::It2MeHostFactory()); | |
| 46 scoped_refptr<ChromotingHostContext> context = | |
| 47 ChromotingHostContext::Create(new AutoThreadTaskRunner( | |
| 48 base::MessageLoopProxy::current(), base::Bind(&base::DoNothing))); | |
| 49 scoped_ptr<extensions::NativeMessageHost> host(new It2MeNativeMessagingHost( | |
| 50 // Remoting uses AutoThread as its threading primitive, which will | |
| 51 // exit itself (by posting a Quit message) when there are no more references | |
| 52 // to the task runner. | |
| 53 // On ChromeOS, the It2MeNativeMessagingHost is created on the UI | |
| 54 // thread of the browser process. Since we do not want to quit the browser | |
| 55 // UI thread just because there are no more tasks in the task_runner, | |
| 56 // base::DoNothing is passed in as the quit closure. | |
|
Wez
2014/10/17 17:57:59
This comment is in the wrong place, and misses the
kelvinp
2014/10/20 00:21:15
I can update the comment.
Yes, I agree that this
| |
| 57 context, | |
| 58 factory.Pass())); | |
| 59 return host.Pass(); | |
| 60 } | |
| 61 | |
| 42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( | 62 It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
| 43 scoped_refptr<AutoThreadTaskRunner> task_runner, | 63 scoped_refptr<ChromotingHostContext> context, |
| 44 scoped_ptr<It2MeHostFactory> factory) | 64 scoped_ptr<It2MeHostFactory> factory) |
| 45 : client_(NULL), | 65 : client_(NULL), |
| 46 factory_(factory.Pass()), | 66 factory_(factory.Pass()), |
| 47 weak_factory_(this) { | 67 weak_factory_(this) { |
| 48 weak_ptr_ = weak_factory_.GetWeakPtr(); | 68 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 49 | 69 |
| 50 // Initialize the host context to manage the threads for the it2me host. | 70 host_context_ = context; |
| 51 // The native messaging host, rather than the It2MeHost object, owns and | 71 task_runner_ = host_context_->ui_task_runner(); |
| 52 // maintains the lifetime of the host context. | |
| 53 | |
| 54 host_context_.reset(ChromotingHostContext::Create(task_runner).release()); | |
| 55 | 72 |
| 56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); | 73 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
| 57 const bool xmpp_server_valid = | 74 const bool xmpp_server_valid = |
| 58 net::ParseHostAndPort(service_urls->xmpp_server_address(), | 75 net::ParseHostAndPort(service_urls->xmpp_server_address(), |
| 59 &xmpp_server_config_.host, | 76 &xmpp_server_config_.host, |
| 60 &xmpp_server_config_.port); | 77 &xmpp_server_config_.port); |
| 61 DCHECK(xmpp_server_valid); | 78 DCHECK(xmpp_server_valid); |
| 62 | 79 |
| 63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); | 80 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); |
| 64 directory_bot_jid_ = service_urls->directory_bot_jid(); | 81 directory_bot_jid_ = service_urls->directory_bot_jid(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } | 213 } |
| 197 | 214 |
| 198 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { | 215 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { |
| 199 SendErrorAndExit(response.Pass(), | 216 SendErrorAndExit(response.Pass(), |
| 200 "'directoryBotJid' not found in request."); | 217 "'directoryBotJid' not found in request."); |
| 201 return; | 218 return; |
| 202 } | 219 } |
| 203 #endif // !defined(NDEBUG) | 220 #endif // !defined(NDEBUG) |
| 204 | 221 |
| 205 // Create the It2Me host and start connecting. | 222 // Create the It2Me host and start connecting. |
| 206 it2me_host_ = factory_->CreateIt2MeHost(host_context_.get(), | 223 it2me_host_ = factory_->CreateIt2MeHost(host_context_, |
| 207 host_context_->ui_task_runner(), | 224 host_context_->ui_task_runner(), |
| 208 weak_ptr_, | 225 weak_ptr_, |
| 209 xmpp_config, | 226 xmpp_config, |
| 210 directory_bot_jid_); | 227 directory_bot_jid_); |
| 211 it2me_host_->Connect(); | 228 it2me_host_->Connect(); |
| 212 | 229 |
| 213 SendMessageToClient(response.Pass()); | 230 SendMessageToClient(response.Pass()); |
| 214 } | 231 } |
| 215 | 232 |
| 216 void It2MeNativeMessagingHost::ProcessDisconnect( | 233 void It2MeNativeMessagingHost::ProcessDisconnect( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 } | 324 } |
| 308 | 325 |
| 309 /* static */ | 326 /* static */ |
| 310 std::string It2MeNativeMessagingHost::HostStateToString( | 327 std::string It2MeNativeMessagingHost::HostStateToString( |
| 311 It2MeHostState host_state) { | 328 It2MeHostState host_state) { |
| 312 return ValueToName(kIt2MeHostStates, host_state); | 329 return ValueToName(kIt2MeHostStates, host_state); |
| 313 } | 330 } |
| 314 | 331 |
| 315 } // namespace remoting | 332 } // namespace remoting |
| 316 | 333 |
| OLD | NEW |