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/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringize_macros.h" | 15 #include "base/strings/stringize_macros.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "media/base/media.h" | |
19 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
20 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_fetcher.h" |
21 #include "remoting/base/auth_token_util.h" | 20 #include "remoting/base/auth_token_util.h" |
22 #include "remoting/base/service_urls.h" | 21 #include "remoting/base/service_urls.h" |
23 #include "remoting/host/chromoting_host_context.h" | 22 #include "remoting/host/chromoting_host_context.h" |
24 #include "remoting/host/host_exit_codes.h" | 23 #include "remoting/host/host_exit_codes.h" |
25 #include "remoting/protocol/name_value_map.h" | 24 #include "remoting/protocol/name_value_map.h" |
26 | 25 |
27 namespace remoting { | 26 namespace remoting { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { | 30 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { |
32 {kDisconnected, "DISCONNECTED"}, | 31 {kDisconnected, "DISCONNECTED"}, |
33 {kStarting, "STARTING"}, | 32 {kStarting, "STARTING"}, |
34 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"}, | 33 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"}, |
35 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"}, | 34 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"}, |
36 {kConnected, "CONNECTED"}, | 35 {kConnected, "CONNECTED"}, |
37 {kDisconnecting, "DISCONNECTING"}, | 36 {kDisconnecting, "DISCONNECTING"}, |
38 {kError, "ERROR"}, | 37 {kError, "ERROR"}, |
39 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, | 38 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, }; |
40 }; | |
41 | 39 |
42 } // namespace | 40 } // namespace |
43 | 41 |
44 It2MeNativeMessagingHost::It2MeNativeMessagingHost( | 42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
45 scoped_ptr<ChromotingHostContext> context, | 43 scoped_refptr<AutoThreadTaskRunner> task_runner, |
46 scoped_ptr<It2MeHostFactory> factory) | 44 scoped_ptr<It2MeHostFactory> factory) |
47 : client_(NULL), | 45 : client_(NULL), |
48 host_context_(context.Pass()), | |
49 factory_(factory.Pass()), | 46 factory_(factory.Pass()), |
50 weak_factory_(this) { | 47 weak_factory_(this) { |
51 weak_ptr_ = weak_factory_.GetWeakPtr(); | 48 weak_ptr_ = weak_factory_.GetWeakPtr(); |
52 | 49 |
53 // Ensures runtime specific CPU features are initialized. | 50 // Initialize the host context to manage the threads for the it2me host. |
54 media::InitializeCPUSpecificMediaFeatures(); | 51 // The native messaging host, rather than the It2MeHost object, owns and |
| 52 // maintains the lifetime of the host context. |
| 53 |
| 54 host_context_.reset(ChromotingHostContext::Create(task_runner).release()); |
55 | 55 |
56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); | 56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
57 const bool xmpp_server_valid = | 57 const bool xmpp_server_valid = |
58 net::ParseHostAndPort(service_urls->xmpp_server_address(), | 58 net::ParseHostAndPort(service_urls->xmpp_server_address(), |
59 &xmpp_server_config_.host, | 59 &xmpp_server_config_.host, |
60 &xmpp_server_config_.port); | 60 &xmpp_server_config_.port); |
61 DCHECK(xmpp_server_valid); | 61 DCHECK(xmpp_server_valid); |
62 | 62 |
63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); | 63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); |
64 directory_bot_jid_ = service_urls->directory_bot_jid(); | 64 directory_bot_jid_ = service_urls->directory_bot_jid(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { | 198 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { |
199 SendErrorAndExit(response.Pass(), | 199 SendErrorAndExit(response.Pass(), |
200 "'directoryBotJid' not found in request."); | 200 "'directoryBotJid' not found in request."); |
201 return; | 201 return; |
202 } | 202 } |
203 #endif // !defined(NDEBUG) | 203 #endif // !defined(NDEBUG) |
204 | 204 |
205 // Create the It2Me host and start connecting. | 205 // Create the It2Me host and start connecting. |
206 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), | 206 it2me_host_ = factory_->CreateIt2MeHost(host_context_.get(), |
| 207 host_context_->ui_task_runner(), |
207 weak_ptr_, | 208 weak_ptr_, |
208 xmpp_config, | 209 xmpp_config, |
209 directory_bot_jid_); | 210 directory_bot_jid_); |
210 it2me_host_->Connect(); | 211 it2me_host_->Connect(); |
211 | 212 |
212 SendMessageToClient(response.Pass()); | 213 SendMessageToClient(response.Pass()); |
213 } | 214 } |
214 | 215 |
215 void It2MeNativeMessagingHost::ProcessDisconnect( | 216 void It2MeNativeMessagingHost::ProcessDisconnect( |
216 const base::DictionaryValue& message, | 217 const base::DictionaryValue& message, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 307 } |
307 | 308 |
308 /* static */ | 309 /* static */ |
309 std::string It2MeNativeMessagingHost::HostStateToString( | 310 std::string It2MeNativeMessagingHost::HostStateToString( |
310 It2MeHostState host_state) { | 311 It2MeHostState host_state) { |
311 return ValueToName(kIt2MeHostStates, host_state); | 312 return ValueToName(kIt2MeHostStates, host_state); |
312 } | 313 } |
313 | 314 |
314 } // namespace remoting | 315 } // namespace remoting |
315 | 316 |
OLD | NEW |