Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system_util.h
blobea9abd57d141f001a0207a3ca50feb7440c0d359
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 "chrome/browser/chromeos/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 FileSystem for the |profile|. If not available (not mounted
33 // or disabled), returns NULL.
34 FileSystemInterface* GetFileSystemByProfile(Profile* profile);
36 // Returns a FileSystemInterface instance for the |profile_id|, or NULL
37 // if the Profile for |profile_id| is destructed or Drive File System is
38 // disabled for the profile.
39 // Note: |profile_id| should be the pointer of the Profile instance if it is
40 // alive. Considering timing issues due to task posting across threads,
41 // this function can accept a dangling pointer as |profile_id| (and will return
42 // NULL for such a case).
43 // This function must be called on UI thread.
44 FileSystemInterface* GetFileSystemByProfileId(void* profile_id);
46 // Returns the DriveAppRegistry for the |profile|. If not available (not
47 // mounted or disabled), returns NULL.
48 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile);
50 // Returns the DriveService for the |profile|. If not available (not mounted
51 // or disabled), returns NULL.
52 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile);
54 // Extracts |profile| from the given paths located under
55 // GetDriveMountPointPath(profile). Returns NULL if it does not correspond to
56 // a valid mount point path. Must be called from UI thread.
57 Profile* ExtractProfileFromPath(const base::FilePath& path);
59 // Extracts the Drive path (e.g., "drive/foo.txt") from the filesystem URL.
60 // Returns an empty path if |url| does not point under Drive mount point.
61 base::FilePath ExtractDrivePathFromFileSystemUrl(
62 const storage::FileSystemURL& url);
64 // Gets the cache root path (i.e. <user_profile_dir>/GCache/v1) from the
65 // profile.
66 base::FilePath GetCacheRootPath(Profile* profile);
68 // Callback type for PrepareWritableFileAndRun.
69 typedef base::Callback<void(FileError, const base::FilePath& path)>
70 PrepareWritableFileCallback;
72 // Invokes |callback| on blocking thread pool, after converting virtual |path|
73 // string like "/special/drive/foo.txt" to the concrete local cache file path.
74 // After |callback| returns, the written content is synchronized to the server.
76 // The |path| must be a path under Drive. Must be called from UI thread.
77 void PrepareWritableFileAndRun(Profile* profile,
78 const base::FilePath& path,
79 const PrepareWritableFileCallback& callback);
81 // Ensures the existence of |directory| of '/special/drive/foo'. This will
82 // create |directory| and its ancestors if they don't exist. |callback| is
83 // invoked after making sure that |directory| exists. |callback| should
84 // interpret error codes of either FILE_ERROR_OK or FILE_ERROR_EXISTS as
85 // indicating that |directory| now exists.
87 // If |directory| is not a Drive path, it won't check the existence and just
88 // runs |callback|.
90 // Must be called from UI thread.
91 void EnsureDirectoryExists(Profile* profile,
92 const base::FilePath& directory,
93 const FileOperationCallback& callback);
95 // Returns true if Drive is enabled for the given Profile.
96 bool IsDriveEnabledForProfile(Profile* profile);
98 // Enum type for describing the current connection status to Drive.
99 enum ConnectionStatusType {
100 // Disconnected because Drive service is unavailable for this account (either
101 // disabled by a flag or the account has no Google account (e.g., guests)).
102 DRIVE_DISCONNECTED_NOSERVICE,
103 // Disconnected because no network is available.
104 DRIVE_DISCONNECTED_NONETWORK,
105 // Disconnected because authentication is not ready.
106 DRIVE_DISCONNECTED_NOTREADY,
107 // Connected by cellular network. Background sync is disabled.
108 DRIVE_CONNECTED_METERED,
109 // Connected without condition (WiFi, Ethernet, or cellular with the
110 // disable-sync preference turned off.)
111 DRIVE_CONNECTED,
114 // Returns the Drive connection status for the |profile|.
115 ConnectionStatusType GetDriveConnectionStatus(Profile* profile);
117 } // namespace util
118 } // namespace drive
120 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_UTIL_H_