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

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: fix failing tests/bugs 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..54242d93b704f9300045d11bd6acfa575f8dcc03 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,26 @@ 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),
+ 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 +122,41 @@ 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 is obtained via asynchonous call. Setting |*defer| to true
+ // keeps the throttle alive in the meantime.
+ *defer = true;
+ net::CookieOptions options;
+ options.set_include_httponly();
+ cookie_store->GetCookieListWithOptionsAsync(
+ request_->url(),
+ options,
+ base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ // Can't get any cookies, start android download.
+ StartDownload(DownloadInfo(request_));
+ }
+}
+
+void InterceptDownloadResourceThrottle::CheckCookiePolicy(
+ const net::CookieList& cookie_list) {
+ DownloadInfo info(request_);
+ if (request_->context()->network_delegate()->CanGetCookies(*request_,
+ cookie_list)) {
+ std::string cookie = net::CookieStore::BuildCookieLine(cookie_list);
+ if (!cookie.empty()) {
+ info.cookie = cookie;
+ }
+ }
+ StartDownload(info);
+}
+
+void InterceptDownloadResourceThrottle::StartDownload(
+ const DownloadInfo& info) {
+ DownloadControllerBase::Get()->CreateGETDownload(
+ render_process_id_, render_view_id_, must_download_, info);
controller()->Cancel();
RecordInterceptFailureReasons(NO_FAILURE);
}
« no previous file with comments | « chrome/browser/android/intercept_download_resource_throttle.h ('k') | chrome/browser/download/download_resource_throttle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698