| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/reading_list/ios/offline_url_utils.h" | |
| 6 | |
| 7 #include "base/md5.h" | |
| 8 #include "base/strings/stringprintf.h" | |
| 9 | |
| 10 namespace { | |
| 11 const char kOfflineDirectory[] = "Offline"; | |
| 12 const char kMainPageFileName[] = "page.html"; | |
| 13 const char kPDFFileName[] = "file.pdf"; | |
| 14 } // namespace | |
| 15 | |
| 16 namespace reading_list { | |
| 17 | |
| 18 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { | |
| 19 return profile_path.Append(FILE_PATH_LITERAL(kOfflineDirectory)); | |
| 20 } | |
| 21 | |
| 22 std::string OfflineURLDirectoryID(const GURL& url) { | |
| 23 return base::MD5String(url.spec()); | |
| 24 } | |
| 25 | |
| 26 base::FilePath OfflineURLDirectoryAbsolutePath( | |
| 27 const base::FilePath& profile_path, | |
| 28 const GURL& url) { | |
| 29 return OfflineURLAbsolutePathFromRelativePath( | |
| 30 profile_path, base::FilePath(OfflineURLDirectoryID(url))); | |
| 31 } | |
| 32 | |
| 33 base::FilePath OfflinePagePath(const GURL& url, OfflineFileType type) { | |
| 34 base::FilePath directory(OfflineURLDirectoryID(url)); | |
| 35 switch (type) { | |
| 36 case OFFLINE_TYPE_HTML: | |
| 37 return directory.Append(FILE_PATH_LITERAL(kMainPageFileName)); | |
| 38 case OFFLINE_TYPE_PDF: | |
| 39 return directory.Append(FILE_PATH_LITERAL(kPDFFileName)); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 base::FilePath OfflineURLAbsolutePathFromRelativePath( | |
| 44 const base::FilePath& profile_path, | |
| 45 const base::FilePath& relative_path) { | |
| 46 return OfflineRootDirectoryPath(profile_path).Append(relative_path); | |
| 47 } | |
| 48 } | |
| OLD | NEW |