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

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

Issue 2507703002: Make offline directory name public. (Closed)
Patch Set: add an S 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
« no previous file with comments | « ios/chrome/browser/reading_list/url_downloader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ios/chrome/browser/reading_list/url_downloader.h" 5 #include "ios/chrome/browser/reading_list/url_downloader.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "ios/chrome/browser/chrome_paths.h" 15 #include "ios/chrome/browser/chrome_paths.h"
16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" 16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h"
17 #include "ios/web/public/web_thread.h" 17 #include "ios/web/public/web_thread.h"
18 #include "net/base/escape.h" 18 #include "net/base/escape.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace { 21 const char kReadingListOfflineDirectory[] = "Offline";
22 char const kOfflineDirectory[] = "Offline";
23 } // namespace
24 22
25 // URLDownloader 23 // URLDownloader
26 24
27 URLDownloader::URLDownloader( 25 URLDownloader::URLDownloader(
28 dom_distiller::DomDistillerService* distiller_service, 26 dom_distiller::DomDistillerService* distiller_service,
29 PrefService* prefs, 27 PrefService* prefs,
30 base::FilePath chrome_profile_path, 28 base::FilePath chrome_profile_path,
31 const DownloadCompletion& download_completion, 29 const DownloadCompletion& download_completion,
32 const SuccessCompletion& delete_completion) 30 const SuccessCompletion& delete_completion)
33 : distiller_service_(distiller_service), 31 : distiller_service_(distiller_service),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 const std::string& html) { 167 const std::string& html) {
170 if (CreateOfflineURLDirectory(url)) { 168 if (CreateOfflineURLDirectory(url)) {
171 return SaveHTMLForURL(SaveAndReplaceImagesInHTML(url, html, images), url) 169 return SaveHTMLForURL(SaveAndReplaceImagesInHTML(url, html, images), url)
172 ? DOWNLOAD_SUCCESS 170 ? DOWNLOAD_SUCCESS
173 : ERROR_PERMANENT; 171 : ERROR_PERMANENT;
174 } 172 }
175 return ERROR_PERMANENT; 173 return ERROR_PERMANENT;
176 } 174 }
177 175
178 base::FilePath URLDownloader::OfflineRootDirectoryPath() { 176 base::FilePath URLDownloader::OfflineRootDirectoryPath() {
179 return base_directory_.Append(FILE_PATH_LITERAL(kOfflineDirectory)); 177 return base_directory_.Append(
178 FILE_PATH_LITERAL(kReadingListOfflineDirectory));
180 } 179 }
181 180
182 std::string URLDownloader::OfflineURLDirectoryID(const GURL& url) { 181 std::string URLDownloader::OfflineURLDirectoryID(const GURL& url) {
183 return base::MD5String(url.spec()); 182 return base::MD5String(url.spec());
184 } 183 }
185 184
186 base::FilePath URLDownloader::OfflinePagePath(const GURL& url) { 185 base::FilePath URLDownloader::OfflinePagePath(const GURL& url) {
187 base::FilePath directory(OfflineURLDirectoryID(url)); 186 base::FilePath directory(OfflineURLDirectoryID(url));
188 return directory.Append(FILE_PATH_LITERAL("page.html")); 187 return directory.Append(FILE_PATH_LITERAL("page.html"));
189 } 188 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return mutable_html; 239 return mutable_html;
241 } 240 }
242 241
243 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { 242 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) {
244 if (html.empty()) { 243 if (html.empty()) {
245 return false; 244 return false;
246 } 245 }
247 base::FilePath path = OfflinePageAbsolutePath(url); 246 base::FilePath path = OfflinePageAbsolutePath(url);
248 return base::WriteFile(path, html.c_str(), html.length()) > 0; 247 return base::WriteFile(path, html.c_str(), html.length()) > 0;
249 } 248 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/url_downloader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698