| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/task/cancelable_task_tracker.h" | 11 #include "base/task/cancelable_task_tracker.h" |
| 12 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" | 12 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 13 | 13 |
| 14 class PrefService; | 14 class PrefService; |
| 15 class GURL; | 15 class GURL; |
| 16 namespace base { | 16 namespace base { |
| 17 class FilePath; | 17 class FilePath; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace dom_distiller { | 20 namespace dom_distiller { |
| 21 class DomDistillerService; | 21 class DomDistillerService; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace reading_list { |
| 25 class ReadingListDistillerPageFactory; |
| 26 } |
| 27 |
| 24 // This class downloads and deletes offline versions of URLs using DOM distiller | 28 // This class downloads and deletes offline versions of URLs using DOM distiller |
| 25 // to fetch the page and simplify it. Only one item is downloaded or deleted at | 29 // to fetch the page and simplify it. Only one item is downloaded or deleted at |
| 26 // a time using a queue of tasks that are handled sequentially. Items (page + | 30 // a time using a queue of tasks that are handled sequentially. Items (page + |
| 27 // images) are saved to individual folders within an offline folder, using md5 | 31 // images) are saved to individual folders within an offline folder, using md5 |
| 28 // hashing to create unique file names. When a deletion is requested, all | 32 // hashing to create unique file names. When a deletion is requested, all |
| 29 // previous downloads for that URL are cancelled as they would be deleted. | 33 // previous downloads for that URL are cancelled as they would be deleted. |
| 30 class URLDownloader { | 34 class URLDownloader { |
| 31 friend class MockURLDownloader; | 35 friend class MockURLDownloader; |
| 32 | 36 |
| 33 public: | 37 public: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 51 // failure. | 55 // failure. |
| 52 using DownloadCompletion = base::Callback<void(const GURL&, | 56 using DownloadCompletion = base::Callback<void(const GURL&, |
| 53 SuccessState, | 57 SuccessState, |
| 54 const base::FilePath&, | 58 const base::FilePath&, |
| 55 const std::string&)>; | 59 const std::string&)>; |
| 56 | 60 |
| 57 // Create a URL downloader with completion callbacks for downloads and | 61 // Create a URL downloader with completion callbacks for downloads and |
| 58 // deletions. The completion callbacks will be called with the original url | 62 // deletions. The completion callbacks will be called with the original url |
| 59 // and a boolean indicating success. For downloads, if distillation was | 63 // and a boolean indicating success. For downloads, if distillation was |
| 60 // successful, it will also include the distilled url and extracted title. | 64 // successful, it will also include the distilled url and extracted title. |
| 61 URLDownloader(dom_distiller::DomDistillerService* distiller_service, | 65 URLDownloader( |
| 62 PrefService* prefs, | 66 dom_distiller::DomDistillerService* distiller_service, |
| 63 base::FilePath chrome_profile_path, | 67 reading_list::ReadingListDistillerPageFactory* distiller_page_factory, |
| 64 const DownloadCompletion& download_completion, | 68 PrefService* prefs, |
| 65 const SuccessCompletion& delete_completion); | 69 base::FilePath chrome_profile_path, |
| 70 const DownloadCompletion& download_completion, |
| 71 const SuccessCompletion& delete_completion); |
| 66 virtual ~URLDownloader(); | 72 virtual ~URLDownloader(); |
| 67 | 73 |
| 68 // Asynchronously download an offline version of the URL. | 74 // Asynchronously download an offline version of the URL. |
| 69 void DownloadOfflineURL(const GURL& url); | 75 void DownloadOfflineURL(const GURL& url); |
| 70 | 76 |
| 71 // Cancels the download job an offline version of the URL. | 77 // Cancels the download job an offline version of the URL. |
| 72 void CancelDownloadOfflineURL(const GURL& url); | 78 void CancelDownloadOfflineURL(const GURL& url); |
| 73 | 79 |
| 74 // Asynchronously remove the offline version of the URL if it exists. | 80 // Asynchronously remove the offline version of the URL if it exists. |
| 75 void RemoveOfflineURL(const GURL& url); | 81 void RemoveOfflineURL(const GURL& url); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const std::string& html); | 125 const std::string& html); |
| 120 // Callback for distillation completion. | 126 // Callback for distillation completion. |
| 121 void DistillerCallback( | 127 void DistillerCallback( |
| 122 const GURL& pageURL, | 128 const GURL& pageURL, |
| 123 const std::string& html, | 129 const std::string& html, |
| 124 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>& | 130 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>& |
| 125 images, | 131 images, |
| 126 const std::string& title); | 132 const std::string& title); |
| 127 | 133 |
| 128 dom_distiller::DomDistillerService* distiller_service_; | 134 dom_distiller::DomDistillerService* distiller_service_; |
| 135 reading_list::ReadingListDistillerPageFactory* distiller_page_factory_; |
| 129 PrefService* pref_service_; | 136 PrefService* pref_service_; |
| 130 const DownloadCompletion download_completion_; | 137 const DownloadCompletion download_completion_; |
| 131 const SuccessCompletion delete_completion_; | 138 const SuccessCompletion delete_completion_; |
| 132 std::deque<Task> tasks_; | 139 std::deque<Task> tasks_; |
| 133 bool working_; | 140 bool working_; |
| 134 base::FilePath base_directory_; | 141 base::FilePath base_directory_; |
| 135 std::unique_ptr<dom_distiller::DistillerViewerInterface> distiller_; | 142 std::unique_ptr<dom_distiller::DistillerViewerInterface> distiller_; |
| 136 base::CancelableTaskTracker task_tracker_; | 143 base::CancelableTaskTracker task_tracker_; |
| 137 | 144 |
| 138 DISALLOW_COPY_AND_ASSIGN(URLDownloader); | 145 DISALLOW_COPY_AND_ASSIGN(URLDownloader); |
| 139 }; | 146 }; |
| 140 | 147 |
| 141 #endif // IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ | 148 #endif // IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ |
| OLD | NEW |