Chromium Code Reviews| 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 "components/reading_list/ios/offline_url_utils.h" | 5 #include "components/reading_list/core/offline_url_utils.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 7 #include "base/md5.h" | 8 #include "base/md5.h" |
| 8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 const char kOfflineDirectory[] = "Offline"; | 12 const base::FilePath::CharType kOfflineDirectory[] = |
|
sdefresne
2017/03/23 10:57:06
optional: it is quite common to define a macro FPL
Olivier
2017/03/23 12:27:37
Thanks.
I think I prefer this format
| |
| 12 const char kMainPageFileName[] = "page.html"; | 13 FILE_PATH_LITERAL("Offline"); |
| 13 const char kPDFFileName[] = "file.pdf"; | 14 const base::FilePath::CharType kMainPageFileName[] = |
| 15 FILE_PATH_LITERAL("page.html"); | |
| 16 const base::FilePath::CharType kPDFFileName[] = FILE_PATH_LITERAL("file.pdf"); | |
| 14 } // namespace | 17 } // namespace |
| 15 | 18 |
| 16 namespace reading_list { | 19 namespace reading_list { |
| 17 | 20 |
| 18 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { | 21 base::FilePath OfflineRootDirectoryPath(const base::FilePath& profile_path) { |
| 19 return profile_path.Append(FILE_PATH_LITERAL(kOfflineDirectory)); | 22 return profile_path.Append(kOfflineDirectory); |
| 20 } | 23 } |
| 21 | 24 |
| 22 std::string OfflineURLDirectoryID(const GURL& url) { | 25 std::string OfflineURLDirectoryID(const GURL& url) { |
| 23 return base::MD5String(url.spec()); | 26 return base::MD5String(url.spec()); |
| 24 } | 27 } |
| 25 | 28 |
| 26 base::FilePath OfflineURLDirectoryAbsolutePath( | 29 base::FilePath OfflineURLDirectoryAbsolutePath( |
| 27 const base::FilePath& profile_path, | 30 const base::FilePath& profile_path, |
| 28 const GURL& url) { | 31 const GURL& url) { |
| 29 return OfflineURLAbsolutePathFromRelativePath( | 32 return OfflineURLAbsolutePathFromRelativePath( |
| 30 profile_path, base::FilePath(OfflineURLDirectoryID(url))); | 33 profile_path, base::FilePath::FromUTF8Unsafe(OfflineURLDirectoryID(url))); |
| 31 } | 34 } |
| 32 | 35 |
| 33 base::FilePath OfflinePagePath(const GURL& url, OfflineFileType type) { | 36 base::FilePath OfflinePagePath(const GURL& url, OfflineFileType type) { |
| 34 base::FilePath directory(OfflineURLDirectoryID(url)); | 37 base::FilePath directory = |
| 38 base::FilePath::FromUTF8Unsafe(OfflineURLDirectoryID(url)); | |
| 35 switch (type) { | 39 switch (type) { |
| 36 case OFFLINE_TYPE_HTML: | 40 case OFFLINE_TYPE_HTML: |
| 37 return directory.Append(FILE_PATH_LITERAL(kMainPageFileName)); | 41 return directory.Append(kMainPageFileName); |
| 38 case OFFLINE_TYPE_PDF: | 42 case OFFLINE_TYPE_PDF: |
| 39 return directory.Append(FILE_PATH_LITERAL(kPDFFileName)); | 43 return directory.Append(kPDFFileName); |
| 40 } | 44 } |
| 45 NOTREACHED(); | |
| 46 return base::FilePath(); | |
| 41 } | 47 } |
| 42 | 48 |
| 43 base::FilePath OfflineURLAbsolutePathFromRelativePath( | 49 base::FilePath OfflineURLAbsolutePathFromRelativePath( |
| 44 const base::FilePath& profile_path, | 50 const base::FilePath& profile_path, |
| 45 const base::FilePath& relative_path) { | 51 const base::FilePath& relative_path) { |
| 46 return OfflineRootDirectoryPath(profile_path).Append(relative_path); | 52 return OfflineRootDirectoryPath(profile_path).Append(relative_path); |
| 47 } | 53 } |
| 48 } | 54 } |
| OLD | NEW |