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" |
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_request_context_getter.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"}, |
| 40 }; |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( | 44 It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
43 scoped_refptr<AutoThreadTaskRunner> task_runner, | 45 scoped_ptr<ChromotingHostContext> context, |
44 scoped_ptr<It2MeHostFactory> factory) | 46 scoped_ptr<It2MeHostFactory> factory) |
45 : client_(NULL), | 47 : client_(NULL), |
| 48 host_context_(context.Pass()), |
46 factory_(factory.Pass()), | 49 factory_(factory.Pass()), |
47 weak_factory_(this) { | 50 weak_factory_(this) { |
48 weak_ptr_ = weak_factory_.GetWeakPtr(); | 51 weak_ptr_ = weak_factory_.GetWeakPtr(); |
49 | 52 |
50 // Initialize the host context to manage the threads for the it2me host. | 53 // Ensures runtime specific CPU features are initialized. |
51 // The native messaging host, rather than the It2MeHost object, owns and | 54 media::InitializeCPUSpecificMediaFeatures(); |
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_.get(), | 206 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), |
207 host_context_->ui_task_runner(), | |
208 weak_ptr_, | 207 weak_ptr_, |
209 xmpp_config, | 208 xmpp_config, |
210 directory_bot_jid_); | 209 directory_bot_jid_); |
211 it2me_host_->Connect(); | 210 it2me_host_->Connect(); |
212 | 211 |
213 SendMessageToClient(response.Pass()); | 212 SendMessageToClient(response.Pass()); |
214 } | 213 } |
215 | 214 |
216 void It2MeNativeMessagingHost::ProcessDisconnect( | 215 void It2MeNativeMessagingHost::ProcessDisconnect( |
217 const base::DictionaryValue& message, | 216 const base::DictionaryValue& message, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 306 } |
308 | 307 |
309 /* static */ | 308 /* static */ |
310 std::string It2MeNativeMessagingHost::HostStateToString( | 309 std::string It2MeNativeMessagingHost::HostStateToString( |
311 It2MeHostState host_state) { | 310 It2MeHostState host_state) { |
312 return ValueToName(kIt2MeHostStates, host_state); | 311 return ValueToName(kIt2MeHostStates, host_state); |
313 } | 312 } |
314 | 313 |
315 } // namespace remoting | 314 } // namespace remoting |
316 | 315 |
OLD | NEW |