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"
13 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
18 struct SearchResultInfo;
21 namespace extensions {
24 namespace file_browser_private {
25 struct DriveEntryProperties;
26 } // namespace file_browser_private
29 // Retrieves property information for an entry and returns it as a dictionary.
30 // On error, returns a dictionary with the key "error" set to the error number
31 // (drive::FileError).
32 class FileBrowserPrivateGetDriveEntryPropertiesFunction
33 : public LoggedAsyncExtensionFunction {
35 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties",
36 FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES)
38 FileBrowserPrivateGetDriveEntryPropertiesFunction();
41 virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction();
43 // AsyncExtensionFunction overrides.
44 virtual bool RunAsync() OVERRIDE;
47 void CompleteGetFileProperties(drive::FileError error);
49 size_t processed_count_;
50 std::vector<linked_ptr<api::file_browser_private::DriveEntryProperties> >
54 // Implements the chrome.fileBrowserPrivate.pinDriveFile method.
55 class FileBrowserPrivatePinDriveFileFunction
56 : public LoggedAsyncExtensionFunction {
58 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile",
59 FILEBROWSERPRIVATE_PINDRIVEFILE)
62 virtual ~FileBrowserPrivatePinDriveFileFunction() {}
64 // AsyncExtensionFunction overrides.
65 virtual bool RunAsync() OVERRIDE;
68 // Callback for RunAsync().
69 void OnPinStateSet(drive::FileError error);
72 // Get drive files for the given list of file URLs. Initiate downloading of
73 // drive files if these are not cached. Return a list of local file names.
74 // This function puts empty strings instead of local paths for files could
75 // not be obtained. For instance, this can happen if the user specifies a new
76 // file name to save a file on drive. There may be other reasons to fail. The
77 // file manager should check if the local paths returned from getDriveFiles()
78 // contain empty paths.
79 // TODO(satorux): Should we propagate error types to the JavaScript layer?
80 class FileBrowserPrivateGetDriveFilesFunction
81 : public LoggedAsyncExtensionFunction {
83 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles",
84 FILEBROWSERPRIVATE_GETDRIVEFILES)
86 FileBrowserPrivateGetDriveFilesFunction();
89 virtual ~FileBrowserPrivateGetDriveFilesFunction();
91 // AsyncExtensionFunction overrides.
92 virtual bool RunAsync() OVERRIDE;
95 // Gets the file on the top of the |remaining_drive_paths_| or sends the
96 // response if the queue is empty.
97 void GetFileOrSendResponse();
99 // Called by FileSystem::GetFile(). Pops the file from
100 // |remaining_drive_paths_|, and calls GetFileOrSendResponse().
101 void OnFileReady(drive::FileError error,
102 const base::FilePath& local_path,
103 scoped_ptr<drive::ResourceEntry> entry);
105 std::queue<base::FilePath> remaining_drive_paths_;
106 std::vector<std::string> local_paths_;
109 // Implements the chrome.fileBrowserPrivate.cancelFileTransfers method.
110 class FileBrowserPrivateCancelFileTransfersFunction
111 : public LoggedAsyncExtensionFunction {
113 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers",
114 FILEBROWSERPRIVATE_CANCELFILETRANSFERS)
117 virtual ~FileBrowserPrivateCancelFileTransfersFunction() {}
119 // AsyncExtensionFunction overrides.
120 virtual bool RunAsync() OVERRIDE;
123 class FileBrowserPrivateSearchDriveFunction
124 : public LoggedAsyncExtensionFunction {
126 typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
128 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive",
129 FILEBROWSERPRIVATE_SEARCHDRIVE)
132 virtual ~FileBrowserPrivateSearchDriveFunction() {}
134 virtual bool RunAsync() OVERRIDE;
137 // Callback for Search().
138 void OnSearch(drive::FileError error,
139 const GURL& next_link,
140 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
142 // Called when |result_paths| in OnSearch() are converted to a list of
143 // entry definitions.
144 void OnEntryDefinitionList(
145 const GURL& next_link,
146 scoped_ptr<SearchResultInfoList> search_result_info_list,
147 scoped_ptr<file_manager::util::EntryDefinitionList>
148 entry_definition_list);
151 // Similar to FileBrowserPrivateSearchDriveFunction but this one is used for
152 // searching drive metadata which is stored locally.
153 class FileBrowserPrivateSearchDriveMetadataFunction
154 : public LoggedAsyncExtensionFunction {
156 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDriveMetadata",
157 FILEBROWSERPRIVATE_SEARCHDRIVEMETADATA)
160 virtual ~FileBrowserPrivateSearchDriveMetadataFunction() {}
162 virtual bool RunAsync() OVERRIDE;
165 // Callback for SearchMetadata();
166 void OnSearchMetadata(drive::FileError error,
167 scoped_ptr<drive::MetadataSearchResultVector> results);
169 // Called when |results| in OnSearchMetadata() are converted to a list of
170 // entry definitions.
171 void OnEntryDefinitionList(
172 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
173 scoped_ptr<file_manager::util::EntryDefinitionList>
174 entry_definition_list);
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 RunSync() 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 RunAsync() 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 RunAsync() 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 // Implements the chrome.fileBrowserPrivate.requestDriveShare method.
228 class FileBrowserPrivateRequestDriveShareFunction
229 : public LoggedAsyncExtensionFunction {
231 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestDriveShare",
232 FILEBROWSERPRIVATE_REQUESTDRIVESHARE);
235 virtual ~FileBrowserPrivateRequestDriveShareFunction() {}
236 virtual bool RunAsync() OVERRIDE;
239 // Called back after the drive file system operation is finished.
240 void OnAddPermission(drive::FileError error);
243 } // namespace extensions
245 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_