BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system_util.h
blob370c7524f087665feacc54e1fb6e81aea9528623
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h"
12 #include "components/drive/file_errors.h"
13 #include "url/gurl.h"
15 class Profile;
17 namespace storage {
18 class FileSystemURL;
21 namespace drive {
23 class DriveAppRegistry;
24 class DriveServiceInterface;
25 class FileSystemInterface;
27 namespace util {
29 // Returns the Drive mount point path, which looks like "/special/drive-<hash>".
30 base::FilePath GetDriveMountPointPath(Profile* profile);
32 // Returns the Drive mount point path, which looks like
33 // "/special/drive-<username_hash>", when provided with the |user_id_hash|.
34 base::FilePath GetDriveMountPointPathForUserIdHash(std::string user_id_hash);
36 // Returns true if the given path is under the Drive mount point.
37 bool IsUnderDriveMountPoint(const base::FilePath& path);
39 // Extracts the Drive path from the given path located under the Drive mount
40 // point. Returns an empty path if |path| is not under the Drive mount point.
41 // Examples: ExtractDrivePath("/special/drive-xxx/foo.txt") => "drive/foo.txt"
42 base::FilePath ExtractDrivePath(const base::FilePath& path);
44 // Returns the FileSystem for the |profile|. If not available (not mounted
45 // or disabled), returns NULL.
46 FileSystemInterface* GetFileSystemByProfile(Profile* profile);
48 // Returns a FileSystemInterface instance for the |profile_id|, or NULL
49 // if the Profile for |profile_id| is destructed or Drive File System is
50 // disabled for the profile.
51 // Note: |profile_id| should be the pointer of the Profile instance if it is
52 // alive. Considering timing issues due to task posting across threads,
53 // this function can accept a dangling pointer as |profile_id| (and will return
54 // NULL for such a case).
55 // This function must be called on UI thread.
56 FileSystemInterface* GetFileSystemByProfileId(void* profile_id);
58 // Returns the DriveAppRegistry for the |profile|. If not available (not
59 // mounted or disabled), returns NULL.
60 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile);
62 // Returns the DriveService for the |profile|. If not available (not mounted
63 // or disabled), returns NULL.
64 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile);
66 // Extracts |profile| from the given paths located under
67 // GetDriveMountPointPath(profile). Returns NULL if it does not correspond to
68 // a valid mount point path. Must be called from UI thread.
69 Profile* ExtractProfileFromPath(const base::FilePath& path);
71 // Extracts the Drive path (e.g., "drive/foo.txt") from the filesystem URL.
72 // Returns an empty path if |url| does not point under Drive mount point.
73 base::FilePath ExtractDrivePathFromFileSystemUrl(
74 const storage::FileSystemURL& url);
76 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
77 // profile.
78 base::FilePath GetCacheRootPath(Profile* profile);
80 // Callback type for PrepareWritableFileAndRun.
81 typedef base::Callback<void(FileError, const base::FilePath& path)>
82 PrepareWritableFileCallback;
84 // Invokes |callback| on blocking thread pool, after converting virtual |path|
85 // string like "/special/drive/foo.txt" to the concrete local cache file path.
86 // After |callback| returns, the written content is synchronized to the server.
88 // The |path| must be a path under Drive. Must be called from UI thread.
89 void PrepareWritableFileAndRun(Profile* profile,
90 const base::FilePath& path,
91 const PrepareWritableFileCallback& callback);
93 // Ensures the existence of |directory| of '/special/drive/foo'. This will
94 // create |directory| and its ancestors if they don't exist. |callback| is
95 // invoked after making sure that |directory| exists. |callback| should
96 // interpret error codes of either FILE_ERROR_OK or FILE_ERROR_EXISTS as
97 // indicating that |directory| now exists.
99 // If |directory| is not a Drive path, it won't check the existence and just
100 // runs |callback|.
102 // Must be called from UI thread.
103 void EnsureDirectoryExists(Profile* profile,
104 const base::FilePath& directory,
105 const FileOperationCallback& callback);
107 // Returns true if Drive is enabled for the given Profile.
108 bool IsDriveEnabledForProfile(Profile* profile);
110 // Enum type for describing the current connection status to Drive.
111 enum ConnectionStatusType {
112 // Disconnected because Drive service is unavailable for this account (either
113 // disabled by a flag or the account has no Google account (e.g., guests)).
114 DRIVE_DISCONNECTED_NOSERVICE,
115 // Disconnected because no network is available.
116 DRIVE_DISCONNECTED_NONETWORK,
117 // Disconnected because authentication is not ready.
118 DRIVE_DISCONNECTED_NOTREADY,
119 // Connected by cellular network. Background sync is disabled.
120 DRIVE_CONNECTED_METERED,
121 // Connected without condition (WiFi, Ethernet, or cellular with the
122 // disable-sync preference turned off.)
123 DRIVE_CONNECTED,
126 // Returns the Drive connection status for the |profile|.
127 ConnectionStatusType GetDriveConnectionStatus(Profile* profile);
129 } // namespace util
130 } // namespace drive
132 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_