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

Side by Side Diff: chrome/browser/download/download_resource_throttle.cc

Issue 1229933010: move file access permission logic to DownloadResourceThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/download_resource_throttle.h" 5 #include "chrome/browser/download/download_resource_throttle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/download/download_stats.h" 8 #include "chrome/browser/download/download_stats.h"
9 #include "content/public/browser/resource_controller.h" 9 #include "content/public/browser/resource_controller.h"
10 10
11 #if defined(OS_ANDROID)
12 #include "content/public/browser/android/download_controller_android.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_view_host.h"
15
16 using content::BrowserThread;
17 using content::DownloadControllerAndroid;
18
19 namespace {
20
21 void OnAcquireFileAccessPermissionDone(
22 const DownloadControllerAndroid::AcquireFileAccessPermissionCallback& cb,
23 bool granted) {
24 DCHECK_CURRENTLY_ON(BrowserThread::UI);
25 BrowserThread::PostTask(
26 BrowserThread::IO, FROM_HERE, base::Bind(cb, granted));
27 }
28
29 void AcquireFileAccessPermission(
30 int render_process_id,
31 int render_view_id,
32 const DownloadControllerAndroid::AcquireFileAccessPermissionCallback& cb) {
33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
34 content::DownloadControllerAndroid::Get()->AcquireFileAccessPermission(
35 render_process_id, render_view_id,
36 base::Bind(&OnAcquireFileAccessPermissionDone, cb));
37 }
38
39 } // namespace
40 #endif
41
11 DownloadResourceThrottle::DownloadResourceThrottle( 42 DownloadResourceThrottle::DownloadResourceThrottle(
12 DownloadRequestLimiter* limiter, 43 scoped_refptr<DownloadRequestLimiter> limiter,
13 int render_process_id, 44 int render_process_id,
14 int render_view_id, 45 int render_view_id,
15 const GURL& url, 46 const GURL& url,
16 const std::string& request_method) 47 const std::string& request_method)
17 : querying_limiter_(true), 48 : querying_limiter_(true),
18 request_allowed_(false), 49 request_allowed_(false),
19 request_deferred_(false) { 50 request_deferred_(false) {
20 limiter->CanDownloadOnIOThread( 51 #if defined(OS_ANDROID)
21 render_process_id, 52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
22 render_view_id, 53 BrowserThread::PostTask(
23 url, 54 BrowserThread::UI, FROM_HERE,base::Bind(
24 request_method, 55 &AcquireFileAccessPermission, render_process_id, render_view_id,
25 base::Bind(&DownloadResourceThrottle::ContinueDownload, 56 base::Bind(
26 AsWeakPtr())); 57 &DownloadResourceThrottle::FileAccessPermissionGranted,
58 AsWeakPtr(), limiter, render_process_id, render_view_id,
59 url, request_method)));
asanka 2015/07/13 19:13:42 Let's try to reduce thread hopping. Currently we
qinmin 2015/07/14 00:30:57 Done.
60 #else
61 FileAccessPermissionGranted(
62 limiter, render_process_id, render_view_id, url, request_method, true);
63 #endif
27 } 64 }
28 65
29 DownloadResourceThrottle::~DownloadResourceThrottle() { 66 DownloadResourceThrottle::~DownloadResourceThrottle() {
30 } 67 }
31 68
32 void DownloadResourceThrottle::WillStartRequest(bool* defer) { 69 void DownloadResourceThrottle::WillStartRequest(bool* defer) {
33 WillDownload(defer); 70 WillDownload(defer);
34 } 71 }
35 72
36 void DownloadResourceThrottle::WillRedirectRequest( 73 void DownloadResourceThrottle::WillRedirectRequest(
37 const net::RedirectInfo& redirect_info, 74 const net::RedirectInfo& redirect_info,
38 bool* defer) { 75 bool* defer) {
39 WillDownload(defer); 76 WillDownload(defer);
40 } 77 }
41 78
42 void DownloadResourceThrottle::WillProcessResponse(bool* defer) { 79 void DownloadResourceThrottle::WillProcessResponse(bool* defer) {
43 WillDownload(defer); 80 WillDownload(defer);
44 } 81 }
45 82
46 const char* DownloadResourceThrottle::GetNameForLogging() const { 83 const char* DownloadResourceThrottle::GetNameForLogging() const {
47 return "DownloadResourceThrottle"; 84 return "DownloadResourceThrottle";
48 } 85 }
49 86
87 void DownloadResourceThrottle::FileAccessPermissionGranted(
88 scoped_refptr<DownloadRequestLimiter> limiter,
89 int render_process_id,
90 int render_view_id,
91 const GURL& url,
92 const std::string& request_method,
93 bool granted) {
94 if (granted) {
95 limiter->CanDownloadOnIOThread(
96 render_process_id,
97 render_view_id,
98 url,
99 request_method,
100 base::Bind(&DownloadResourceThrottle::ContinueDownload,
101 AsWeakPtr()));
102 } else {
103 controller()->Cancel();
104 }
105 }
106
50 void DownloadResourceThrottle::WillDownload(bool* defer) { 107 void DownloadResourceThrottle::WillDownload(bool* defer) {
51 DCHECK(!request_deferred_); 108 DCHECK(!request_deferred_);
52 109
53 // Defer the download until we have the DownloadRequestLimiter result. 110 // Defer the download until we have the DownloadRequestLimiter result.
54 if (querying_limiter_) { 111 if (querying_limiter_) {
55 request_deferred_ = true; 112 request_deferred_ = true;
56 *defer = true; 113 *defer = true;
57 return; 114 return;
58 } 115 }
59 116
(...skipping 15 matching lines...) Expand all
75 132
76 if (request_deferred_) { 133 if (request_deferred_) {
77 request_deferred_ = false; 134 request_deferred_ = false;
78 if (allow) { 135 if (allow) {
79 controller()->Resume(); 136 controller()->Resume();
80 } else { 137 } else {
81 controller()->Cancel(); 138 controller()->Cancel();
82 } 139 }
83 } 140 }
84 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698