OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/files/file_path.h" |
| 12 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace drive { |
| 16 |
| 17 class DriveAppRegistry; |
| 18 class DriveServiceInterface; |
| 19 class FileSystemInterface; |
| 20 |
| 21 namespace util { |
| 22 |
| 23 // "drive" diretory's local ID is fixed to this value. |
| 24 const char kDriveGrandRootLocalId[] = "<drive>"; |
| 25 |
| 26 // "drive/other" diretory's local ID is fixed to this value. |
| 27 const char kDriveOtherDirLocalId[] = "<other>"; |
| 28 |
| 29 // "drive/trash" diretory's local ID is fixed to this value. |
| 30 const char kDriveTrashDirLocalId[] = "<trash>"; |
| 31 |
| 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"; |
| 38 |
| 39 // Returns the path of the top root of the pseudo tree. |
| 40 const base::FilePath& GetDriveGrandRootPath(); |
| 41 |
| 42 // Returns the path of the directory representing "My Drive". |
| 43 const base::FilePath& GetDriveMyDriveRootPath(); |
| 44 |
| 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); |
| 48 |
| 49 // Returns true if the given path is under the Drive mount point. |
| 50 bool IsUnderDriveMountPoint(const base::FilePath& path); |
| 51 |
| 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); |
| 56 |
| 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); |
| 60 |
| 61 // Unescapes a file path in Drive cache. |
| 62 // This is the inverse of EscapeCacheFileName. |
| 63 std::string UnescapeCacheFileName(const std::string& filename); |
| 64 |
| 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); |
| 71 |
| 72 // Does nothing with |error|. Used with functions taking FileOperationCallback. |
| 73 void EmptyFileOperationCallback(FileError error); |
| 74 |
| 75 // Helper to destroy objects which needs Destroy() to be called on destruction. |
| 76 struct DestroyHelper { |
| 77 template <typename T> |
| 78 void operator()(T* object) const { |
| 79 if (object) |
| 80 object->Destroy(); |
| 81 } |
| 82 }; |
| 83 |
| 84 // Creates a GDoc file with given values. |
| 85 // |
| 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, |
| 90 const GURL& url, |
| 91 const std::string& resource_id); |
| 92 |
| 93 // Reads URL from a GDoc file. |
| 94 GURL ReadUrlFromGDocFile(const base::FilePath& file_path); |
| 95 |
| 96 // Reads resource ID from a GDoc file. |
| 97 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path); |
| 98 |
| 99 } // namespace util |
| 100 } // namespace drive |
| 101 |
| 102 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_CORE_UTIL_H_ |
OLD | NEW |