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 COMPONENTS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_
6 #define COMPONENTS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_
10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h"
12 #include "components/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 // Escapes a file name in Drive cache.
46 // Replaces percent ('%'), period ('.') and slash ('/') with %XX (hex)
47 std::string
EscapeCacheFileName(const std::string
& filename
);
49 // Unescapes a file path in Drive cache.
50 // This is the inverse of EscapeCacheFileName.
51 std::string
UnescapeCacheFileName(const std::string
& filename
);
53 // Converts the given string to a form suitable as a file name. Specifically,
54 // - Normalizes in Unicode Normalization Form C.
55 // - Replaces slashes '/' with '_'.
56 // - Replaces the whole input with "_" if the all input characters are '.'.
57 // |input| must be a valid UTF-8 encoded string.
58 std::string
NormalizeFileName(const std::string
& input
);
60 // Does nothing with |error|. Used with functions taking FileOperationCallback.
61 void EmptyFileOperationCallback(FileError error
);
63 // Helper to destroy objects which needs Destroy() to be called on destruction.
64 struct DestroyHelper
{
66 void operator()(T
* object
) const {
72 // Creates a GDoc file with given values.
74 // GDoc files are used to represent hosted documents on local filesystems.
75 // A GDoc file contains a JSON whose content is a URL to view the document and
76 // a resource ID of the entry.
77 bool CreateGDocFile(const base::FilePath
& file_path
,
79 const std::string
& resource_id
);
81 // Reads URL from a GDoc file.
82 GURL
ReadUrlFromGDocFile(const base::FilePath
& file_path
);
84 // Reads resource ID from a GDoc file.
85 std::string
ReadResourceIdFromGDocFile(const base::FilePath
& file_path
);
90 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_