| 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_READING_LIST_DOWNLOAD_SERVICE_H_ | 5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ |
| 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ | 6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "components/keyed_service/core/keyed_service.h" | 9 #include "components/keyed_service/core/keyed_service.h" |
| 10 #include "components/reading_list/ios/reading_list_model_observer.h" | 10 #include "components/reading_list/ios/reading_list_model_observer.h" |
| 11 #include "ios/chrome/browser/reading_list/url_downloader.h" | 11 #include "ios/chrome/browser/reading_list/url_downloader.h" |
| 12 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 class PrefService; | 15 class PrefService; |
| 16 class ReadingListModel; | 16 class ReadingListModel; |
| 17 namespace base { | 17 namespace base { |
| 18 class FilePath; | 18 class FilePath; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace dom_distiller { | 21 namespace dom_distiller { |
| 22 class DomDistillerService; | 22 class DomDistillerService; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace reading_list { | 25 namespace reading_list { |
| 26 class ReadingListDistillerPageFactory; | 26 class ReadingListDistillerPageFactory; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Observes the reading list and downloads offline versions of its articles. | 29 // Observes the reading list and downloads offline versions of its articles. |
| 30 // Any calls made to DownloadAllEntries/DownloadEntry before the model is | 30 // Any calls made to DownloadEntry before the model is loaded will be ignored. |
| 31 // loaded will be ignored. When the model is loaded, DownloadAllEntries will be | 31 // When the model is loaded, offline directory is automatically synced with the |
| 32 // called automatically. | 32 // entries in the model. |
| 33 class ReadingListDownloadService | 33 class ReadingListDownloadService |
| 34 : public KeyedService, | 34 : public KeyedService, |
| 35 public ReadingListModelObserver, | 35 public ReadingListModelObserver, |
| 36 public net::NetworkChangeNotifier::ConnectionTypeObserver { | 36 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 37 public: | 37 public: |
| 38 ReadingListDownloadService( | 38 ReadingListDownloadService( |
| 39 ReadingListModel* reading_list_model, | 39 ReadingListModel* reading_list_model, |
| 40 dom_distiller::DomDistillerService* distiller_service, | 40 dom_distiller::DomDistillerService* distiller_service, |
| 41 PrefService* prefs, | 41 PrefService* prefs, |
| 42 base::FilePath chrome_profile_path, | 42 base::FilePath chrome_profile_path, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 57 void ReadingListModelLoaded(const ReadingListModel* model) override; | 57 void ReadingListModelLoaded(const ReadingListModel* model) override; |
| 58 void ReadingListWillRemoveEntry(const ReadingListModel* model, | 58 void ReadingListWillRemoveEntry(const ReadingListModel* model, |
| 59 const GURL& url) override; | 59 const GURL& url) override; |
| 60 void ReadingListDidAddEntry(const ReadingListModel* model, | 60 void ReadingListDidAddEntry(const ReadingListModel* model, |
| 61 const GURL& url, | 61 const GURL& url, |
| 62 reading_list::EntrySource entry_source) override; | 62 reading_list::EntrySource entry_source) override; |
| 63 void ReadingListDidMoveEntry(const ReadingListModel* model, | 63 void ReadingListDidMoveEntry(const ReadingListModel* model, |
| 64 const GURL& url) override; | 64 const GURL& url) override; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 // Tries to save offline versions of all entries in the reading list that are | 67 // Checks the model and determines which entries are processed and which |
| 68 // not yet saved. Must only be called after reading list model is loaded. | 68 // entries need to be processed. |
| 69 void DownloadAllEntries(); | 69 // Initiates a cleanup of |OfflineRoot()| directory removing sub_directories |
| 70 // Processes a new entry and schedule a download if needed. | 70 // not corresponding to a processed ReadingListEntry. |
| 71 // Schedules unprocessed entries for distillation. |
| 72 void SyncWithModel(); |
| 73 // Scans |OfflineRoot()| directory and deletes all subdirectories not listed |
| 74 // in |directories_to_keep|. |
| 75 // Must be called on File thread. |
| 76 void CleanUpFiles(const std::set<std::string>& directories_to_keep); |
| 77 // Schedules all entries in |unprocessed_entries| for distillation. |
| 78 void DownloadUnprocessedEntries(const std::set<GURL>& unprocessed_entries); |
| 79 // Processes a new entry and schedules a download if needed. |
| 71 void ProcessNewEntry(const GURL& url); | 80 void ProcessNewEntry(const GURL& url); |
| 72 // Schedule a download of an offline version of the reading list entry, | 81 // Schedules a download of an offline version of the reading list entry, |
| 73 // according to the delay of the entry. Must only be called after reading list | 82 // according to the delay of the entry. Must only be called after reading list |
| 74 // model is loaded. | 83 // model is loaded. |
| 75 void ScheduleDownloadEntry(const GURL& url); | 84 void ScheduleDownloadEntry(const GURL& url); |
| 76 // Tries to save an offline version of the reading list entry if it is not yet | 85 // Tries to save an offline version of the reading list entry if it is not yet |
| 77 // saved. Must only be called after reading list model is loaded. | 86 // saved. Must only be called after reading list model is loaded. |
| 78 void DownloadEntry(const GURL& url); | 87 void DownloadEntry(const GURL& url); |
| 79 // Removes the offline version of the reading list entry if it exists. Must | 88 // Removes the offline version of the reading list entry if it exists. Must |
| 80 // only be called after reading list model is loaded. | 89 // only be called after reading list model is loaded. |
| 81 void RemoveDownloadedEntry(const GURL& url); | 90 void RemoveDownloadedEntry(const GURL& url); |
| 82 // Callback for entry download. | 91 // Callback for entry download. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 bool had_connection_; | 110 bool had_connection_; |
| 102 std::unique_ptr<reading_list::ReadingListDistillerPageFactory> | 111 std::unique_ptr<reading_list::ReadingListDistillerPageFactory> |
| 103 distiller_page_factory_; | 112 distiller_page_factory_; |
| 104 | 113 |
| 105 base::WeakPtrFactory<ReadingListDownloadService> weak_ptr_factory_; | 114 base::WeakPtrFactory<ReadingListDownloadService> weak_ptr_factory_; |
| 106 | 115 |
| 107 DISALLOW_COPY_AND_ASSIGN(ReadingListDownloadService); | 116 DISALLOW_COPY_AND_ASSIGN(ReadingListDownloadService); |
| 108 }; | 117 }; |
| 109 | 118 |
| 110 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ | 119 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ |
| OLD | NEW |