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

Unified Diff: chrome/browser/android/intercept_download_resource_throttle.cc

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/intercept_download_resource_throttle.cc
diff --git a/chrome/browser/android/intercept_download_resource_throttle.cc b/chrome/browser/android/intercept_download_resource_throttle.cc
index 30fd0a118f346f7833ec01595fd639fb5622d601..5383f5f2e1cbfaa250e3a5b9793379429aadc93b 100644
--- a/chrome/browser/android/intercept_download_resource_throttle.cc
+++ b/chrome/browser/android/intercept_download_resource_throttle.cc
@@ -8,11 +8,14 @@
#include "base/metrics/histogram_macros.h"
#include "chrome/browser/android/chrome_feature_list.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
-#include "content/public/browser/android/download_controller_android.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_controller.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
+
+using content::BrowserThread;
namespace {
@@ -52,27 +55,27 @@ InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
net::URLRequest* request,
int render_process_id,
int render_view_id,
- int request_id,
bool must_download)
: request_(request),
render_process_id_(render_process_id),
render_view_id_(render_view_id),
- request_id_(request_id),
- must_download_(must_download) {
+ must_download_(must_download),
+ cookie_completed_(false),
+ weak_factory_(this) {
}
InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
}
void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
- ProcessDownloadRequest();
+ ProcessDownloadRequest(defer);
}
const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
return "InterceptDownloadResourceThrottle";
}
-void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
+void InterceptDownloadResourceThrottle::ProcessDownloadRequest(bool* defer) {
if (!IsDownloadInterceptionEnabled())
return;
@@ -120,8 +123,53 @@ void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
return;
}
- content::DownloadControllerAndroid::Get()->CreateGETDownload(
- render_process_id_, render_view_id_, request_id_, must_download_);
+ net::CookieStore* cookie_store = request_->context()->cookie_store();
+ if (cookie_store && !cookie_completed_) {
+ // Deferring here causes this function to be called again after we Resume().
+ *defer = true;
+ net::CookieOptions options;
+ options.set_include_httponly();
+ cookie_store->GetCookieListWithOptionsAsync(
+ request_->url(),
+ options,
+ base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ DownloadInfo info(request_);
+ if (!cookie_.empty()) {
+ info.cookie = cookie_;
+ }
+ StartDownload(info);
+ }
+}
+
+void InterceptDownloadResourceThrottle::CheckCookiePolicy(
+ const net::CookieList& cookie_list) {
+ if (request_->context()->network_delegate()->CanGetCookies(*request_,
+ cookie_list)) {
+ cookie_ = net::CookieStore::BuildCookieLine(cookie_list);
+ }
+ cookie_completed_ = true;
+
+ // Makes sure the request gets resumed after it is marked as deferred by
+ // the caller.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InterceptDownloadResourceThrottle::ResumeDeferredRequest,
+ weak_factory_.GetWeakPtr()));
+}
+
+void InterceptDownloadResourceThrottle::ResumeDeferredRequest() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ // Cookie is ready now. Calling |Resume()| causes |ProcesDownloadRequest()|
+ // to be invoked again.
+ controller()->Resume();
+}
+
+void InterceptDownloadResourceThrottle::StartDownload(
+ const DownloadInfo& info) {
+ DownloadControllerBase::Get()->CreateGETDownload(
+ render_process_id_, render_view_id_, must_download_, info);
controller()->Cancel();
RecordInterceptFailureReasons(NO_FAILURE);
}

Powered by Google App Engine
This is Rietveld 408576698