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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_download_service.h

Issue 2351113003: Reading list downloader retries on recoverable error (Closed)
Patch Set: Reviewable Created 4 years, 3 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
OLDNEW
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 "ios/chrome/browser/reading_list/reading_list_model_observer.h" 10 #include "ios/chrome/browser/reading_list/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 13
13 class GURL; 14 class GURL;
14 class PrefService; 15 class PrefService;
15 class ReadingListModel; 16 class ReadingListModel;
16 namespace base { 17 namespace base {
17 class FilePath; 18 class FilePath;
18 } 19 }
19 20
20 namespace dom_distiller { 21 namespace dom_distiller {
21 class DomDistillerService; 22 class DomDistillerService;
22 } 23 }
23 24
24 // Observes the reading list and downloads offline versions of its articles. 25 // Observes the reading list and downloads offline versions of its articles.
25 // Any calls made to DownloadAllEntries/DownloadEntry before the model is 26 // Any calls made to DownloadAllEntries/DownloadEntry before the model is
26 // loaded will be ignored. When the model is loaded, DownloadAllEntries will be 27 // loaded will be ignored. When the model is loaded, DownloadAllEntries will be
27 // called automatically. 28 // called automatically.
28 class ReadingListDownloadService : public KeyedService, 29 class ReadingListDownloadService
29 public ReadingListModelObserver { 30 : public KeyedService,
31 public ReadingListModelObserver,
32 public net::NetworkChangeNotifier::ConnectionTypeObserver {
30 public: 33 public:
31 ReadingListDownloadService( 34 ReadingListDownloadService(
32 ReadingListModel* reading_list_model, 35 ReadingListModel* reading_list_model,
33 dom_distiller::DomDistillerService* distiller_service, 36 dom_distiller::DomDistillerService* distiller_service,
34 PrefService* prefs, 37 PrefService* prefs,
35 base::FilePath chrome_profile_path); 38 base::FilePath chrome_profile_path);
36 ~ReadingListDownloadService() override; 39 ~ReadingListDownloadService() override;
37 40
38 // Initializes the reading list download service. 41 // Initializes the reading list download service.
39 void Initialize(); 42 void Initialize();
40 43
41 // KeyedService implementation. 44 // KeyedService implementation.
42 void Shutdown() override; 45 void Shutdown() override;
43 46
44 // ReadingListModelObserver implementation 47 // ReadingListModelObserver implementation
45 void ReadingListModelLoaded(const ReadingListModel* model) override; 48 void ReadingListModelLoaded(const ReadingListModel* model) override;
46 void ReadingListWillRemoveReadEntry(const ReadingListModel* model, 49 void ReadingListWillRemoveReadEntry(const ReadingListModel* model,
47 size_t index) override; 50 size_t index) override;
48 void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model, 51 void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model,
49 size_t index) override; 52 size_t index) override;
50 void ReadingListWillAddUnreadEntry(const ReadingListModel* model, 53 void ReadingListWillAddUnreadEntry(const ReadingListModel* model,
51 const ReadingListEntry& entry) override; 54 const ReadingListEntry& entry) override;
52 void ReadingListWillAddReadEntry(const ReadingListModel* model, 55 void ReadingListWillAddReadEntry(const ReadingListModel* model,
53 const ReadingListEntry& entry) override; 56 const ReadingListEntry& entry) override;
54 57
55 private: 58 private:
56 // Tries to save offline versions of all entries in the reading list that are 59 // Tries to save offline versions of all entries in the reading list that are
57 // not yet saved. Must only be called after reading list model is loaded. 60 // not yet saved. Must only be called after reading list model is loaded.
58 void DownloadAllEntries(); 61 void DownloadAllEntries();
62 // Schedule a download of an offline version of the reading list entry,
63 // according to the delay of the entry. Must only be called after reading list
64 // model is loaded.
65 void ScheduleDownloadEntry(const ReadingListEntry& entry);
66 // Tries to save an offline version of the reading list entry corresponding to
67 // the |url| if it is not yet saved. Must only be called after reading list
68 // model is loaded.
69 void DownloadEntryFromURL(const GURL& url);
59 // Tries to save an offline version of the reading list entry if it is not yet 70 // Tries to save an offline version of the reading list entry if it is not yet
60 // saved. Must only be called after reading list model is loaded. 71 // saved. Must only be called after reading list model is loaded.
61 void DownloadEntry(const ReadingListEntry& entry); 72 void DownloadEntry(const ReadingListEntry& entry);
62 // Removes the offline version of the reading list entry if it exists. Must 73 // Removes the offline version of the reading list entry if it exists. Must
63 // only be called after reading list model is loaded. 74 // only be called after reading list model is loaded.
64 void RemoveDownloadedEntry(const ReadingListEntry& entry); 75 void RemoveDownloadedEntry(const ReadingListEntry& entry);
65 // Callback for entry download. 76 // Callback for entry download.
66 void OnDownloadEnd(const GURL& url, 77 void OnDownloadEnd(const GURL& url,
67 URLDownloader::SuccessState success, 78 URLDownloader::SuccessState success,
68 const GURL& distilled_url, 79 const GURL& distilled_url,
69 const std::string& title); 80 const std::string& title);
70 81
71 // Callback for entry deletion. 82 // Callback for entry deletion.
72 void OnDeleteEnd(const GURL& url, bool success); 83 void OnDeleteEnd(const GURL& url, bool success);
73 84
85 // net::NetworkChangeNotifier::ConnectionTypeObserver:
86 void OnConnectionTypeChanged(
87 net::NetworkChangeNotifier::ConnectionType type) override;
88
74 ReadingListModel* reading_list_model_; 89 ReadingListModel* reading_list_model_;
75 std::unique_ptr<URLDownloader> url_downloader_; 90 std::unique_ptr<URLDownloader> url_downloader_;
91 std::vector<GURL> url_to_download_cellular_;
92 std::vector<GURL> url_to_download_wifi_;
93 bool had_connection_;
76 94
77 DISALLOW_COPY_AND_ASSIGN(ReadingListDownloadService); 95 DISALLOW_COPY_AND_ASSIGN(ReadingListDownloadService);
78 }; 96 };
79 97
80 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_ 98 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_DOWNLOAD_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698