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

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

Issue 2604773002: Create distiller files for Reading List. (Closed)
Patch Set: feedback Created 3 years, 11 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 #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/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "components/reading_list/ios/offline_url_utils.h" 14 #include "components/reading_list/ios/offline_url_utils.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/chrome/browser/reading_list/reading_list_distiller_page_factory.h"
17 #include "ios/web/public/web_thread.h" 18 #include "ios/web/public/web_thread.h"
18 #include "net/base/escape.h" 19 #include "net/base/escape.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 // URLDownloader 22 // URLDownloader
22 23
23 URLDownloader::URLDownloader( 24 URLDownloader::URLDownloader(
24 dom_distiller::DomDistillerService* distiller_service, 25 dom_distiller::DomDistillerService* distiller_service,
26 reading_list::ReadingListDistillerPageFactory* distiller_page_factory,
25 PrefService* prefs, 27 PrefService* prefs,
26 base::FilePath chrome_profile_path, 28 base::FilePath chrome_profile_path,
27 const DownloadCompletion& download_completion, 29 const DownloadCompletion& download_completion,
28 const SuccessCompletion& delete_completion) 30 const SuccessCompletion& delete_completion)
29 : distiller_service_(distiller_service), 31 : distiller_service_(distiller_service),
32 distiller_page_factory_(distiller_page_factory),
30 pref_service_(prefs), 33 pref_service_(prefs),
31 download_completion_(download_completion), 34 download_completion_(download_completion),
32 delete_completion_(delete_completion), 35 delete_completion_(delete_completion),
33 working_(false), 36 working_(false),
34 base_directory_(chrome_profile_path), 37 base_directory_(chrome_profile_path),
35 task_tracker_() {} 38 task_tracker_() {}
36 39
37 URLDownloader::~URLDownloader() { 40 URLDownloader::~URLDownloader() {
38 task_tracker_.TryCancelAll(); 41 task_tracker_.TryCancelAll();
39 } 42 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 138 }
136 139
137 void URLDownloader::DownloadURL(GURL url, bool offline_url_exists) { 140 void URLDownloader::DownloadURL(GURL url, bool offline_url_exists) {
138 if (offline_url_exists) { 141 if (offline_url_exists) {
139 DownloadCompletionHandler(url, std::string(), DOWNLOAD_EXISTS); 142 DownloadCompletionHandler(url, std::string(), DOWNLOAD_EXISTS);
140 return; 143 return;
141 } 144 }
142 145
143 distiller_.reset(new dom_distiller::DistillerViewer( 146 distiller_.reset(new dom_distiller::DistillerViewer(
144 distiller_service_, pref_service_, url, 147 distiller_service_, pref_service_, url,
145 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); 148 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)),
149 distiller_page_factory_));
146 } 150 }
147 151
148 void URLDownloader::DistillerCallback( 152 void URLDownloader::DistillerCallback(
149 const GURL& page_url, 153 const GURL& page_url,
150 const std::string& html, 154 const std::string& html,
151 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>& 155 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>&
152 images, 156 images,
153 const std::string& title) { 157 const std::string& title) {
154 if (html.empty()) { 158 if (html.empty()) {
155 DownloadCompletionHandler(page_url, std::string(), ERROR_RETRY); 159 DownloadCompletionHandler(page_url, std::string(), ERROR_RETRY);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 236 }
233 237
234 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { 238 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) {
235 if (html.empty()) { 239 if (html.empty()) {
236 return false; 240 return false;
237 } 241 }
238 base::FilePath path = 242 base::FilePath path =
239 reading_list::OfflinePageAbsolutePath(base_directory_, url); 243 reading_list::OfflinePageAbsolutePath(base_directory_, url);
240 return base::WriteFile(path, html.c_str(), html.length()) > 0; 244 return base::WriteFile(path, html.c_str(), html.length()) > 0;
241 } 245 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/url_downloader.h ('k') | ios/chrome/browser/reading_list/url_downloader_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698