Index: remoting/host/it2me/it2me_native_messaging_host.cc |
diff --git a/remoting/host/it2me/it2me_native_messaging_host.cc b/remoting/host/it2me/it2me_native_messaging_host.cc |
index 24ddc1b8dc38c72475555f4c0dbc00ea915aa62d..0dcca9ede40fc27c441b8b65020897bccb05bacc 100644 |
--- a/remoting/host/it2me/it2me_native_messaging_host.cc |
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc |
@@ -11,12 +11,14 @@ |
#include "base/callback.h" |
#include "base/json/json_reader.h" |
#include "base/json/json_writer.h" |
+#include "base/message_loop/message_loop.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringize_macros.h" |
#include "base/threading/thread.h" |
#include "base/values.h" |
+#include "components/policy/core/common/policy_service.h" |
#include "net/base/net_util.h" |
-#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_request_context_getter.h" |
#include "remoting/base/auth_token_util.h" |
#include "remoting/base/service_urls.h" |
#include "remoting/host/chromoting_host_context.h" |
@@ -39,19 +41,53 @@ const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { |
} // namespace |
+// static |
+scoped_ptr<extensions::NativeMessageHost> |
+It2MeNativeMessagingHost::CreateForChromeOS( |
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
+ policy::PolicyService* policy_service) { |
+ |
+ scoped_ptr<It2MeHostFactory> factory(new remoting::It2MeHostFactory()); |
+ scoped_ptr<ChromotingHostContext> context( |
+ ChromotingHostContext::CreateForChromeOS( |
+ // Remoting uses AutoThread as its threading primitive, which will |
+ // exit itself (by posting a Quit message) when there are no more |
+ // references to the task runner. |
+ // On ChromeOS, the It2MeNativeMessagingHost is created on the UI |
+ // thread of the browser process and its lifetime is explicitly |
+ // managed by the browser process. Therefore, base::DoNothing is |
+ // passed in as the quit closure. |
+ new AutoThreadTaskRunner(base::MessageLoopProxy::current(), |
+ base::Bind(&base::DoNothing)), |
+ url_request_context_getter, |
+ policy_service)); |
+ |
+ scoped_ptr<extensions::NativeMessageHost> host(new It2MeNativeMessagingHost( |
+ context.Pass(), |
+ factory.Pass())); |
+ return host.Pass(); |
+} |
+ |
+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.
|
+ scoped_ptr<ChromotingHostContext> context, |
+ scoped_ptr<It2MeHostFactory> factory) { |
+ scoped_ptr<extensions::NativeMessageHost> host(new It2MeNativeMessagingHost( |
+ context.Pass(), |
+ 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
|
+ return host.Pass(); |
+} |
+ |
+ |
It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
- scoped_refptr<AutoThreadTaskRunner> task_runner, |
+ scoped_ptr<ChromotingHostContext> context, |
scoped_ptr<It2MeHostFactory> factory) |
: client_(NULL), |
factory_(factory.Pass()), |
weak_factory_(this) { |
weak_ptr_ = weak_factory_.GetWeakPtr(); |
- // Initialize the host context to manage the threads for the it2me host. |
- // The native messaging host, rather than the It2MeHost object, owns and |
- // maintains the lifetime of the host context. |
- |
- host_context_.reset(ChromotingHostContext::Create(task_runner).release()); |
+ host_context_ = context.Pass(); |
+ task_runner_ = host_context_->ui_task_runner(); |
const ServiceUrls* service_urls = ServiceUrls::GetInstance(); |
const bool xmpp_server_valid = |
@@ -303,7 +339,7 @@ void It2MeNativeMessagingHost::OnClientAuthenticated( |
scoped_refptr<base::SingleThreadTaskRunner> |
It2MeNativeMessagingHost::task_runner() const { |
- return host_context_->ui_task_runner(); |
+ return task_runner_; |
} |
/* static */ |