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

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

Issue 2339373002: Prevent error in file path (Closed)
Patch Set: Rebase 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
« 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"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE).get(), 159 web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE).get(),
160 FROM_HERE, 160 FROM_HERE,
161 base::Bind(&URLDownloader::SaveDistilledHTML, base::Unretained(this), 161 base::Bind(&URLDownloader::SaveDistilledHTML, base::Unretained(this),
162 page_url, images_block, block_html), 162 page_url, images_block, block_html),
163 base::Bind(&URLDownloader::DownloadCompletionHandler, 163 base::Bind(&URLDownloader::DownloadCompletionHandler,
164 base::Unretained(this), page_url, title)); 164 base::Unretained(this), page_url, title));
165 } 165 }
166 166
167 URLDownloader::SuccessState URLDownloader::SaveDistilledHTML( 167 URLDownloader::SuccessState URLDownloader::SaveDistilledHTML(
168 const GURL& url, 168 const GURL& url,
169 std::vector<dom_distiller::DistillerViewerInterface::ImageInfo> images, 169 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>&
170 std::string html) { 170 images,
171 const std::string& html) {
171 if (CreateOfflineURLDirectory(url)) { 172 if (CreateOfflineURLDirectory(url)) {
172 return SaveHTMLForURL(SaveAndReplaceImagesInHTML(url, html, images), url) 173 return SaveHTMLForURL(SaveAndReplaceImagesInHTML(url, html, images), url)
173 ? DOWNLOAD_SUCCESS 174 ? DOWNLOAD_SUCCESS
174 : ERROR_PERMANENT; 175 : ERROR_PERMANENT;
175 } 176 }
176 return ERROR_PERMANENT; 177 return ERROR_PERMANENT;
177 } 178 }
178 179
179 base::FilePath URLDownloader::OfflineDirectoryPath() { 180 base::FilePath URLDownloader::OfflineDirectoryPath() {
180 return base_directory_.Append(kOfflineDirectory); 181 return base_directory_.Append(FILE_PATH_LITERAL(kOfflineDirectory));
181 } 182 }
182 183
183 base::FilePath URLDownloader::OfflineURLDirectoryPath(const GURL& url) { 184 base::FilePath URLDownloader::OfflineURLDirectoryPath(const GURL& url) {
184 std::string hash = base::MD5String(url.spec()); 185 std::string hash = base::MD5String(url.spec());
185 return OfflineDirectoryPath().Append(hash); 186 return OfflineDirectoryPath().AppendASCII(hash);
186 } 187 }
187 188
188 base::FilePath URLDownloader::OfflineURLPagePath(const GURL& url) { 189 base::FilePath URLDownloader::OfflineURLPagePath(const GURL& url) {
189 return OfflineURLDirectoryPath(url).Append("page.html"); 190 return OfflineURLDirectoryPath(url).Append(FILE_PATH_LITERAL("page.html"));
190 } 191 }
191 192
192 bool URLDownloader::CreateOfflineURLDirectory(const GURL& url) { 193 bool URLDownloader::CreateOfflineURLDirectory(const GURL& url) {
193 base::FilePath path = OfflineURLDirectoryPath(url); 194 base::FilePath path = OfflineURLDirectoryPath(url);
194 if (!DirectoryExists(path)) { 195 if (!DirectoryExists(path)) {
195 return CreateDirectoryAndGetError(path, nil); 196 return CreateDirectoryAndGetError(path, nil);
196 } 197 }
197 return true; 198 return true;
198 } 199 }
199 200
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return mutable_html; 232 return mutable_html;
232 } 233 }
233 234
234 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { 235 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) {
235 if (html.empty()) { 236 if (html.empty()) {
236 return false; 237 return false;
237 } 238 }
238 base::FilePath path = OfflineURLPagePath(url); 239 base::FilePath path = OfflineURLPagePath(url);
239 return base::WriteFile(path, html.c_str(), html.length()) > 0; 240 return base::WriteFile(path, html.c_str(), html.length()) > 0;
240 } 241 }
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