1 // Copyright 2013 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 // This file provides Drive specific API functions.
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
10 #include "chrome/browser/chromeos/drive/file_errors.h"
11 #include "chrome/browser/chromeos/drive/file_system_interface.h"
12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
18 struct SearchResultInfo;
21 namespace extensions {
23 namespace file_browser_private{
24 struct DriveEntryProperties;
28 // Retrieves property information for an entry and returns it as a dictionary.
29 // On error, returns a dictionary with the key "error" set to the error number
30 // (drive::FileError).
31 class FileBrowserPrivateGetDriveEntryPropertiesFunction
32 : public LoggedAsyncExtensionFunction {
34 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties",
35 FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES)
37 FileBrowserPrivateGetDriveEntryPropertiesFunction();
40 virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction();
42 // AsyncExtensionFunction overrides.
43 virtual bool RunImpl() OVERRIDE;
46 void OnGetFileInfo(drive::FileError error,
47 scoped_ptr<drive::ResourceEntry> entry);
49 void CacheStateReceived(bool success,
50 const drive::FileCacheEntry& cache_entry);
52 void CompleteGetFileProperties(drive::FileError error);
54 base::FilePath file_path_;
55 scoped_ptr<extensions::api::file_browser_private::
56 DriveEntryProperties> properties_;
59 // Implements the chrome.fileBrowserPrivate.pinDriveFile method.
60 class FileBrowserPrivatePinDriveFileFunction
61 : public LoggedAsyncExtensionFunction {
63 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile",
64 FILEBROWSERPRIVATE_PINDRIVEFILE)
67 virtual ~FileBrowserPrivatePinDriveFileFunction() {}
69 // AsyncExtensionFunction overrides.
70 virtual bool RunImpl() OVERRIDE;
73 // Callback for RunImpl().
74 void OnPinStateSet(drive::FileError error);
77 // Get drive files for the given list of file URLs. Initiate downloading of
78 // drive files if these are not cached. Return a list of local file names.
79 // This function puts empty strings instead of local paths for files could
80 // not be obtained. For instance, this can happen if the user specifies a new
81 // file name to save a file on drive. There may be other reasons to fail. The
82 // file manager should check if the local paths returned from getDriveFiles()
83 // contain empty paths.
84 // TODO(satorux): Should we propagate error types to the JavaScript layer?
85 class FileBrowserPrivateGetDriveFilesFunction
86 : public LoggedAsyncExtensionFunction {
88 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles",
89 FILEBROWSERPRIVATE_GETDRIVEFILES)
91 FileBrowserPrivateGetDriveFilesFunction();
94 virtual ~FileBrowserPrivateGetDriveFilesFunction();
96 // AsyncExtensionFunction overrides.
97 virtual bool RunImpl() OVERRIDE;
100 // Gets the file on the top of the |remaining_drive_paths_| or sends the
101 // response if the queue is empty.
102 void GetFileOrSendResponse();
104 // Called by FileSystem::GetFile(). Pops the file from
105 // |remaining_drive_paths_|, and calls GetFileOrSendResponse().
106 void OnFileReady(drive::FileError error,
107 const base::FilePath& local_path,
108 scoped_ptr<drive::ResourceEntry> entry);
110 std::queue<base::FilePath> remaining_drive_paths_;
111 std::vector<std::string> local_paths_;
114 // Implements the chrome.fileBrowserPrivate.cancelFileTransfers method.
115 class FileBrowserPrivateCancelFileTransfersFunction
116 : public LoggedAsyncExtensionFunction {
118 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers",
119 FILEBROWSERPRIVATE_CANCELFILETRANSFERS)
122 virtual ~FileBrowserPrivateCancelFileTransfersFunction() {}
124 // AsyncExtensionFunction overrides.
125 virtual bool RunImpl() OVERRIDE;
128 class FileBrowserPrivateSearchDriveFunction
129 : public LoggedAsyncExtensionFunction {
131 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive",
132 FILEBROWSERPRIVATE_SEARCHDRIVE)
135 virtual ~FileBrowserPrivateSearchDriveFunction() {}
137 virtual bool RunImpl() OVERRIDE;
140 // Callback for Search().
141 void OnSearch(drive::FileError error,
142 const GURL& next_link,
143 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
146 // Similar to FileBrowserPrivateSearchDriveFunction but this one is used for
147 // searching drive metadata which is stored locally.
148 class FileBrowserPrivateSearchDriveMetadataFunction
149 : public LoggedAsyncExtensionFunction {
151 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDriveMetadata",
152 FILEBROWSERPRIVATE_SEARCHDRIVEMETADATA)
155 virtual ~FileBrowserPrivateSearchDriveMetadataFunction() {}
157 virtual bool RunImpl() OVERRIDE;
160 // Callback for SearchMetadata();
161 void OnSearchMetadata(drive::FileError error,
162 scoped_ptr<drive::MetadataSearchResultVector> results);
165 class FileBrowserPrivateClearDriveCacheFunction
166 : public LoggedAsyncExtensionFunction {
168 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.clearDriveCache",
169 FILEBROWSERPRIVATE_CLEARDRIVECACHE)
172 virtual ~FileBrowserPrivateClearDriveCacheFunction() {}
174 virtual bool RunImpl() OVERRIDE;
177 // Implements the chrome.fileBrowserPrivate.getDriveConnectionState method.
178 class FileBrowserPrivateGetDriveConnectionStateFunction
179 : public ChromeSyncExtensionFunction {
181 DECLARE_EXTENSION_FUNCTION(
182 "fileBrowserPrivate.getDriveConnectionState",
183 FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE);
186 virtual ~FileBrowserPrivateGetDriveConnectionStateFunction() {}
188 virtual bool RunImpl() OVERRIDE;
191 // Implements the chrome.fileBrowserPrivate.requestAccessToken method.
192 class FileBrowserPrivateRequestAccessTokenFunction
193 : public LoggedAsyncExtensionFunction {
195 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken",
196 FILEBROWSERPRIVATE_REQUESTACCESSTOKEN)
199 virtual ~FileBrowserPrivateRequestAccessTokenFunction() {}
201 // AsyncExtensionFunction overrides.
202 virtual bool RunImpl() OVERRIDE;
204 // Callback with a cached auth token (if available) or a fetched one.
205 void OnAccessTokenFetched(google_apis::GDataErrorCode code,
206 const std::string& access_token);
209 // Implements the chrome.fileBrowserPrivate.getShareUrl method.
210 class FileBrowserPrivateGetShareUrlFunction
211 : public LoggedAsyncExtensionFunction {
213 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl",
214 FILEBROWSERPRIVATE_GETSHAREURL)
217 virtual ~FileBrowserPrivateGetShareUrlFunction() {}
219 // AsyncExtensionFunction overrides.
220 virtual bool RunImpl() OVERRIDE;
222 // Callback with an url to the sharing dialog as |share_url|, called by
223 // FileSystem::GetShareUrl.
224 void OnGetShareUrl(drive::FileError error, const GURL& share_url);
227 } // namespace extensions
229 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_