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

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: Address feedbacks 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/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"
19 #include "components/policy/core/common/policy_service.h"
18 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
19 #include "net/url_request/url_fetcher.h" 21 #include "net/url_request/url_request_context_getter.h"
20 #include "remoting/base/auth_token_util.h" 22 #include "remoting/base/auth_token_util.h"
21 #include "remoting/base/service_urls.h" 23 #include "remoting/base/service_urls.h"
22 #include "remoting/host/chromoting_host_context.h" 24 #include "remoting/host/chromoting_host_context.h"
23 #include "remoting/host/host_exit_codes.h" 25 #include "remoting/host/host_exit_codes.h"
24 #include "remoting/protocol/name_value_map.h" 26 #include "remoting/protocol/name_value_map.h"
25 27
26 namespace remoting { 28 namespace remoting {
27 29
28 namespace { 30 namespace {
29 31
30 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { 32 const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = {
31 {kDisconnected, "DISCONNECTED"}, 33 {kDisconnected, "DISCONNECTED"},
32 {kStarting, "STARTING"}, 34 {kStarting, "STARTING"},
33 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"}, 35 {kRequestedAccessCode, "REQUESTED_ACCESS_CODE"},
34 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"}, 36 {kReceivedAccessCode, "RECEIVED_ACCESS_CODE"},
35 {kConnected, "CONNECTED"}, 37 {kConnected, "CONNECTED"},
36 {kDisconnecting, "DISCONNECTING"}, 38 {kDisconnecting, "DISCONNECTING"},
37 {kError, "ERROR"}, 39 {kError, "ERROR"},
38 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, }; 40 {kInvalidDomainError, "INVALID_DOMAIN_ERROR"}, };
39 41
40 } // namespace 42 } // namespace
41 43
44 // static
45 scoped_ptr<extensions::NativeMessageHost>
46 It2MeNativeMessagingHost::CreateForChromeOS(
47 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
48 policy::PolicyService* policy_service) {
49
50 scoped_ptr<It2MeHostFactory> factory(new remoting::It2MeHostFactory());
51 scoped_ptr<ChromotingHostContext> context(
52 ChromotingHostContext::CreateForChromeOS(
53 // Remoting uses AutoThread as its threading primitive, which will
54 // exit itself (by posting a Quit message) when there are no more
55 // references to the task runner.
56 // On ChromeOS, the It2MeNativeMessagingHost is created on the UI
57 // thread of the browser process and its lifetime is explicitly
58 // managed by the browser process. Therefore, base::DoNothing is
59 // passed in as the quit closure.
60 new AutoThreadTaskRunner(base::MessageLoopProxy::current(),
61 base::Bind(&base::DoNothing)),
62 url_request_context_getter,
63 policy_service));
64
65 scoped_ptr<extensions::NativeMessageHost> host(new It2MeNativeMessagingHost(
66 context.Pass(),
67 factory.Pass()));
68 return host.Pass();
69 }
70
71 scoped_ptr<extensions::NativeMessageHost> It2MeNativeMessagingHost::Create(
Wez 2014/10/17 17:58:01 This is also // static
kelvinp 2014/10/20 00:21:18 Done.
72 scoped_ptr<ChromotingHostContext> context,
73 scoped_ptr<It2MeHostFactory> factory) {
74 scoped_ptr<extensions::NativeMessageHost> host(new It2MeNativeMessagingHost(
75 context.Pass(),
76 factory.Pass()));
Wez 2014/10/17 17:58:01 Why is this Create() method parameterized on It2Me
kelvinp 2014/10/20 00:21:18 Good Idea. In this case, I can simply get rid of
77 return host.Pass();
78 }
79
80
42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( 81 It2MeNativeMessagingHost::It2MeNativeMessagingHost(
43 scoped_refptr<AutoThreadTaskRunner> task_runner, 82 scoped_ptr<ChromotingHostContext> context,
44 scoped_ptr<It2MeHostFactory> factory) 83 scoped_ptr<It2MeHostFactory> factory)
45 : client_(NULL), 84 : client_(NULL),
46 factory_(factory.Pass()), 85 factory_(factory.Pass()),
47 weak_factory_(this) { 86 weak_factory_(this) {
48 weak_ptr_ = weak_factory_.GetWeakPtr(); 87 weak_ptr_ = weak_factory_.GetWeakPtr();
49 88
50 // Initialize the host context to manage the threads for the it2me host. 89 host_context_ = context.Pass();
51 // The native messaging host, rather than the It2MeHost object, owns and 90 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 91
56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); 92 const ServiceUrls* service_urls = ServiceUrls::GetInstance();
57 const bool xmpp_server_valid = 93 const bool xmpp_server_valid =
58 net::ParseHostAndPort(service_urls->xmpp_server_address(), 94 net::ParseHostAndPort(service_urls->xmpp_server_address(),
59 &xmpp_server_config_.host, 95 &xmpp_server_config_.host,
60 &xmpp_server_config_.port); 96 &xmpp_server_config_.port);
61 DCHECK(xmpp_server_valid); 97 DCHECK(xmpp_server_valid);
62 98
63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); 99 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls();
64 directory_bot_jid_ = service_urls->directory_bot_jid(); 100 directory_bot_jid_ = service_urls->directory_bot_jid();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Stores the client user's name for the web-app to query. 332 // Stores the client user's name for the web-app to query.
297 void It2MeNativeMessagingHost::OnClientAuthenticated( 333 void It2MeNativeMessagingHost::OnClientAuthenticated(
298 const std::string& client_username) { 334 const std::string& client_username) {
299 DCHECK(task_runner()->BelongsToCurrentThread()); 335 DCHECK(task_runner()->BelongsToCurrentThread());
300 336
301 client_username_ = client_username; 337 client_username_ = client_username;
302 } 338 }
303 339
304 scoped_refptr<base::SingleThreadTaskRunner> 340 scoped_refptr<base::SingleThreadTaskRunner>
305 It2MeNativeMessagingHost::task_runner() const { 341 It2MeNativeMessagingHost::task_runner() const {
306 return host_context_->ui_task_runner(); 342 return task_runner_;
307 } 343 }
308 344
309 /* static */ 345 /* static */
310 std::string It2MeNativeMessagingHost::HostStateToString( 346 std::string It2MeNativeMessagingHost::HostStateToString(
311 It2MeHostState host_state) { 347 It2MeHostState host_state) {
312 return ValueToName(kIt2MeHostStates, host_state); 348 return ValueToName(kIt2MeHostStates, host_state);
313 } 349 }
314 350
315 } // namespace remoting 351 } // namespace remoting
316 352
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698