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

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: Move DEPS to remoting/host 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
42 It2MeNativeMessagingHost::It2MeNativeMessagingHost( 71 It2MeNativeMessagingHost::It2MeNativeMessagingHost(
43 scoped_refptr<AutoThreadTaskRunner> task_runner, 72 scoped_ptr<ChromotingHostContext> context,
44 scoped_ptr<It2MeHostFactory> factory) 73 scoped_ptr<It2MeHostFactory> factory)
45 : client_(NULL), 74 : client_(NULL),
46 factory_(factory.Pass()), 75 factory_(factory.Pass()),
47 weak_factory_(this) { 76 weak_factory_(this) {
48 weak_ptr_ = weak_factory_.GetWeakPtr(); 77 weak_ptr_ = weak_factory_.GetWeakPtr();
49 78
50 // Initialize the host context to manage the threads for the it2me host. 79 host_context_ = context.Pass();
51 // The native messaging host, rather than the It2MeHost object, owns and 80 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 81
56 const ServiceUrls* service_urls = ServiceUrls::GetInstance(); 82 const ServiceUrls* service_urls = ServiceUrls::GetInstance();
57 const bool xmpp_server_valid = 83 const bool xmpp_server_valid =
58 net::ParseHostAndPort(service_urls->xmpp_server_address(), 84 net::ParseHostAndPort(service_urls->xmpp_server_address(),
59 &xmpp_server_config_.host, 85 &xmpp_server_config_.host,
60 &xmpp_server_config_.port); 86 &xmpp_server_config_.port);
61 DCHECK(xmpp_server_valid); 87 DCHECK(xmpp_server_valid);
62 88
63 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls(); 89 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls();
64 directory_bot_jid_ = service_urls->directory_bot_jid(); 90 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. 322 // Stores the client user's name for the web-app to query.
297 void It2MeNativeMessagingHost::OnClientAuthenticated( 323 void It2MeNativeMessagingHost::OnClientAuthenticated(
298 const std::string& client_username) { 324 const std::string& client_username) {
299 DCHECK(task_runner()->BelongsToCurrentThread()); 325 DCHECK(task_runner()->BelongsToCurrentThread());
300 326
301 client_username_ = client_username; 327 client_username_ = client_username;
302 } 328 }
303 329
304 scoped_refptr<base::SingleThreadTaskRunner> 330 scoped_refptr<base::SingleThreadTaskRunner>
305 It2MeNativeMessagingHost::task_runner() const { 331 It2MeNativeMessagingHost::task_runner() const {
306 return host_context_->ui_task_runner(); 332 return task_runner_;
307 } 333 }
308 334
309 /* static */ 335 /* static */
310 std::string It2MeNativeMessagingHost::HostStateToString( 336 std::string It2MeNativeMessagingHost::HostStateToString(
311 It2MeHostState host_state) { 337 It2MeHostState host_state) {
312 return ValueToName(kIt2MeHostStates, host_state); 338 return ValueToName(kIt2MeHostStates, host_state);
313 } 339 }
314 340
315 } // namespace remoting 341 } // namespace remoting
316 342
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698