diff options
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/DEPS | 2 | ||||
-rw-r--r-- | remoting/host/gaia_oauth_client.cc | 136 | ||||
-rw-r--r-- | remoting/host/gaia_oauth_client.h | 19 | ||||
-rw-r--r-- | remoting/host/signaling_connector.cc | 8 | ||||
-rw-r--r-- | remoting/host/signaling_connector.h | 3 | ||||
-rw-r--r-- | remoting/host/url_fetcher.cc | 207 | ||||
-rw-r--r-- | remoting/host/url_fetcher.h | 63 | ||||
-rw-r--r-- | remoting/host/url_fetcher_unittest.cc | 94 | ||||
-rw-r--r-- | remoting/host/url_request_context.h | 2 | ||||
-rw-r--r-- | remoting/remoting.gyp | 10 |
10 files changed, 402 insertions, 142 deletions
diff --git a/remoting/host/DEPS b/remoting/host/DEPS index c84c993..ad3bc87 100644 --- a/remoting/host/DEPS +++ b/remoting/host/DEPS @@ -1,11 +1,11 @@ include_rules = [ "+ui", "+base/crypto", - "+content/public/common", "+net/base", "+net/ftp", "+net/http", "+net/proxy", + "+net/test", "+net/url_request", "+remoting/protocol", diff --git a/remoting/host/gaia_oauth_client.cc b/remoting/host/gaia_oauth_client.cc index 63c7869..f20cb82 100644 --- a/remoting/host/gaia_oauth_client.cc +++ b/remoting/host/gaia_oauth_client.cc @@ -4,16 +4,17 @@ #include "remoting/host/gaia_oauth_client.h" +#include "base/bind.h" #include "base/json/json_reader.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" -#include "content/public/common/url_fetcher.h" -#include "content/public/common/url_fetcher_delegate.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" #include "net/http/http_status_code.h" #include "net/url_request/url_request_context_getter.h" +#include "net/url_request/url_request_status.h" +#include "remoting/host/url_fetcher.h" namespace { const char kAccessTokenValue[] = "access_token"; @@ -24,64 +25,37 @@ const char kExpiresInValue[] = "expires_in"; namespace remoting { class GaiaOAuthClient::Core - : public base::RefCountedThreadSafe<GaiaOAuthClient::Core>, - public content::URLFetcherDelegate { + : public base::RefCountedThreadSafe<GaiaOAuthClient::Core> { public: Core(const std::string& gaia_url, net::URLRequestContextGetter* request_context_getter) : gaia_url_(gaia_url), - num_retries_(0), request_context_getter_(request_context_getter), delegate_(NULL) { } virtual ~Core() { } - void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, - const std::string& auth_code, - int max_retries, - GaiaOAuthClient::Delegate* delegate); void RefreshToken(const OAuthClientInfo& oauth_client_info, const std::string& refresh_token, - int max_retries, GaiaOAuthClient::Delegate* delegate); - // content::URLFetcherDelegate implementation. - virtual void OnURLFetchComplete(const content::URLFetcher* source); - private: - void MakeGaiaRequest(std::string post_body, - int max_retries, - GaiaOAuthClient::Delegate* delegate); - void HandleResponse(const content::URLFetcher* source, - bool* should_retry_request); + void OnUrlFetchComplete(const net::URLRequestStatus& status, + int response_code, + const std::string& response); GURL gaia_url_; - int num_retries_; scoped_refptr<net::URLRequestContextGetter> request_context_getter_; GaiaOAuthClient::Delegate* delegate_; - scoped_ptr<content::URLFetcher> request_; + scoped_ptr<UrlFetcher> request_; }; -void GaiaOAuthClient::Core::GetTokensFromAuthCode( - const OAuthClientInfo& oauth_client_info, - const std::string& auth_code, - int max_retries, - GaiaOAuthClient::Delegate* delegate) { - std::string post_body = - "code=" + net::EscapeUrlEncodedData(auth_code, true) + - "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, - true) + - "&client_secret=" + - net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) + - "&redirect_uri=oob&grant_type=authorization_code"; - MakeGaiaRequest(post_body, max_retries, delegate); -} - void GaiaOAuthClient::Core::RefreshToken( const OAuthClientInfo& oauth_client_info, const std::string& refresh_token, - int max_retries, GaiaOAuthClient::Delegate* delegate) { + DCHECK(!request_.get()) << "Tried to fetch two things at once!"; + std::string post_body = "refresh_token=" + net::EscapeUrlEncodedData(refresh_token, true) + "&client_id=" + net::EscapeUrlEncodedData(oauth_client_info.client_id, @@ -89,63 +63,36 @@ void GaiaOAuthClient::Core::RefreshToken( "&client_secret=" + net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) + "&grant_type=refresh_token"; - MakeGaiaRequest(post_body, max_retries, delegate); -} - -void GaiaOAuthClient::Core::MakeGaiaRequest( - std::string post_body, - int max_retries, - GaiaOAuthClient::Delegate* delegate) { - DCHECK(!request_.get()) << "Tried to fetch two things at once!"; delegate_ = delegate; - num_retries_ = 0; - request_.reset(content::URLFetcher::Create( - 0, gaia_url_, content::URLFetcher::POST, this)); + request_.reset(new UrlFetcher(gaia_url_, UrlFetcher::POST)); request_->SetRequestContext(request_context_getter_); request_->SetUploadData("application/x-www-form-urlencoded", post_body); - request_->SetMaxRetries(max_retries); - request_->Start(); + request_->Start(base::Bind(&GaiaOAuthClient::Core::OnUrlFetchComplete, this)); } -// URLFetcher::Delegate implementation. -void GaiaOAuthClient::Core::OnURLFetchComplete( - const content::URLFetcher* source) { - bool should_retry = false; - HandleResponse(source, &should_retry); - if (should_retry) { - // Explicitly call ReceivedContentWasMalformed() to ensure the current - // request gets counted as a failure for calculation of the back-off - // period. If it was already a failure by status code, this call will - // be ignored. - request_->ReceivedContentWasMalformed(); - num_retries_++; - // We must set our request_context_getter_ again because - // URLFetcher::Core::RetryOrCompleteUrlFetch resets it to NULL... - request_->SetRequestContext(request_context_getter_); - request_->Start(); - } else { - request_.reset(); +void GaiaOAuthClient::Core::OnUrlFetchComplete( + const net::URLRequestStatus& status, + int response_code, + const std::string& response) { + request_.reset(); + + if (!status.is_success()) { + delegate_->OnNetworkError(response_code); + return; } -} -void GaiaOAuthClient::Core::HandleResponse( - const content::URLFetcher* source, - bool* should_retry_request) { - *should_retry_request = false; - // RC_BAD_REQUEST means the arguments are invalid. No point retrying. We are - // done here. - if (source->GetResponseCode() == net::HTTP_BAD_REQUEST) { + // HTTP_BAD_REQUEST means the arguments are invalid. + if (response_code == net::HTTP_BAD_REQUEST) { LOG(ERROR) << "Gaia response: response code=net::HTTP_BAD_REQUEST."; delegate_->OnOAuthError(); return; } + std::string access_token; std::string refresh_token; int expires_in_seconds = 0; - if (source->GetResponseCode() == net::HTTP_OK) { - std::string data; - source->GetResponseAsString(&data); - scoped_ptr<Value> message_value(base::JSONReader::Read(data)); + if (response_code == net::HTTP_OK) { + scoped_ptr<Value> message_value(base::JSONReader::Read(response)); if (message_value.get() && message_value->IsType(Value::TYPE_DICTIONARY)) { scoped_ptr<DictionaryValue> response_dict( @@ -158,25 +105,14 @@ void GaiaOAuthClient::Core::HandleResponse( << "', refresh_token='" << refresh_token << "', expires in " << expires_in_seconds << " second(s)"; } else { - LOG(ERROR) << "Gaia response: response code=" << source->GetResponseCode(); + LOG(ERROR) << "Gaia response: response code=" << response_code; } + if (access_token.empty()) { - // If we don't have an access token yet and the the error was not - // RC_BAD_REQUEST, we may need to retry. - if ((-1 != source->GetMaxRetries()) && - (num_retries_ > source->GetMaxRetries())) { - // Retry limit reached. Give up. - delegate_->OnNetworkError(source->GetResponseCode()); - } else { - *should_retry_request = true; - } + delegate_->OnNetworkError(response_code); } else if (refresh_token.empty()) { // If we only have an access token, then this was a refresh request. delegate_->OnRefreshTokenResponse(access_token, expires_in_seconds); - } else { - delegate_->OnGetTokensResponse(refresh_token, - access_token, - expires_in_seconds); } } @@ -188,25 +124,11 @@ GaiaOAuthClient::GaiaOAuthClient(const std::string& gaia_url, GaiaOAuthClient::~GaiaOAuthClient() { } - -void GaiaOAuthClient::GetTokensFromAuthCode( - const OAuthClientInfo& oauth_client_info, - const std::string& auth_code, - int max_retries, - Delegate* delegate) { - return core_->GetTokensFromAuthCode(oauth_client_info, - auth_code, - max_retries, - delegate); -} - void GaiaOAuthClient::RefreshToken(const OAuthClientInfo& oauth_client_info, const std::string& refresh_token, - int max_retries, Delegate* delegate) { return core_->RefreshToken(oauth_client_info, refresh_token, - max_retries, delegate); } diff --git a/remoting/host/gaia_oauth_client.h b/remoting/host/gaia_oauth_client.h index f893037..58178dc 100644 --- a/remoting/host/gaia_oauth_client.h +++ b/remoting/host/gaia_oauth_client.h @@ -36,35 +36,21 @@ class GaiaOAuthClient { public: virtual ~Delegate() { } - // Invoked on a successful response to the GetTokensFromAuthCode request. - virtual void OnGetTokensResponse(const std::string& refresh_token, - const std::string& access_token, - int expires_in_seconds) = 0; // Invoked on a successful response to the RefreshToken request. virtual void OnRefreshTokenResponse(const std::string& access_token, int expires_in_seconds) = 0; // Invoked when there is an OAuth error with one of the requests. virtual void OnOAuthError() = 0; - // Invoked when there is a network error or upon receiving an invalid - // response. This is invoked when the maximum number of retries have been - // exhausted. If max_retries is -1, this is never invoked. + // Invoked when there is a network error or upon receiving an + // invalid response. virtual void OnNetworkError(int response_code) = 0; }; GaiaOAuthClient(const std::string& gaia_url, net::URLRequestContextGetter* context_getter); ~GaiaOAuthClient(); - // In the below methods, |max_retries| specifies the maximum number of times - // we should retry on a network error in invalid response. This does not - // apply in the case of an OAuth error (i.e. there was something wrong with - // the input arguments). Setting |max_retries| to -1 implies infinite retries. - void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, - const std::string& auth_code, - int max_retries, - Delegate* delegate); void RefreshToken(const OAuthClientInfo& oauth_client_info, const std::string& refresh_token, - int max_retries, Delegate* delegate); private: @@ -73,6 +59,7 @@ class GaiaOAuthClient { scoped_refptr<Core> core_; DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); }; + } // namespace remoting #endif // CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ diff --git a/remoting/host/signaling_connector.cc b/remoting/host/signaling_connector.cc index 9b80a81..25bef4c 100644 --- a/remoting/host/signaling_connector.cc +++ b/remoting/host/signaling_connector.cc @@ -82,12 +82,6 @@ void SignalingConnector::OnOnlineStateChanged(bool online) { } } -void SignalingConnector::OnGetTokensResponse(const std::string& refresh_token, - const std::string& access_token, - int expires_seconds) { - NOTREACHED(); -} - void SignalingConnector::OnRefreshTokenResponse(const std::string& access_token, int expires_seconds) { DCHECK(CalledOnValidThread()); @@ -172,7 +166,7 @@ void SignalingConnector::RefreshOAuthToken() { #endif // !OFFICIAL_BUILD refreshing_oauth_token_ = true; gaia_oauth_client_->RefreshToken( - client_info, oauth_credentials_->refresh_token, 1, this); + client_info, oauth_credentials_->refresh_token, this); } } // namespace remoting diff --git a/remoting/host/signaling_connector.h b/remoting/host/signaling_connector.h index 227bf71..17a8f6a 100644 --- a/remoting/host/signaling_connector.h +++ b/remoting/host/signaling_connector.h @@ -58,9 +58,6 @@ class SignalingConnector virtual void OnOnlineStateChanged(bool online) OVERRIDE; // GaiaOAuthClient::Delegate interface. - virtual void OnGetTokensResponse(const std::string& refresh_token, - const std::string& access_token, - int expires_seconds) OVERRIDE; virtual void OnRefreshTokenResponse(const std::string& access_token, int expires_seconds) OVERRIDE; virtual void OnOAuthError() OVERRIDE; diff --git a/remoting/host/url_fetcher.cc b/remoting/host/url_fetcher.cc new file mode 100644 index 0000000..1844d0c --- /dev/null +++ b/remoting/host/url_fetcher.cc @@ -0,0 +1,207 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/url_fetcher.h" + +#include "base/location.h" +#include "base/message_loop_proxy.h" +#include "googleurl/src/gurl.h" +#include "net/base/io_buffer.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_context_getter.h" + +namespace remoting { + +const int kBufferSize = 4096; + +class UrlFetcher::Core : public base::RefCountedThreadSafe<Core>, + public net::URLRequest::Delegate { + public: + Core(const GURL& url, Method method); + + void SetRequestContext( + net::URLRequestContextGetter* request_context_getter); + void SetUploadData(const std::string& upload_content_type, + const std::string& upload_content); + void Start(const UrlFetcher::DoneCallback& done_callback); + + void Detach(); + + // net::UrlRequest::Delegate interface. + virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; + virtual void OnReadCompleted(net::URLRequest* request, + int bytes_read) OVERRIDE; + + private: + friend class base::RefCountedThreadSafe<Core>; + virtual ~Core(); + + // Helper methods called on the IO thread. + void DoStart(); + void ReadResponse(); + void CancelRequest(); + + // Helper called on the delegate thread to invoke |done_callback_|. + void CallCallback(const net::URLRequestStatus& status, + int response_code); + + GURL url_; + Method method_; + + scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; + scoped_refptr<base::MessageLoopProxy> io_message_loop_; + + scoped_refptr<net::URLRequestContextGetter> request_context_getter_; + + std::string upload_content_; + std::string upload_content_type_; + + scoped_ptr<net::URLRequest> request_; + + scoped_refptr<net::IOBuffer> buffer_; + std::string data_; + + UrlFetcher::DoneCallback done_callback_; + + DISALLOW_COPY_AND_ASSIGN(Core); +}; + +UrlFetcher::Core::Core(const GURL& url, Method method) + : url_(url), + method_(method), + delegate_message_loop_(base::MessageLoopProxy::current()), + buffer_(new net::IOBuffer(kBufferSize)) { +} + +UrlFetcher::Core::~Core() { +} + +void UrlFetcher::Core::SetRequestContext( + net::URLRequestContextGetter* request_context_getter) { + DCHECK(!request_context_getter_); + request_context_getter_ = request_context_getter; +} + +void UrlFetcher::Core::SetUploadData(const std::string& upload_content_type, + const std::string& upload_content) { + upload_content_type_ = upload_content_type; + upload_content_ = upload_content; +} + +void UrlFetcher::Core::Start(const UrlFetcher::DoneCallback& done_callback) { + done_callback_ = done_callback; + io_message_loop_ = request_context_getter_->GetIOMessageLoopProxy(); + DCHECK(io_message_loop_); + io_message_loop_->PostTask(FROM_HERE, base::Bind( + &UrlFetcher::Core::DoStart, this)); +} + +void UrlFetcher::Core::Detach() { + DCHECK(delegate_message_loop_->BelongsToCurrentThread()); + io_message_loop_->PostTask( + FROM_HERE, base::Bind(&UrlFetcher::Core::CancelRequest, this)); + done_callback_.Reset(); +} + +void UrlFetcher::Core::OnResponseStarted(net::URLRequest* request) { + DCHECK_EQ(request, request_.get()); + DCHECK(io_message_loop_->BelongsToCurrentThread()); + ReadResponse(); +} + +void UrlFetcher::Core::OnReadCompleted(net::URLRequest* request, + int bytes_read) { + DCHECK_EQ(request, request_.get()); + DCHECK(io_message_loop_->BelongsToCurrentThread()); + + do { + if (!request_->status().is_success() || bytes_read <= 0) + break; + + data_.append(buffer_->data(), bytes_read); + } while (request_->Read(buffer_, kBufferSize, &bytes_read)); + + const net::URLRequestStatus status = request_->status(); + if (!status.is_io_pending()) { + // We are done. Post a task to call |done_callback_|. + delegate_message_loop_->PostTask( + FROM_HERE, base::Bind(&UrlFetcher::Core::CallCallback, this, status, + request_->GetResponseCode())); + } +} + +void UrlFetcher::Core::DoStart() { + DCHECK(io_message_loop_->BelongsToCurrentThread()); + + request_.reset(new net::URLRequest(url_, this)); + request_->set_context(request_context_getter_->GetURLRequestContext()); + + switch (method_) { + case GET: + break; + + case POST: + DCHECK(!upload_content_.empty()); + DCHECK(!upload_content_type_.empty()); + request_->set_method("POST"); + + net::HttpRequestHeaders headers; + headers.SetHeader(net::HttpRequestHeaders::kContentType, + upload_content_type_); + request_->SetExtraRequestHeaders(headers); + + request_->AppendBytesToUpload( + upload_content_.data(), static_cast<int>(upload_content_.length())); + break; + } + + request_->Start(); +} + +void UrlFetcher::Core::ReadResponse() { + int bytes_read = 0; + if (request_->status().is_success()) { + request_->Read(buffer_, kBufferSize, &bytes_read); + } + OnReadCompleted(request_.get(), bytes_read); +} + +void UrlFetcher::Core::CallCallback(const net::URLRequestStatus& status, + int response_code) { + DCHECK(delegate_message_loop_->BelongsToCurrentThread()); + if (!done_callback_.is_null()) { + done_callback_.Run(status, response_code, data_); + } +} + +void UrlFetcher::Core::CancelRequest() { + if (request_.get()) { + request_->Cancel(); + request_.reset(); + } +} + +UrlFetcher::UrlFetcher(const GURL& url, Method method) + : core_ (new Core(url, method)) { +} + +UrlFetcher::~UrlFetcher() { + core_->Detach(); +} + +void UrlFetcher::SetRequestContext( + net::URLRequestContextGetter* request_context_getter) { + core_->SetRequestContext(request_context_getter); +} + +void UrlFetcher::SetUploadData(const std::string& upload_content_type, + const std::string& upload_content) { + core_->SetUploadData(upload_content_type, upload_content); +} + +void UrlFetcher::Start(const DoneCallback& done_callback) { + core_->Start(done_callback); +} + +} // namespace remoting diff --git a/remoting/host/url_fetcher.h b/remoting/host/url_fetcher.h new file mode 100644 index 0000000..1b8b193 --- /dev/null +++ b/remoting/host/url_fetcher.h @@ -0,0 +1,63 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_HOST_URL_FETCHER_H_ +#define REMOTING_HOST_URL_FETCHER_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/callback_forward.h" +#include "base/memory/ref_counted.h" + +class GURL; + +namespace net { +class URLRequestContextGetter; +class URLRequestStatus; +} // namespace net + +namespace remoting { + +// UrlFetcher implements HTTP querying functionality that is used in +// remoting code (e.g. in GaiaOAuthClient). It takes care of switching +// threads when neccessary and provides interface that is simpler to +// use than net::UrlRequest. +// +// This code is a simplified version of content::UrlFetcher from +// content/common/net. It implements only features that remoting code +// needs. +class UrlFetcher { + public: + enum Method { + GET, + POST, + }; + + typedef base::Callback<void(const net::URLRequestStatus& status, + int response_code, + const std::string& response)> + DoneCallback; + + UrlFetcher(const GURL& url, Method method); + ~UrlFetcher(); + + void SetRequestContext( + net::URLRequestContextGetter* request_context_getter); + void SetUploadData(const std::string& upload_content_type, + const std::string& upload_content); + void Start(const DoneCallback& done_callback); + + private: + // Ref-counted core of the implementation. + class Core; + + scoped_refptr<Core> core_; + + DISALLOW_COPY_AND_ASSIGN(UrlFetcher); +}; + +} // namespace remoting + +#endif // REMOTING_HOST_URL_FETCHER_H_ diff --git a/remoting/host/url_fetcher_unittest.cc b/remoting/host/url_fetcher_unittest.cc new file mode 100644 index 0000000..614474e --- /dev/null +++ b/remoting/host/url_fetcher_unittest.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/url_fetcher.h" + +#include "base/message_loop.h" +#include "base/threading/thread.h" +#include "net/test/test_server.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_status.h" +#include "remoting/host/url_request_context.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace remoting { + +class UrlFetcherTest : public testing::Test { + public: + UrlFetcherTest() + : test_server_( + net::TestServer::TYPE_HTTPS, + net::TestServer::kLocalhost, + FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))), + io_thread_("TestIOThread"), + file_thread_("TestFileThread") { + } + + protected: + void SetUp() OVERRIDE { + ASSERT_TRUE(io_thread_.StartWithOptions( + base::Thread::Options(MessageLoop::TYPE_IO, 0))); + ASSERT_TRUE(file_thread_.StartWithOptions( + base::Thread::Options(MessageLoop::TYPE_IO, 0))); + context_getter_ = new URLRequestContextGetter(io_thread_.message_loop(), + file_thread_.message_loop()); + ASSERT_TRUE(test_server_.Start()); + } + + protected: + void OnDone(const net::URLRequestStatus& status, + int response_code, + const std::string& response) { + ASSERT_EQ(MessageLoop::current(), &message_loop_); + status_ = status; + response_code_ = response_code; + response_ = response; + message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); + } + + net::TestServer test_server_; + MessageLoopForUI message_loop_; + base::Thread io_thread_; + base::Thread file_thread_; + scoped_refptr<URLRequestContextGetter> context_getter_; + net::URLRequestStatus status_; + std::string response_; + int response_code_; +}; + +TEST_F(UrlFetcherTest, TestGet) { + UrlFetcher fetcher(test_server_.GetURL("default"), UrlFetcher::GET); + fetcher.SetRequestContext(context_getter_); + fetcher.Start(base::Bind(&UrlFetcherTest_TestGet_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ("Default response given for path: /default", response_); + EXPECT_EQ(200, response_code_); +} + +TEST_F(UrlFetcherTest, TestPost) { + const char kTestQueryData[] = "123qwe123qwe"; + UrlFetcher fetcher(test_server_.GetURL("echo"), UrlFetcher::POST); + fetcher.SetRequestContext(context_getter_); + fetcher.SetUploadData("text/html", kTestQueryData); + fetcher.Start(base::Bind(&UrlFetcherTest_TestPost_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ(kTestQueryData, response_); + EXPECT_EQ(200, response_code_); +} + +TEST_F(UrlFetcherTest, TestFailed) { + UrlFetcher fetcher(test_server_.GetURL("auth-basic"), UrlFetcher::GET); + fetcher.SetRequestContext(context_getter_); + fetcher.Start(base::Bind(&UrlFetcherTest_TestFailed_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ(401, response_code_); +} + +} // namespace remoting diff --git a/remoting/host/url_request_context.h b/remoting/host/url_request_context.h index 372d5ee..9461275 100644 --- a/remoting/host/url_request_context.h +++ b/remoting/host/url_request_context.h @@ -60,4 +60,4 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { } // namespace remoting -#endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ +#endif // REMOTING_HOST_URL_REQUEST_CONTEXT_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 9cf4e6a..fb410aa 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -620,11 +620,6 @@ # duplicate string once # http://code.google.com/p/gyp/issues/detail?id=243 is fixed. 'INFOPLIST_PREPROCESSOR_DEFINITIONS': 'HOST_PLUGIN_MIME_TYPE="<(host_plugin_mime_type)" HOST_PLUGIN_NAME="<(host_plugin_name)" HOST_PLUGIN_DESCRIPTION="<(host_plugin_description)"', - - # TODO(thakis): Remove this once remoting no longer depends on - # webkit (through content through urlfetcher), - # http://crbug.com/124041 - 'DEAD_CODE_STRIPPING': 'YES', # -Wl,-dead_strip }, # TODO(mark): Come up with a fancier way to do this. It should # only be necessary to list host_plugin-Info.plist once, not the @@ -832,8 +827,6 @@ 'remoting_protocol', 'differ_block', '../crypto/crypto.gyp:crypto', - # TODO(hclam): Remove this dependency once we don't use URLFetcher. - '../content/content.gyp:content_common', ], 'sources': [ 'host/capturer.h', @@ -922,6 +915,8 @@ 'host/scoped_thread_desktop_win.h', 'host/ui_strings.cc', 'host/ui_strings.h', + 'host/url_fetcher.cc', + 'host/url_fetcher.h', 'host/url_request_context.cc', 'host/url_request_context.h', 'host/usb_keycode_map.h', @@ -1449,6 +1444,7 @@ 'host/capturer_win_unittest.cc', 'host/remote_input_filter_unittest.cc', 'host/test_key_pair.h', + 'host/url_fetcher_unittest.cc', 'jingle_glue/fake_signal_strategy.cc', 'jingle_glue/fake_signal_strategy.h', 'jingle_glue/iq_sender_unittest.cc', |