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

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

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ChromotingHostContext cleanup Created 6 years, 2 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
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"
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 task_runner_(context->ui_task_runner()),
Wez 2014/10/24 00:28:48 Why pull this out here, rather than just referring
kelvinp 2014/10/24 21:39:42 Done.
49 host_context_(context.Pass()),
46 factory_(factory.Pass()), 50 factory_(factory.Pass()),
47 weak_factory_(this) { 51 weak_factory_(this) {
48 weak_ptr_ = weak_factory_.GetWeakPtr(); 52 weak_ptr_ = weak_factory_.GetWeakPtr();
49 53
50 // Initialize the host context to manage the threads for the it2me host. 54 // Ensures runtime specific CPU features are initialized.
51 // The native messaging host, rather than the It2MeHost object, owns and 55 media::InitializeCPUSpecificMediaFeatures();
52 // maintains the lifetime of the host context.
53
54 host_context_.reset(ChromotingHostContext::Create(task_runner).release());
55 56
56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); 57 const ServiceUrls* service_urls = ServiceUrls::GetInstance();
57 const bool xmpp_server_valid = 58 const bool xmpp_server_valid =
58 net::ParseHostAndPort(service_urls->xmpp_server_address(), 59 net::ParseHostAndPort(service_urls->xmpp_server_address(),
59 &xmpp_server_config_.host, 60 &xmpp_server_config_.host,
60 &xmpp_server_config_.port); 61 &xmpp_server_config_.port);
61 DCHECK(xmpp_server_valid); 62 DCHECK(xmpp_server_valid);
62 63
63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); 64 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls();
64 directory_bot_jid_ = service_urls->directory_bot_jid(); 65 directory_bot_jid_ = service_urls->directory_bot_jid();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 197 }
197 198
198 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) { 199 if (!message.GetString("directoryBotJid", &directory_bot_jid_)) {
199 SendErrorAndExit(response.Pass(), 200 SendErrorAndExit(response.Pass(),
200 "'directoryBotJid' not found in request."); 201 "'directoryBotJid' not found in request.");
201 return; 202 return;
202 } 203 }
203 #endif // !defined(NDEBUG) 204 #endif // !defined(NDEBUG)
204 205
205 // Create the It2Me host and start connecting. 206 // Create the It2Me host and start connecting.
206 it2me_host_ = factory_->CreateIt2MeHost(host_context_.get(), 207 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(),
207 host_context_->ui_task_runner(),
208 weak_ptr_, 208 weak_ptr_,
209 xmpp_config, 209 xmpp_config,
210 directory_bot_jid_); 210 directory_bot_jid_);
211 it2me_host_->Connect(); 211 it2me_host_->Connect();
212 212
213 SendMessageToClient(response.Pass()); 213 SendMessageToClient(response.Pass());
214 } 214 }
215 215
216 void It2MeNativeMessagingHost::ProcessDisconnect( 216 void It2MeNativeMessagingHost::ProcessDisconnect(
217 const base::DictionaryValue& message, 217 const base::DictionaryValue& message,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Stores the client user's name for the web-app to query. 296 // Stores the client user's name for the web-app to query.
297 void It2MeNativeMessagingHost::OnClientAuthenticated( 297 void It2MeNativeMessagingHost::OnClientAuthenticated(
298 const std::string& client_username) { 298 const std::string& client_username) {
299 DCHECK(task_runner()->BelongsToCurrentThread()); 299 DCHECK(task_runner()->BelongsToCurrentThread());
300 300
301 client_username_ = client_username; 301 client_username_ = client_username;
302 } 302 }
303 303
304 scoped_refptr<base::SingleThreadTaskRunner> 304 scoped_refptr<base::SingleThreadTaskRunner>
305 It2MeNativeMessagingHost::task_runner() const { 305 It2MeNativeMessagingHost::task_runner() const {
306 return host_context_->ui_task_runner(); 306 return task_runner_;
307 } 307 }
308 308
309 /* static */ 309 /* static */
310 std::string It2MeNativeMessagingHost::HostStateToString( 310 std::string It2MeNativeMessagingHost::HostStateToString(
311 It2MeHostState host_state) { 311 It2MeHostState host_state) {
312 return ValueToName(kIt2MeHostStates, host_state); 312 return ValueToName(kIt2MeHostStates, host_state);
313 } 313 }
314 314
315 } // namespace remoting 315 } // namespace remoting
316 316
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698