Chromium Code Reviews| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc |
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54a0bb87ceb42db1c6977c95f7e0fa86bdfbc080 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.cc |
| @@ -0,0 +1,48 @@ |
| +// 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_documents_provider_util.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/strings/string_util.h" |
| +#include "storage/browser/fileapi/file_system_url.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +constexpr base::FilePath::CharType kSpecialDirectory[] = |
| + FILE_PATH_LITERAL("special"); |
| + |
| +} // namespace |
| + |
| +bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url, |
| + std::string* authority, |
| + std::string* root_document_id, |
| + base::FilePath* path) { |
| + if (url.type() != storage::kFileSystemTypeArcDocumentsProvider) { |
|
Luis Héctor Chávez
2016/12/14 20:53:50
nit: elide braces
Shuhei Takahashi
2016/12/15 02:37:55
Done.
|
| + return false; |
| + } |
| + |
| + // Filesystem URL format for documents provider is: |
| + // /special/arc-documents-provider/<authority>/<root_doc_id>/<relative_path> |
| + using Components = std::vector<base::FilePath::StringType>; |
| + Components components; |
| + url.path().GetComponents(&components); |
| + if (components.size() < 5 || components[0] != FILE_PATH_LITERAL("/") || |
|
Luis Héctor Chávez
2016/12/14 20:53:50
re: components[0] != FILE_PATH_LITERAL("/"). Does
Shuhei Takahashi
2016/12/15 02:37:55
Strictly, those two conditions are different. If t
Luis Héctor Chávez
2016/12/15 21:26:10
Got it, thanks for your explanation.
|
| + components[1] != kSpecialDirectory || |
| + components[2] != kDocumentsProviderMountPointName) { |
| + return false; |
| + } |
| + |
| + *authority = components[3]; |
| + *root_document_id = components[4]; |
| + *path = base::FilePath::FromUTF8Unsafe(base::JoinString( |
| + Components(components.begin() + 5, components.end()), "/")); |
| + DCHECK(!path->IsAbsolute()); |
|
Luis Héctor Chávez
2016/12/14 20:53:50
nit: compute the path in a temporary and move the
Shuhei Takahashi
2016/12/15 02:37:55
Hmm, if we return false in the failure case it mak
|
| + return true; |
| +} |
| + |
| +} // namespace arc |