File: arc_documents_provider_util.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 4,456 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Utilities for ARC documents provider file system.

#ifndef CHROME_BROWSER_ASH_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_UTIL_H_
#define CHROME_BROWSER_ASH_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_UTIL_H_

#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "chromeos/ash/experiences/arc/mojom/file_system.mojom-forward.h"

class GURL;

namespace storage {
class FileSystemURL;
}  // namespace storage

namespace arc {

// The name of ARC documents provider file system mount point.
extern const char kDocumentsProviderMountPointName[];

// The path of ARC documents provider file system mount point.
extern const base::FilePath::CharType kDocumentsProviderMountPointPath[];

// MIME type for directories in Android.
// Defined as DocumentsContract.Document.MIME_TYPE_DIR in Android.
extern const char kAndroidDirectoryMimeType[];

// Escapes a string so it can be used as a file/directory name.
// [%/.] are escaped with percent-encoding.
// NOTE: This function is visible only for unit testing. Usually you should not
// call this function directly.
std::string EscapePathComponent(const std::string& name);

// Unescapes a string escaped by EscapePathComponent().
// NOTE: This function is visible only for unit testing. Usually you should not
// call this function directly.
std::string UnescapePathComponent(const std::string& escaped);

// Returns the path of a directory where the specified DocumentsProvider is
// mounted.
// Appropriate escaping is done to embed |authority| and |root_document_id| in
// a file path.
base::FilePath GetDocumentsProviderMountPath(const std::string& authority,
                                             const std::string& root_id);

// Returns the "escaped_authority/escaped_root_id" suffix of the
// "/foo/bar/baz/escaped_authority/escaped_root_id" that is returned
// by GetDocumentsProviderMountPath.
base::FilePath GetDocumentsProviderMountPathSuffix(const std::string& authority,
                                                   const std::string& root_id);

// Parses an absolute file |path| from the ARC documents provider file system.
// Appropriate unescaping is done to extract |authority| and |root_id|
// from |path|.
// On success, true is returned. All arguments must not be nullptr.
bool ParseDocumentsProviderPath(const base::FilePath& path,
                                std::string* authority,
                                std::string* root_id);

// Parses a FileSystem URL pointing to ARC documents provider file system.
// Appropriate unescaping is done to extract |authority| and |root_id|
// from |url|.  The absolute file |path| is returned with appropriate escaping.
// On success, true is returned. All arguments must not be nullptr.
bool ParseDocumentsProviderUrl(const storage::FileSystemURL& url,
                               std::string* authority,
                               std::string* root_id,
                               base::FilePath* path);

// C++ implementation of DocumentsContract.buildDocumentUri() in Android.
GURL BuildDocumentUrl(const std::string& authority,
                      const std::string& document_id);

// Similar to net::GetExtensionsForMimeType(), but this covers more MIME types
// used in Android.
// Returns an empty vector if the MIME type is not known.
// If the returned vector is not empty, the first extension is the preferred
// extension.
std::vector<base::FilePath::StringType> GetExtensionsForArcMimeType(
    const std::string& mime_type);

// Computes a file name for a document.
base::FilePath::StringType GetFileNameForDocument(
    const mojom::DocumentPtr& document);

// Returns the provided MIME type without the subtype component.
std::string StripMimeSubType(const std::string& mime_type);

// Finds the first matching mime type with |ext| as a valid extension from the
// internal list of Android mime types. On success, the first matching MIME type
// is returned. On failure, nullptr is returned.
std::string FindArcMimeTypeFromExtension(const std::string& ext);

// Returns an ID of a Documents Provider volume.
std::string GetDocumentsProviderVolumeId(const std::string& authority,
                                         const std::string& root_id);

}  // namespace arc

#endif  // CHROME_BROWSER_ASH_ARC_FILEAPI_ARC_DOCUMENTS_PROVIDER_UTIL_H_