1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_
10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
17 class DriveAppRegistry
;
18 class DriveServiceInterface
;
19 class FileSystemInterface
;
23 // "drive" diretory's local ID is fixed to this value.
24 const char kDriveGrandRootLocalId
[] = "<drive>";
26 // "drive/other" diretory's local ID is fixed to this value.
27 const char kDriveOtherDirLocalId
[] = "<other>";
29 // "drive/trash" diretory's local ID is fixed to this value.
30 const char kDriveTrashDirLocalId
[] = "<trash>";
32 // The directory names used for the Google Drive file system tree. These names
33 // are used in URLs for the file manager, hence user-visible.
34 const char kDriveGrandRootDirName
[] = "drive";
35 const char kDriveMyDriveRootDirName
[] = "root";
36 const char kDriveOtherDirName
[] = "other";
37 const char kDriveTrashDirName
[] = "trash";
39 // Returns the path of the top root of the pseudo tree.
40 const base::FilePath
& GetDriveGrandRootPath();
42 // Returns the path of the directory representing "My Drive".
43 const base::FilePath
& GetDriveMyDriveRootPath();
45 // Returns the Drive mount point path, which looks like
46 // "/special/drive-<username_hash>", when provided with the |user_id_hash|.
47 base::FilePath
GetDriveMountPointPathForUserIdHash(std::string user_id_hash
);
49 // Returns true if the given path is under the Drive mount point.
50 bool IsUnderDriveMountPoint(const base::FilePath
& path
);
52 // Extracts the Drive path from the given path located under the Drive mount
53 // point. Returns an empty path if |path| is not under the Drive mount point.
54 // Examples: ExtractDrivePath("/special/drive-xxx/foo.txt") => "drive/foo.txt"
55 base::FilePath
ExtractDrivePath(const base::FilePath
& path
);
57 // Escapes a file name in Drive cache.
58 // Replaces percent ('%'), period ('.') and slash ('/') with %XX (hex)
59 std::string
EscapeCacheFileName(const std::string
& filename
);
61 // Unescapes a file path in Drive cache.
62 // This is the inverse of EscapeCacheFileName.
63 std::string
UnescapeCacheFileName(const std::string
& filename
);
65 // Converts the given string to a form suitable as a file name. Specifically,
66 // - Normalizes in Unicode Normalization Form C.
67 // - Replaces slashes '/' with '_'.
68 // - Replaces the whole input with "_" if the all input characters are '.'.
69 // |input| must be a valid UTF-8 encoded string.
70 std::string
NormalizeFileName(const std::string
& input
);
72 // Does nothing with |error|. Used with functions taking FileOperationCallback.
73 void EmptyFileOperationCallback(FileError error
);
75 // Helper to destroy objects which needs Destroy() to be called on destruction.
76 struct DestroyHelper
{
78 void operator()(T
* object
) const {
84 // Creates a GDoc file with given values.
86 // GDoc files are used to represent hosted documents on local filesystems.
87 // A GDoc file contains a JSON whose content is a URL to view the document and
88 // a resource ID of the entry.
89 bool CreateGDocFile(const base::FilePath
& file_path
,
91 const std::string
& resource_id
);
93 // Reads URL from a GDoc file.
94 GURL
ReadUrlFromGDocFile(const base::FilePath
& file_path
);
96 // Reads resource ID from a GDoc file.
97 std::string
ReadResourceIdFromGDocFile(const base::FilePath
& file_path
);
102 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_