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

Side by Side Diff: chrome/browser/download/download_throttling_resource_handler.h

Issue 7660007: Factor out dependncy on download throttling from core download code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "chrome/browser/download/download_request_limiter.h" 11 #include "chrome/browser/download/download_request_limiter.h"
12 #include "content/browser/renderer_host/resource_handler.h" 12 #include "content/browser/renderer_host/resource_handler.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 14
15 class DownloadResourceHandler; 15 class DownloadResourceHandler;
16 class ResourceDispatcherHost; 16 class ResourceDispatcherHost;
17 17
18 namespace net { 18 namespace net {
19 class URLRequest; 19 class URLRequest;
20 } // namespace net 20 } // namespace net
21 21
22 // DownloadThrottlingResourceHandler is used to determine if a download should 22 // DownloadThrottlingResourceHandler is used to determine if a download should
23 // be allowed. When a DownloadThrottlingResourceHandler is created it pauses the 23 // be allowed. When a DownloadThrottlingResourceHandler is created it pauses the
24 // download and asks the DownloadRequestLimiter if the download should be 24 // download and asks the DownloadRequestLimiter if the download should be
25 // allowed. The DownloadRequestLimiter notifies us asynchronously as to whether 25 // allowed. The DownloadRequestLimiter notifies us asynchronously as to whether
26 // the download is allowed or not. If the download is allowed the request is 26 // the download is allowed or not. If the download is allowed the request is
27 // resumed, a DownloadResourceHandler is created and all EventHandler methods 27 // resumed, all EventHandler methods are delegated to it to the original
28 // are delegated to it. If the download is not allowed the request is canceled. 28 // handler. If the download is not allowed the request is canceled.
29 29
30 class DownloadThrottlingResourceHandler 30 class DownloadThrottlingResourceHandler
31 : public ResourceHandler, 31 : public ResourceHandler,
32 public DownloadRequestLimiter::Callback { 32 public DownloadRequestLimiter::Callback {
33 public: 33 public:
34 DownloadThrottlingResourceHandler(ResourceDispatcherHost* host, 34 DownloadThrottlingResourceHandler(ResourceHandler* next_handler,
35 ResourceDispatcherHost* host,
36 DownloadRequestLimiter* limiter,
35 net::URLRequest* request, 37 net::URLRequest* request,
36 const GURL& url, 38 const GURL& url,
37 int render_process_host_id, 39 int render_process_host_id,
38 int render_view_id, 40 int render_view_id,
39 int request_id, 41 int request_id,
40 bool in_complete); 42 bool in_complete);
41 43
42 // ResourceHanlder implementation: 44 // ResourceHanlder implementation:
43 virtual bool OnUploadProgress(int request_id, 45 virtual bool OnUploadProgress(int request_id,
44 uint64 position, 46 uint64 position,
(...skipping 19 matching lines...) Expand all
64 66
65 void CopyTmpBufferToDownloadHandler(); 67 void CopyTmpBufferToDownloadHandler();
66 68
67 ResourceDispatcherHost* host_; 69 ResourceDispatcherHost* host_;
68 net::URLRequest* request_; 70 net::URLRequest* request_;
69 GURL url_; 71 GURL url_;
70 int render_process_host_id_; 72 int render_process_host_id_;
71 int render_view_id_; 73 int render_view_id_;
72 int request_id_; 74 int request_id_;
73 75
74 // Handles the actual download. This is only created if the download is 76 // The original handler.
75 // allowed to continue. 77 scoped_refptr<ResourceHandler> next_handler_;
76 scoped_refptr<DownloadResourceHandler> download_handler_; 78
79 // Set to true when we know that the request is allowed to start.
80 bool request_allowed_;
77 81
78 // Response supplied to OnResponseStarted. Only non-null if OnResponseStarted 82 // Response supplied to OnResponseStarted. Only non-null if OnResponseStarted
79 // is invoked. 83 // is invoked.
80 scoped_refptr<ResourceResponse> response_; 84 scoped_refptr<ResourceResponse> response_;
81 85
82 // If we're created by way of BufferedEventHandler we'll get one request for 86 // If we're created by way of BufferedEventHandler we'll get one request for
83 // a buffer. This is that buffer. 87 // a buffer. This is that buffer.
84 scoped_refptr<net::IOBuffer> tmp_buffer_; 88 scoped_refptr<net::IOBuffer> tmp_buffer_;
85 int tmp_buffer_length_; 89 int tmp_buffer_length_;
86 90
87 // If true the next call to OnReadCompleted is ignored. This is used if we're 91 // If true the next call to OnReadCompleted is ignored. This is used if we're
88 // paused during a call to OnReadCompleted. Pausing during OnReadCompleted 92 // paused during a call to OnReadCompleted. Pausing during OnReadCompleted
89 // results in two calls to OnReadCompleted for the same data. This make sure 93 // results in two calls to OnReadCompleted for the same data. This make sure
90 // we ignore one of them. 94 // we ignore one of them.
91 bool ignore_on_read_complete_; 95 bool ignore_on_read_complete_;
92 96
93 // Have we received OnRequestClosed()? If so, we shouldn't act on 97 // Have we received OnRequestClosed()? If so, we shouldn't act on
94 // CancelDownload()/ContinueDownload(). 98 // CancelDownload()/ContinueDownload().
95 bool request_closed_; 99 bool request_closed_;
96 100
97 DISALLOW_COPY_AND_ASSIGN(DownloadThrottlingResourceHandler); 101 DISALLOW_COPY_AND_ASSIGN(DownloadThrottlingResourceHandler);
98 }; 102 };
99 103
100 #endif // CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_ 104 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_THROTTLING_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698