summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 19:11:48 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-17 19:11:48 +0000
commite6ed01713f65a7d475b593657d5e6889a5941d44 (patch)
tree39278026fbcff3fdd98344442a09626945f1a1a0 /remoting
parent659ba74332cd6353af762787efdde4f78c51bafa (diff)
downloadchromium_src-e6ed01713f65a7d475b593657d5e6889a5941d44.zip
chromium_src-e6ed01713f65a7d475b593657d5e6889a5941d44.tar.gz
chromium_src-e6ed01713f65a7d475b593657d5e6889a5941d44.tar.bz2
Move URLRequestContextGetter creation to ChromotingHostContext.
Review URL: http://codereview.chromium.org/9956153 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132613 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/chromoting_host_context.cc25
-rw-r--r--remoting/host/chromoting_host_context.h12
-rw-r--r--remoting/host/chromoting_host_context_unittest.cc2
-rw-r--r--remoting/host/desktop_environment.cc2
-rw-r--r--remoting/host/oauth_client.cc26
-rw-r--r--remoting/host/oauth_client.h12
-rw-r--r--remoting/host/remoting_me2me_host.cc6
7 files changed, 51 insertions, 34 deletions
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index 74d214c..d693b55 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/threading/thread.h"
+#include "remoting/host/url_request_context.h"
#include "remoting/jingle_glue/jingle_thread.h"
namespace remoting {
@@ -17,6 +18,7 @@ ChromotingHostContext::ChromotingHostContext(
: main_thread_("ChromotingMainThread"),
encode_thread_("ChromotingEncodeThread"),
desktop_thread_("ChromotingDesktopThread"),
+ io_thread_("ChromotingIOThread"),
file_thread_("ChromotingFileIOThread"),
ui_message_loop_(ui_message_loop) {
}
@@ -26,10 +28,18 @@ ChromotingHostContext::~ChromotingHostContext() {
bool ChromotingHostContext::Start() {
// Start all the threads.
- return main_thread_.Start() && encode_thread_.Start() &&
+ bool started = main_thread_.Start() && encode_thread_.Start() &&
jingle_thread_.Start() && desktop_thread_.Start() &&
+ io_thread_.StartWithOptions(
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)) &&
file_thread_.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0));
+ if (!started)
+ return false;
+
+ url_request_context_getter_ = new URLRequestContextGetter(
+ io_thread_.message_loop(), file_thread_.message_loop());
+ return true;
}
JingleThread* ChromotingHostContext::jingle_thread() {
@@ -56,8 +66,17 @@ base::MessageLoopProxy* ChromotingHostContext::ui_message_loop() {
return ui_message_loop_;
}
-MessageLoop* ChromotingHostContext::file_message_loop() {
- return file_thread_.message_loop();
+base::MessageLoopProxy* ChromotingHostContext::io_message_loop() {
+ return io_thread_.message_loop_proxy();
+}
+
+base::MessageLoopProxy* ChromotingHostContext::file_message_loop() {
+ return file_thread_.message_loop_proxy();
+}
+
+const scoped_refptr<URLRequestContextGetter>&
+ChromotingHostContext::url_request_context_getter() {
+ return url_request_context_getter_;
}
} // namespace remoting
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 60b261e..c4d557e 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -14,6 +14,8 @@
namespace remoting {
+class URLRequestContextGetter;
+
// A class that manages threads and running context for the chromoting host
// process. This class is virtual only for testing purposes (see below).
class ChromotingHostContext {
@@ -31,13 +33,14 @@ class ChromotingHostContext {
virtual JingleThread* jingle_thread();
-
virtual MessageLoop* main_message_loop();
virtual MessageLoop* encode_message_loop();
virtual base::MessageLoopProxy* network_message_loop();
virtual MessageLoop* desktop_message_loop();
virtual base::MessageLoopProxy* ui_message_loop();
- virtual MessageLoop* file_message_loop();
+ virtual base::MessageLoopProxy* io_message_loop();
+ virtual base::MessageLoopProxy* file_message_loop();
+ const scoped_refptr<URLRequestContextGetter>& url_request_context_getter();
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop);
@@ -56,11 +59,16 @@ class ChromotingHostContext {
// This is NOT a Chrome-style UI thread.
base::Thread desktop_thread_;
+ // Thread for non-blocking IO operations.
+ base::Thread io_thread_;
+
// Thread for blocking IO operations.
base::Thread file_thread_;
scoped_refptr<base::MessageLoopProxy> ui_message_loop_;
+ scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
+
DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
};
diff --git a/remoting/host/chromoting_host_context_unittest.cc b/remoting/host/chromoting_host_context_unittest.cc
index 179673c..b48d322 100644
--- a/remoting/host/chromoting_host_context_unittest.cc
+++ b/remoting/host/chromoting_host_context_unittest.cc
@@ -12,7 +12,7 @@ namespace remoting {
// A simple test that starts and stop the context. This tests the context
// operates properly and all threads and message loops are valid.
TEST(ChromotingHostContextTest, StartAndStop) {
- MessageLoop message_loop;
+ MessageLoopForUI message_loop;
ChromotingHostContext context(base::MessageLoopProxy::current());
context.Start();
diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc
index f5d45f8..97586f9 100644
--- a/remoting/host/desktop_environment.cc
+++ b/remoting/host/desktop_environment.cc
@@ -52,7 +52,7 @@ scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService(
#if defined(OS_WIN)
event_executor.reset(new SessionEventExecutorWin(
context->desktop_message_loop(),
- context->file_message_loop()->message_loop_proxy(),
+ context->file_message_loop(),
event_executor.Pass()));
#endif
diff --git a/remoting/host/oauth_client.cc b/remoting/host/oauth_client.cc
index 34ab1c1..8156bfd 100644
--- a/remoting/host/oauth_client.cc
+++ b/remoting/host/oauth_client.cc
@@ -11,25 +11,19 @@
namespace remoting {
OAuthClient::OAuthClient()
- : network_thread_("OAuthNetworkThread"),
- file_thread_("OAuthFileThread"),
- delegate_(NULL) {
- network_thread_.StartWithOptions(
- base::Thread::Options(MessageLoop::TYPE_IO, 0));
- file_thread_.StartWithOptions(
- base::Thread::Options(MessageLoop::TYPE_IO, 0));
- url_request_context_getter_ = new URLRequestContextGetter(
- network_thread_.message_loop(), file_thread_.message_loop());
- gaia_oauth_client_.reset(
- new GaiaOAuthClient(kGaiaOAuth2Url, url_request_context_getter_.get()));
+ : delegate_(NULL) {
}
OAuthClient::~OAuthClient() {
}
-void OAuthClient::Start(const std::string& refresh_token,
- OAuthClient::Delegate* delegate,
- base::MessageLoopProxy* message_loop) {
+void OAuthClient::Start(
+ const scoped_refptr<URLRequestContextGetter>& url_context_,
+ const std::string& refresh_token,
+ OAuthClient::Delegate* delegate,
+ base::MessageLoopProxy* message_loop) {
+ gaia_oauth_client_.reset(
+ new GaiaOAuthClient(kGaiaOAuth2Url, url_context_));
refresh_token_ = refresh_token;
delegate_ = delegate;
message_loop_ = message_loop;
@@ -76,12 +70,12 @@ void OAuthClient::RefreshToken() {
"440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com",
"Bgur6DFiOMM1h8x-AQpuTQlK"
};
-#else
+#else // OFFICIAL_BUILD
OAuthClientInfo client_info = {
"440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com",
"W2ieEsG-R1gIA4MMurGrgMc_"
};
-#endif
+#endif // !OFFICIAL_BUILD
gaia_oauth_client_->RefreshToken(client_info, refresh_token_, -1, this);
}
diff --git a/remoting/host/oauth_client.h b/remoting/host/oauth_client.h
index 559bc5f..a92077a 100644
--- a/remoting/host/oauth_client.h
+++ b/remoting/host/oauth_client.h
@@ -10,9 +10,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "base/threading/thread.h"
#include "remoting/host/gaia_oauth_client.h"
-#include "remoting/host/url_request_context.h"
namespace base {
class MessageLoopProxy;
@@ -20,6 +18,8 @@ class MessageLoopProxy;
namespace remoting {
+class URLRequestContextGetter;
+
class OAuthClient : public GaiaOAuthClient::Delegate {
public:
class Delegate {
@@ -42,7 +42,8 @@ class OAuthClient : public GaiaOAuthClient::Delegate {
//
// The delegate is accessed on the specified message loop, and must out-live
// it.
- void Start(const std::string& refresh_token,
+ void Start(const scoped_refptr<URLRequestContextGetter>& url_context_,
+ const std::string& refresh_token,
Delegate* delegate,
base::MessageLoopProxy* message_loop);
@@ -58,11 +59,6 @@ class OAuthClient : public GaiaOAuthClient::Delegate {
private:
void RefreshToken();
- // TODO(jamiewalch): Move these to the ChromotingHostContext class so
- // that the URLRequestContextGetter is available for other purposes.
- base::Thread network_thread_;
- base::Thread file_thread_;
- scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
scoped_ptr<GaiaOAuthClient> gaia_oauth_client_;
std::string refresh_token_;
OAuthClient::Delegate* delegate_;
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index ad8c175..c71b8e5 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -179,7 +179,8 @@ class HostProcess : public OAuthClient::Delegate {
// the access token is available.
//
// TODO(sergeyu): Move this code to SignalingConnector.
- oauth_client_.Start(oauth_refresh_token_, this,
+ oauth_client_.Start(context_->url_request_context_getter(),
+ oauth_refresh_token_, this,
message_loop_.message_loop_proxy());
} else {
StartWatchingNatPolicy();
@@ -221,8 +222,7 @@ class HostProcess : public OAuthClient::Delegate {
private:
void StartWatchingNatPolicy() {
nat_policy_.reset(
- policy_hack::NatPolicy::Create(
- context_->file_message_loop()->message_loop_proxy()));
+ policy_hack::NatPolicy::Create(context_->file_message_loop()));
nat_policy_->StartWatching(
base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this)));
}