Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util.h

Issue 1192493003: Move browser-agnostic code from file_system_util to file_system_core_util. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@drive-prefservice
Patch Set: Rebasing... Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h" 12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 class Profile; 15 class Profile;
16 16
17 namespace storage { 17 namespace storage {
18 class FileSystemURL; 18 class FileSystemURL;
19 } 19 }
20 20
21 namespace drive { 21 namespace drive {
22 22
23 class DriveAppRegistry; 23 class DriveAppRegistry;
24 class DriveServiceInterface; 24 class DriveServiceInterface;
25 class FileSystemInterface; 25 class FileSystemInterface;
26 26
27
28 namespace util { 27 namespace util {
29 28
30 // "drive" diretory's local ID is fixed to this value.
31 const char kDriveGrandRootLocalId[] = "<drive>";
32
33 // "drive/other" diretory's local ID is fixed to this value.
34 const char kDriveOtherDirLocalId[] = "<other>";
35
36 // "drive/trash" diretory's local ID is fixed to this value.
37 const char kDriveTrashDirLocalId[] = "<trash>";
38
39 // The directory names used for the Google Drive file system tree. These names
40 // are used in URLs for the file manager, hence user-visible.
41 const char kDriveGrandRootDirName[] = "drive";
42 const char kDriveMyDriveRootDirName[] = "root";
43 const char kDriveOtherDirName[] = "other";
44 const char kDriveTrashDirName[] = "trash";
45
46 // Returns the path of the top root of the pseudo tree.
47 const base::FilePath& GetDriveGrandRootPath();
48
49 // Returns the path of the directory representing "My Drive".
50 const base::FilePath& GetDriveMyDriveRootPath();
51
52 // Returns the Drive mount point path, which looks like "/special/drive-<hash>". 29 // Returns the Drive mount point path, which looks like "/special/drive-<hash>".
53 base::FilePath GetDriveMountPointPath(Profile* profile); 30 base::FilePath GetDriveMountPointPath(Profile* profile);
54 31
55 // Returns the Drive mount point path, which looks like
56 // "/special/drive-<username_hash>", when provided with the |user_id_hash|.
57 base::FilePath GetDriveMountPointPathForUserIdHash(std::string user_id_hash);
58
59 // Returns the FileSystem for the |profile|. If not available (not mounted 32 // Returns the FileSystem for the |profile|. If not available (not mounted
60 // or disabled), returns NULL. 33 // or disabled), returns NULL.
61 FileSystemInterface* GetFileSystemByProfile(Profile* profile); 34 FileSystemInterface* GetFileSystemByProfile(Profile* profile);
62 35
63 // Returns a FileSystemInterface instance for the |profile_id|, or NULL 36 // Returns a FileSystemInterface instance for the |profile_id|, or NULL
64 // if the Profile for |profile_id| is destructed or Drive File System is 37 // if the Profile for |profile_id| is destructed or Drive File System is
65 // disabled for the profile. 38 // disabled for the profile.
66 // Note: |profile_id| should be the pointer of the Profile instance if it is 39 // Note: |profile_id| should be the pointer of the Profile instance if it is
67 // alive. Considering timing issues due to task posting across threads, 40 // alive. Considering timing issues due to task posting across threads,
68 // this function can accept a dangling pointer as |profile_id| (and will return 41 // this function can accept a dangling pointer as |profile_id| (and will return
69 // NULL for such a case). 42 // NULL for such a case).
70 // This function must be called on UI thread. 43 // This function must be called on UI thread.
71 FileSystemInterface* GetFileSystemByProfileId(void* profile_id); 44 FileSystemInterface* GetFileSystemByProfileId(void* profile_id);
72 45
73 // Returns the DriveAppRegistry for the |profile|. If not available (not 46 // Returns the DriveAppRegistry for the |profile|. If not available (not
74 // mounted or disabled), returns NULL. 47 // mounted or disabled), returns NULL.
75 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile); 48 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile);
76 49
77 // Returns the DriveService for the |profile|. If not available (not mounted 50 // Returns the DriveService for the |profile|. If not available (not mounted
78 // or disabled), returns NULL. 51 // or disabled), returns NULL.
79 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile); 52 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile);
80 53
81 // Returns true if the given path is under the Drive mount point.
82 bool IsUnderDriveMountPoint(const base::FilePath& path);
83
84 // Extracts the Drive path from the given path located under the Drive mount
85 // point. Returns an empty path if |path| is not under the Drive mount point.
86 // Examples: ExtractDrivePath("/special/drive-xxx/foo.txt") => "drive/foo.txt"
87 base::FilePath ExtractDrivePath(const base::FilePath& path);
88
89 // Extracts |profile| from the given paths located under 54 // Extracts |profile| from the given paths located under
90 // GetDriveMountPointPath(profile). Returns NULL if it does not correspond to 55 // GetDriveMountPointPath(profile). Returns NULL if it does not correspond to
91 // a valid mount point path. Must be called from UI thread. 56 // a valid mount point path. Must be called from UI thread.
92 Profile* ExtractProfileFromPath(const base::FilePath& path); 57 Profile* ExtractProfileFromPath(const base::FilePath& path);
93 58
94 // Extracts the Drive path (e.g., "drive/foo.txt") from the filesystem URL. 59 // Extracts the Drive path (e.g., "drive/foo.txt") from the filesystem URL.
95 // Returns an empty path if |url| does not point under Drive mount point. 60 // Returns an empty path if |url| does not point under Drive mount point.
96 base::FilePath ExtractDrivePathFromFileSystemUrl( 61 base::FilePath ExtractDrivePathFromFileSystemUrl(
97 const storage::FileSystemURL& url); 62 const storage::FileSystemURL& url);
98 63
99 // Escapes a file name in Drive cache.
100 // Replaces percent ('%'), period ('.') and slash ('/') with %XX (hex)
101 std::string EscapeCacheFileName(const std::string& filename);
102
103 // Unescapes a file path in Drive cache.
104 // This is the inverse of EscapeCacheFileName.
105 std::string UnescapeCacheFileName(const std::string& filename);
106
107 // Converts the given string to a form suitable as a file name. Specifically,
108 // - Normalizes in Unicode Normalization Form C.
109 // - Replaces slashes '/' with '_'.
110 // - Replaces the whole input with "_" if the all input characters are '.'.
111 // |input| must be a valid UTF-8 encoded string.
112 std::string NormalizeFileName(const std::string& input);
113
114 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the 64 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
115 // profile. 65 // profile.
116 base::FilePath GetCacheRootPath(Profile* profile); 66 base::FilePath GetCacheRootPath(Profile* profile);
117 67
118 // Callback type for PrepareWritableFileAndRun. 68 // Callback type for PrepareWritableFileAndRun.
119 typedef base::Callback<void (FileError, const base::FilePath& path)> 69 typedef base::Callback<void(FileError, const base::FilePath& path)>
120 PrepareWritableFileCallback; 70 PrepareWritableFileCallback;
121 71
122 // Invokes |callback| on blocking thread pool, after converting virtual |path| 72 // Invokes |callback| on blocking thread pool, after converting virtual |path|
123 // string like "/special/drive/foo.txt" to the concrete local cache file path. 73 // string like "/special/drive/foo.txt" to the concrete local cache file path.
124 // After |callback| returns, the written content is synchronized to the server. 74 // After |callback| returns, the written content is synchronized to the server.
125 // 75 //
126 // The |path| must be a path under Drive. Must be called from UI thread. 76 // The |path| must be a path under Drive. Must be called from UI thread.
127 void PrepareWritableFileAndRun(Profile* profile, 77 void PrepareWritableFileAndRun(Profile* profile,
128 const base::FilePath& path, 78 const base::FilePath& path,
129 const PrepareWritableFileCallback& callback); 79 const PrepareWritableFileCallback& callback);
130 80
131 // Ensures the existence of |directory| of '/special/drive/foo'. This will 81 // Ensures the existence of |directory| of '/special/drive/foo'. This will
132 // create |directory| and its ancestors if they don't exist. |callback| is 82 // create |directory| and its ancestors if they don't exist. |callback| is
133 // invoked after making sure that |directory| exists. |callback| should 83 // invoked after making sure that |directory| exists. |callback| should
134 // interpret error codes of either FILE_ERROR_OK or FILE_ERROR_EXISTS as 84 // interpret error codes of either FILE_ERROR_OK or FILE_ERROR_EXISTS as
135 // indicating that |directory| now exists. 85 // indicating that |directory| now exists.
136 // 86 //
137 // If |directory| is not a Drive path, it won't check the existence and just 87 // If |directory| is not a Drive path, it won't check the existence and just
138 // runs |callback|. 88 // runs |callback|.
139 // 89 //
140 // Must be called from UI thread. 90 // Must be called from UI thread.
141 void EnsureDirectoryExists(Profile* profile, 91 void EnsureDirectoryExists(Profile* profile,
142 const base::FilePath& directory, 92 const base::FilePath& directory,
143 const FileOperationCallback& callback); 93 const FileOperationCallback& callback);
144 94
145 // Does nothing with |error|. Used with functions taking FileOperationCallback.
146 void EmptyFileOperationCallback(FileError error);
147
148 // Helper to destroy objects which needs Destroy() to be called on destruction.
149 struct DestroyHelper {
150 template<typename T>
151 void operator()(T* object) const {
152 if (object)
153 object->Destroy();
154 }
155 };
156
157 // Creates a GDoc file with given values.
158 //
159 // GDoc files are used to represent hosted documents on local filesystems.
160 // A GDoc file contains a JSON whose content is a URL to view the document and
161 // a resource ID of the entry.
162 bool CreateGDocFile(const base::FilePath& file_path,
163 const GURL& url,
164 const std::string& resource_id);
165
166 // Reads URL from a GDoc file.
167 GURL ReadUrlFromGDocFile(const base::FilePath& file_path);
168
169 // Reads resource ID from a GDoc file.
170 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path);
171
172 // Returns true if Drive is enabled for the given Profile. 95 // Returns true if Drive is enabled for the given Profile.
173 bool IsDriveEnabledForProfile(Profile* profile); 96 bool IsDriveEnabledForProfile(Profile* profile);
174 97
175 // Enum type for describing the current connection status to Drive. 98 // Enum type for describing the current connection status to Drive.
176 enum ConnectionStatusType { 99 enum ConnectionStatusType {
177 // Disconnected because Drive service is unavailable for this account (either 100 // Disconnected because Drive service is unavailable for this account (either
178 // disabled by a flag or the account has no Google account (e.g., guests)). 101 // disabled by a flag or the account has no Google account (e.g., guests)).
179 DRIVE_DISCONNECTED_NOSERVICE, 102 DRIVE_DISCONNECTED_NOSERVICE,
180 // Disconnected because no network is available. 103 // Disconnected because no network is available.
181 DRIVE_DISCONNECTED_NONETWORK, 104 DRIVE_DISCONNECTED_NONETWORK,
182 // Disconnected because authentication is not ready. 105 // Disconnected because authentication is not ready.
183 DRIVE_DISCONNECTED_NOTREADY, 106 DRIVE_DISCONNECTED_NOTREADY,
184 // Connected by cellular network. Background sync is disabled. 107 // Connected by cellular network. Background sync is disabled.
185 DRIVE_CONNECTED_METERED, 108 DRIVE_CONNECTED_METERED,
186 // Connected without condition (WiFi, Ethernet, or cellular with the 109 // Connected without condition (WiFi, Ethernet, or cellular with the
187 // disable-sync preference turned off.) 110 // disable-sync preference turned off.)
188 DRIVE_CONNECTED, 111 DRIVE_CONNECTED,
189 }; 112 };
190 113
191 // Returns the Drive connection status for the |profile|. 114 // Returns the Drive connection status for the |profile|.
192 ConnectionStatusType GetDriveConnectionStatus(Profile* profile); 115 ConnectionStatusType GetDriveConnectionStatus(Profile* profile);
193 116
194 } // namespace util 117 } // namespace util
195 } // namespace drive 118 } // namespace drive
196 119
197 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_ 120 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_unittest.cc ('k') | chrome/browser/chromeos/drive/file_system_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698