Chromium Code Reviews| Index: chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.cc |
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ef0463be270cd1394ecb66539244520442eb3037 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.cc |
| @@ -0,0 +1,38 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_url_util.h" |
| + |
| +#include "base/files/file_path.h" |
| +#include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| +#include "net/base/escape.h" |
| + |
| +namespace arc { |
| + |
| +const char kMountPointName[] = "arc-content"; |
|
mtomasz
2016/10/20 08:55:05
nit: Can this be constexpr and/or anonymous namesp
hashimoto
2016/10/20 09:26:45
Later this will be used to add a mount to chromeos
|
| + |
| +GURL ArcUrlToExternalFileUrl(const GURL& arc_url) { |
| + // Return "externalfile:arc-content/<|arc_url| escaped>". |
| + base::FilePath virtual_path = |
| + base::FilePath::FromUTF8Unsafe(kMountPointName) |
| + .Append(base::FilePath::FromUTF8Unsafe( |
| + net::EscapeQueryParamValue(arc_url.spec(), false))); |
| + return chromeos::VirtualPathToExternalFileURL(virtual_path); |
| +} |
| + |
| +GURL ExternalFileUrlToArcUrl(const GURL& external_file_url) { |
| + base::FilePath virtual_path = |
| + chromeos::ExternalFileURLToVirtualPath(external_file_url); |
| + base::FilePath path_after_root; |
| + if (!base::FilePath::FromUTF8Unsafe(kMountPointName) |
| + .AppendRelativePath(virtual_path, &path_after_root)) { |
| + return GURL(); |
| + } |
| + return GURL(net::UnescapeURLComponent( |
| + path_after_root.AsUTF8Unsafe(), |
| + net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS | |
| + net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS)); |
| +} |
| + |
| +} // namespace arc |