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

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.cc

Issue 2464333003: arc: Add utility functions to implement ARC content file system (Closed)
Patch Set: Address comments 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 "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h " 5 #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h "
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" 8 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
9 #include "net/base/escape.h" 9 #include "net/base/escape.h"
10 #include "storage/browser/fileapi/file_system_url.h"
10 11
11 namespace arc { 12 namespace arc {
12 13
13 const char kMountPointName[] = "arc-content"; 14 const char kMountPointName[] = "arc-content";
14 15
15 const base::FilePath::CharType kMountPointPath[] = 16 const base::FilePath::CharType kMountPointPath[] =
16 FILE_PATH_LITERAL("/special/arc-content"); 17 FILE_PATH_LITERAL("/special/arc-content");
17 18
19 std::string EscapeArcUrl(const GURL& arc_url) {
20 return net::EscapeQueryParamValue(arc_url.spec(), false);
21 }
22
23 GURL UnescapeArcUrl(const std::string& escaped_arc_url) {
24 return GURL(net::UnescapeURLComponent(
25 escaped_arc_url,
26 net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS |
27 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS));
28 }
29
18 GURL ArcUrlToExternalFileUrl(const GURL& arc_url) { 30 GURL ArcUrlToExternalFileUrl(const GURL& arc_url) {
19 // Return "externalfile:arc-content/<|arc_url| escaped>". 31 // Return "externalfile:arc-content/<|arc_url| escaped>".
20 base::FilePath virtual_path = 32 base::FilePath virtual_path =
21 base::FilePath::FromUTF8Unsafe(kMountPointName) 33 base::FilePath::FromUTF8Unsafe(kMountPointName)
22 .Append(base::FilePath::FromUTF8Unsafe( 34 .Append(base::FilePath::FromUTF8Unsafe(EscapeArcUrl(arc_url)));
23 net::EscapeQueryParamValue(arc_url.spec(), false)));
24 return chromeos::VirtualPathToExternalFileURL(virtual_path); 35 return chromeos::VirtualPathToExternalFileURL(virtual_path);
25 } 36 }
26 37
27 GURL ExternalFileUrlToArcUrl(const GURL& external_file_url) { 38 GURL ExternalFileUrlToArcUrl(const GURL& external_file_url) {
28 base::FilePath virtual_path = 39 base::FilePath virtual_path =
29 chromeos::ExternalFileURLToVirtualPath(external_file_url); 40 chromeos::ExternalFileURLToVirtualPath(external_file_url);
30 base::FilePath path_after_root; 41 base::FilePath path_after_root;
31 if (!base::FilePath::FromUTF8Unsafe(kMountPointName) 42 if (!base::FilePath::FromUTF8Unsafe(kMountPointName)
32 .AppendRelativePath(virtual_path, &path_after_root)) { 43 .AppendRelativePath(virtual_path, &path_after_root)) {
33 return GURL(); 44 return GURL();
34 } 45 }
35 return GURL(net::UnescapeURLComponent( 46 return UnescapeArcUrl(path_after_root.AsUTF8Unsafe());
36 path_after_root.AsUTF8Unsafe(), 47 }
37 net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS | 48
38 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS)); 49 GURL FileSystemUrlToArcUrl(const storage::FileSystemURL& url) {
50 base::FilePath path_after_mount_point;
51 if (!base::FilePath(kMountPointPath)
52 .AppendRelativePath(url.path(), &path_after_mount_point)) {
53 return GURL();
54 }
55 return UnescapeArcUrl(path_after_mount_point.AsUTF8Unsafe());
39 } 56 }
40 57
41 } // namespace arc 58 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698