| OLD | NEW |
| 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 "base/stl_util.h" |
| 14 #include "components/reading_list/core/offline_url_utils.h" | 15 #include "components/reading_list/core/offline_url_utils.h" |
| 15 #include "ios/chrome/browser/chrome_paths.h" | 16 #include "ios/chrome/browser/chrome_paths.h" |
| 16 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" | 17 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 17 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" | 18 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" |
| 18 #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" | 19 #include "ios/chrome/browser/reading_list/reading_list_distiller_page_factory.h" |
| 19 #include "ios/web/public/web_thread.h" | 20 #include "ios/web/public/web_thread.h" |
| 20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 23 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 74 } |
| 74 | 75 |
| 75 void URLDownloader::RemoveOfflineURL(const GURL& url) { | 76 void URLDownloader::RemoveOfflineURL(const GURL& url) { |
| 76 // Remove all download tasks for this url as it would be pointless work. | 77 // Remove all download tasks for this url as it would be pointless work. |
| 77 CancelDownloadOfflineURL(url); | 78 CancelDownloadOfflineURL(url); |
| 78 tasks_.push_back(std::make_pair(DELETE, url)); | 79 tasks_.push_back(std::make_pair(DELETE, url)); |
| 79 HandleNextTask(); | 80 HandleNextTask(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void URLDownloader::DownloadOfflineURL(const GURL& url) { | 83 void URLDownloader::DownloadOfflineURL(const GURL& url) { |
| 83 if (std::find(tasks_.begin(), tasks_.end(), std::make_pair(DOWNLOAD, url)) == | 84 if (!base::ContainsValue(tasks_, std::make_pair(DOWNLOAD, url))) { |
| 84 tasks_.end()) { | |
| 85 tasks_.push_back(std::make_pair(DOWNLOAD, url)); | 85 tasks_.push_back(std::make_pair(DOWNLOAD, url)); |
| 86 HandleNextTask(); | 86 HandleNextTask(); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void URLDownloader::CancelDownloadOfflineURL(const GURL& url) { | 90 void URLDownloader::CancelDownloadOfflineURL(const GURL& url) { |
| 91 tasks_.erase( | 91 tasks_.erase( |
| 92 std::remove(tasks_.begin(), tasks_.end(), std::make_pair(DOWNLOAD, url)), | 92 std::remove(tasks_.begin(), tasks_.end(), std::make_pair(DOWNLOAD, url)), |
| 93 tasks_.end()); | 93 tasks_.end()); |
| 94 } | 94 } |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath( | 377 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath( |
| 378 base_directory_, | 378 base_directory_, |
| 379 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML)); | 379 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML)); |
| 380 int written = base::WriteFile(path, html.c_str(), html.length()); | 380 int written = base::WriteFile(path, html.c_str(), html.length()); |
| 381 if (written <= 0) { | 381 if (written <= 0) { |
| 382 return false; | 382 return false; |
| 383 } | 383 } |
| 384 saved_size_ += written; | 384 saved_size_ += written; |
| 385 return true; | 385 return true; |
| 386 } | 386 } |
| OLD | NEW |