| 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_COMPLETION_BLOCKER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "content/public/browser/download_item.h" | 9 #include "content/public/browser/download_item.h" |
| 10 | 10 |
| 11 // A subsystem may use a DownloadCompletionBlocker in conjunction with | 11 // A subsystem may use a DownloadCompletionBlocker in conjunction with |
| 12 // DownloadManagerDelegate::ShouldCompleteDownload() in order to block the | 12 // DownloadManagerDelegate::ShouldCompleteDownload() in order to block the |
| 13 // completion of a DownloadItem. CompleteDownload() will run the most recent | 13 // completion of a DownloadItem. CompleteDownload() will run the most recent |
| 14 // callback set. | 14 // callback set. |
| 15 class DownloadCompletionBlocker : public content::DownloadItem::ExternalData { | 15 class DownloadCompletionBlocker : public base::SupportsUserData::Data { |
| 16 public: | 16 public: |
| 17 DownloadCompletionBlocker(); | 17 DownloadCompletionBlocker(); |
| 18 virtual ~DownloadCompletionBlocker(); | 18 virtual ~DownloadCompletionBlocker(); |
| 19 | 19 |
| 20 bool is_complete() const { return is_complete_; } | 20 bool is_complete() const { return is_complete_; } |
| 21 | 21 |
| 22 void set_callback(const base::Closure& callback) { | 22 void set_callback(const base::Closure& callback) { |
| 23 if (!is_complete()) | 23 if (!is_complete()) |
| 24 callback_ = callback; | 24 callback_ = callback; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Mark this download item as complete with respect to this blocker. (Other | 27 // Mark this download item as complete with respect to this blocker. (Other |
| 28 // blockers may continue to block the item.) Run |callback_|. This method may | 28 // blockers may continue to block the item.) Run |callback_|. This method may |
| 29 // only be called once, so |callback_| will only be called once. Subclasses | 29 // only be called once, so |callback_| will only be called once. Subclasses |
| 30 // must call the base implementation if they override this method. | 30 // must call the base implementation if they override this method. |
| 31 virtual void CompleteDownload(); | 31 virtual void CompleteDownload(); |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 bool is_complete_; | 34 bool is_complete_; |
| 35 base::Closure callback_; | 35 base::Closure callback_; |
| 36 | 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(DownloadCompletionBlocker); | 37 DISALLOW_COPY_AND_ASSIGN(DownloadCompletionBlocker); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_ | 40 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_COMPLETION_BLOCKER_H_ |
| OLD | NEW |