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

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

Issue 2506993002: Create offline_url_utils (Closed)
Patch Set: feedback Created 4 years, 1 month 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_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 // This string contains the directory name in which offline pages are saved.
25 // The directory is located in the profile directory.
26 extern const char kReadingListOfflineDirectory[];
27
28 // This class downloads and deletes offline versions of URLs using DOM distiller 24 // This class downloads and deletes offline versions of URLs using DOM distiller
29 // to fetch the page and simplify it. Only one item is downloaded or deleted at 25 // to fetch the page and simplify it. Only one item is downloaded or deleted at
30 // a time using a queue of tasks that are handled sequentially. Items (page + 26 // a time using a queue of tasks that are handled sequentially. Items (page +
31 // images) are saved to individual folders within an offline folder, using md5 27 // images) are saved to individual folders within an offline folder, using md5
32 // hashing to create unique file names. When a deletion is requested, all 28 // hashing to create unique file names. When a deletion is requested, all
33 // previous downloads for that URL are cancelled as they would be deleted. 29 // previous downloads for that URL are cancelled as they would be deleted.
34 class URLDownloader { 30 class URLDownloader {
35 friend class MockURLDownloader; 31 friend class MockURLDownloader;
36 32
37 public: 33 public:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Handles the next task in the queue, if no task is currently being handled. 80 // Handles the next task in the queue, if no task is currently being handled.
85 void HandleNextTask(); 81 void HandleNextTask();
86 // Callback for completed (or failed) download, handles calling 82 // Callback for completed (or failed) download, handles calling
87 // downloadCompletion and starting the next task. 83 // downloadCompletion and starting the next task.
88 void DownloadCompletionHandler(const GURL& url, 84 void DownloadCompletionHandler(const GURL& url,
89 const std::string& title, 85 const std::string& title,
90 SuccessState success); 86 SuccessState success);
91 // Callback for completed (or failed) deletion, handles calling 87 // Callback for completed (or failed) deletion, handles calling
92 // deleteCompletion and starting the next task. 88 // deleteCompletion and starting the next task.
93 void DeleteCompletionHandler(const GURL& url, bool success); 89 void DeleteCompletionHandler(const GURL& url, bool success);
94 // The absolute path of the directory where offline URLs are saved.
95 base::FilePath OfflineRootDirectoryPath();
96 90
97 // The absolute path of the directory where a specific URL is saved offline.
98 // Contains the page and supporting files (images).
99 base::FilePath OfflineURLDirectoryAbsolutePath(const GURL& url);
100 // The absolute path of the offline webpage for the URL. The file may not
101 // exist.
102 base::FilePath OfflinePageAbsolutePath(const GURL& url);
103 // The relative path to the distilled page. The result is relative to
104 // |OfflineRootDirectoryPath()|.
105 base::FilePath OfflinePagePath(const GURL& url);
106 // Creates the offline directory for |url|. Returns true if successful or if 91 // Creates the offline directory for |url|. Returns true if successful or if
107 // the directory already exists. 92 // the directory already exists.
108 bool CreateOfflineURLDirectory(const GURL& url); 93 bool CreateOfflineURLDirectory(const GURL& url);
109 // The name of the directory containing offline data for |url|.
110 std::string OfflineURLDirectoryID(const GURL& url);
111
112 // Saves the |data| for image at |imageURL| to disk, for main URL |url|; 94 // Saves the |data| for image at |imageURL| to disk, for main URL |url|;
113 // puts path of saved file in |path| and returns whether save was successful. 95 // puts path of saved file in |path| and returns whether save was successful.
114 bool SaveImage(const GURL& url, 96 bool SaveImage(const GURL& url,
115 const GURL& imageURL, 97 const GURL& imageURL,
116 const std::string& data, 98 const std::string& data,
117 std::string* image_name); 99 std::string* image_name);
118 // Saves images in |images| array to disk and replaces references in |html| to 100 // Saves images in |images| array to disk and replaces references in |html| to
119 // local path. Returns updated html. 101 // local path. Returns updated html.
120 std::string SaveAndReplaceImagesInHTML( 102 std::string SaveAndReplaceImagesInHTML(
121 const GURL& url, 103 const GURL& url,
(...skipping 25 matching lines...) Expand all
147 std::deque<Task> tasks_; 129 std::deque<Task> tasks_;
148 bool working_; 130 bool working_;
149 base::FilePath base_directory_; 131 base::FilePath base_directory_;
150 std::unique_ptr<dom_distiller::DistillerViewerInterface> distiller_; 132 std::unique_ptr<dom_distiller::DistillerViewerInterface> distiller_;
151 base::CancelableTaskTracker task_tracker_; 133 base::CancelableTaskTracker task_tracker_;
152 134
153 DISALLOW_COPY_AND_ASSIGN(URLDownloader); 135 DISALLOW_COPY_AND_ASSIGN(URLDownloader);
154 }; 136 };
155 137
156 #endif // IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_ 138 #endif // IOS_CHROME_BROWSER_READING_LIST_URL_DOWNLOADER_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_entry.cc ('k') | ios/chrome/browser/reading_list/url_downloader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698