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

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

Issue 2514333003: Componentize Reading List (Closed)
Patch Set: fix Created 4 years, 1 month 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/offline_url_utils.h" 5 #include "ios/chrome/browser/reading_list/offline_url_utils.h"
6 6
7 #include "base/md5.h" 7 #include "base/md5.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "components/reading_list/offline_url_utils.h"
9 #include "ios/chrome/browser/chrome_url_constants.h" 10 #include "ios/chrome/browser/chrome_url_constants.h"
10 11
11 namespace {
12 const char kOfflineDirectory[] = "Offline";
13 const char kMainPageFileName[] = "page.html";
14 } // namespace
15
16 namespace reading_list { 12 namespace reading_list {
17 13
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 OfflinePagePath(const GURL& url) {
27 base::FilePath directory(OfflineURLDirectoryID(url));
28 return directory.Append(FILE_PATH_LITERAL(kMainPageFileName));
29 }
30
31 base::FilePath OfflineURLDirectoryAbsolutePath(
32 const base::FilePath& profile_path,
33 const GURL& url) {
34 return OfflineRootDirectoryPath(profile_path)
35 .Append(OfflineURLDirectoryID(url));
36 }
37
38 base::FilePath OfflinePageAbsolutePath(const base::FilePath& profile_path,
39 const GURL& url) {
40 return OfflineRootDirectoryPath(profile_path).Append(OfflinePagePath(url));
41 }
42
43 GURL DistilledURLForPath(const base::FilePath& distilled_path) { 14 GURL DistilledURLForPath(const base::FilePath& distilled_path) {
44 if (distilled_path.empty()) { 15 if (distilled_path.empty()) {
45 return GURL(); 16 return GURL();
46 } 17 }
47 return GURL(kChromeUIOfflineURL + distilled_path.value()); 18 return GURL(kChromeUIOfflineURL + distilled_path.value());
48 } 19 }
49 20
50 GURL FileURLForDistilledURL(const GURL& distilled_url, 21 GURL FileURLForDistilledURL(const GURL& distilled_url,
51 const base::FilePath& profile_path, 22 const base::FilePath& profile_path,
52 GURL* resources_root_url) { 23 GURL* resources_root_url) {
53 if (!distilled_url.is_valid()) { 24 if (!distilled_url.is_valid()) {
54 return GURL(); 25 return GURL();
55 } 26 }
56 DCHECK(distilled_url.SchemeIs(kChromeUIScheme)); 27 DCHECK(distilled_url.SchemeIs(kChromeUIScheme));
57 base::FilePath offline_path = profile_path.AppendASCII(kOfflineDirectory); 28 base::FilePath offline_path = OfflineRootDirectoryPath(profile_path);
58 29
59 GURL file_url(base::StringPrintf("%s%s", url::kFileScheme, 30 GURL file_url(base::StringPrintf("%s%s", url::kFileScheme,
60 url::kStandardSchemeSeparator) + 31 url::kStandardSchemeSeparator) +
61 offline_path.value() + distilled_url.path()); 32 offline_path.value() + distilled_url.path());
62 if (resources_root_url) { 33 if (resources_root_url) {
63 *resources_root_url = file_url.Resolve("."); 34 *resources_root_url = file_url.Resolve(".");
64 } 35 }
65 return file_url; 36 return file_url;
66 } 37 }
67 } 38 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698