| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Number of "ALLOWED" downloads. | 96 // Number of "ALLOWED" downloads. |
| 97 void increment_download_count() { | 97 void increment_download_count() { |
| 98 download_count_++; | 98 download_count_++; |
| 99 } | 99 } |
| 100 size_t download_count() const { | 100 size_t download_count() const { |
| 101 return download_count_; | 101 return download_count_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // content::WebContentsObserver overrides. | 104 // content::WebContentsObserver overrides. |
| 105 virtual void AboutToNavigateRenderView( | 105 virtual void AboutToNavigateRenderView( |
| 106 content::RenderViewHost* render_view_host) OVERRIDE; | 106 content::RenderViewHost* render_view_host) override; |
| 107 // Invoked when a user gesture occurs (mouse click, enter or space). This | 107 // Invoked when a user gesture occurs (mouse click, enter or space). This |
| 108 // may result in invoking Remove on DownloadRequestLimiter. | 108 // may result in invoking Remove on DownloadRequestLimiter. |
| 109 virtual void DidGetUserGesture() OVERRIDE; | 109 virtual void DidGetUserGesture() override; |
| 110 virtual void WebContentsDestroyed() OVERRIDE; | 110 virtual void WebContentsDestroyed() override; |
| 111 | 111 |
| 112 // Asks the user if they really want to allow the download. | 112 // Asks the user if they really want to allow the download. |
| 113 // See description above CanDownloadOnIOThread for details on lifetime of | 113 // See description above CanDownloadOnIOThread for details on lifetime of |
| 114 // callback. | 114 // callback. |
| 115 void PromptUserForDownload( | 115 void PromptUserForDownload( |
| 116 const DownloadRequestLimiter::Callback& callback); | 116 const DownloadRequestLimiter::Callback& callback); |
| 117 | 117 |
| 118 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and | 118 // Invoked from DownloadRequestDialogDelegate. Notifies the delegates and |
| 119 // changes the status appropriately. Virtual for testing. | 119 // changes the status appropriately. Virtual for testing. |
| 120 virtual void Cancel(); | 120 virtual void Cancel(); |
| 121 virtual void CancelOnce(); | 121 virtual void CancelOnce(); |
| 122 virtual void Accept(); | 122 virtual void Accept(); |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 // Used for testing. | 125 // Used for testing. |
| 126 TabDownloadState(); | 126 TabDownloadState(); |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 // Are we showing a prompt to the user? Determined by whether | 129 // Are we showing a prompt to the user? Determined by whether |
| 130 // we have an outstanding weak pointer--weak pointers are only | 130 // we have an outstanding weak pointer--weak pointers are only |
| 131 // given to the info bar delegate or permission bubble request. | 131 // given to the info bar delegate or permission bubble request. |
| 132 bool is_showing_prompt() const; | 132 bool is_showing_prompt() const; |
| 133 | 133 |
| 134 // content::NotificationObserver method. | 134 // content::NotificationObserver method. |
| 135 virtual void Observe(int type, | 135 virtual void Observe(int type, |
| 136 const content::NotificationSource& source, | 136 const content::NotificationSource& source, |
| 137 const content::NotificationDetails& details) OVERRIDE; | 137 const content::NotificationDetails& details) override; |
| 138 | 138 |
| 139 // Remember to either block or allow automatic downloads from this origin. | 139 // Remember to either block or allow automatic downloads from this origin. |
| 140 void SetContentSetting(ContentSetting setting); | 140 void SetContentSetting(ContentSetting setting); |
| 141 | 141 |
| 142 // Notifies the callbacks as to whether the download is allowed or not. | 142 // Notifies the callbacks as to whether the download is allowed or not. |
| 143 // Updates status_ appropriately. | 143 // Updates status_ appropriately. |
| 144 void NotifyCallbacks(bool allow); | 144 void NotifyCallbacks(bool allow); |
| 145 | 145 |
| 146 content::WebContents* web_contents_; | 146 content::WebContents* web_contents_; |
| 147 | 147 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 StateMap state_map_; | 250 StateMap state_map_; |
| 251 | 251 |
| 252 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously | 252 // Weak ptr factory used when |CanDownload| asks the delegate asynchronously |
| 253 // about the download. | 253 // about the download. |
| 254 base::WeakPtrFactory<DownloadRequestLimiter> factory_; | 254 base::WeakPtrFactory<DownloadRequestLimiter> factory_; |
| 255 | 255 |
| 256 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); | 256 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiter); |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ | 259 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_LIMITER_H_ |
| OLD | NEW |