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. 4 // 5 // This file provides Drive specific API functions. 6 7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 9 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" 14 15 namespace drive { 16 class FileCacheEntry; 17 class ResourceEntry; 18 struct SearchResultInfo; 19 } 20 21 namespace extensions { 22 23 namespace api { 24 namespace file_browser_private { 25 struct DriveEntryProperties; 26 } // namespace file_browser_private 27 } // namespace api 28 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 { 34 public: 35 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties", 36 FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES) 37 38 FileBrowserPrivateGetDriveEntryPropertiesFunction(); 39 40 protected: 41 virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction(); 42 43 // AsyncExtensionFunction overrides. 44 virtual bool RunAsync() OVERRIDE; 45 46 private: 47 void CompleteGetFileProperties(drive::FileError error); 48 49 size_t processed_count_; 50 std::vector<linked_ptr<api::file_browser_private::DriveEntryProperties> > 51 properties_list_; 52 }; 53 54 // Implements the chrome.fileBrowserPrivate.pinDriveFile method. 55 class FileBrowserPrivatePinDriveFileFunction 56 : public LoggedAsyncExtensionFunction { 57 public: 58 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile", 59 FILEBROWSERPRIVATE_PINDRIVEFILE) 60 61 protected: 62 virtual ~FileBrowserPrivatePinDriveFileFunction() {} 63 64 // AsyncExtensionFunction overrides. 65 virtual bool RunAsync() OVERRIDE; 66 67 private: 68 // Callback for RunAsync(). 69 void OnPinStateSet(drive::FileError error); 70 }; 71 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 { 82 public: 83 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles", 84 FILEBROWSERPRIVATE_GETDRIVEFILES) 85 86 FileBrowserPrivateGetDriveFilesFunction(); 87 88 protected: 89 virtual ~FileBrowserPrivateGetDriveFilesFunction(); 90 91 // AsyncExtensionFunction overrides. 92 virtual bool RunAsync() OVERRIDE; 93 94 private: 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(); 98 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); 104 105 std::queue<base::FilePath> remaining_drive_paths_; 106 std::vector<std::string> local_paths_; 107 }; 108 109 // Implements the chrome.fileBrowserPrivate.cancelFileTransfers method. 110 class FileBrowserPrivateCancelFileTransfersFunction 111 : public LoggedAsyncExtensionFunction { 112 public: 113 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers", 114 FILEBROWSERPRIVATE_CANCELFILETRANSFERS) 115 116 protected: 117 virtual ~FileBrowserPrivateCancelFileTransfersFunction() {} 118 119 // AsyncExtensionFunction overrides. 120 virtual bool RunAsync() OVERRIDE; 121 }; 122 123 class FileBrowserPrivateSearchDriveFunction 124 : public LoggedAsyncExtensionFunction { 125 public: 126 typedef std::vector<drive::SearchResultInfo> SearchResultInfoList; 127 128 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive", 129 FILEBROWSERPRIVATE_SEARCHDRIVE) 130 131 protected: 132 virtual ~FileBrowserPrivateSearchDriveFunction() {} 133 134 virtual bool RunAsync() OVERRIDE; 135 136 private: 137 // Callback for Search(). 138 void OnSearch(drive::FileError error, 139 const GURL& next_link, 140 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths); 141 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); 149 }; 150 151 // Similar to FileBrowserPrivateSearchDriveFunction but this one is used for 152 // searching drive metadata which is stored locally. 153 class FileBrowserPrivateSearchDriveMetadataFunction 154 : public LoggedAsyncExtensionFunction { 155 public: 156 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDriveMetadata", 157 FILEBROWSERPRIVATE_SEARCHDRIVEMETADATA) 158 159 protected: 160 virtual ~FileBrowserPrivateSearchDriveMetadataFunction() {} 161 162 virtual bool RunAsync() OVERRIDE; 163 164 private: 165 // Callback for SearchMetadata(); 166 void OnSearchMetadata(drive::FileError error, 167 scoped_ptr<drive::MetadataSearchResultVector> results); 168 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); 175 }; 176 177 // Implements the chrome.fileBrowserPrivate.getDriveConnectionState method. 178 class FileBrowserPrivateGetDriveConnectionStateFunction 179 : public ChromeSyncExtensionFunction { 180 public: 181 DECLARE_EXTENSION_FUNCTION( 182 "fileBrowserPrivate.getDriveConnectionState", 183 FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE); 184 185 protected: 186 virtual ~FileBrowserPrivateGetDriveConnectionStateFunction() {} 187 188 virtual bool RunSync() OVERRIDE; 189 }; 190 191 // Implements the chrome.fileBrowserPrivate.requestAccessToken method. 192 class FileBrowserPrivateRequestAccessTokenFunction 193 : public LoggedAsyncExtensionFunction { 194 public: 195 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken", 196 FILEBROWSERPRIVATE_REQUESTACCESSTOKEN) 197 198 protected: 199 virtual ~FileBrowserPrivateRequestAccessTokenFunction() {} 200 201 // AsyncExtensionFunction overrides. 202 virtual bool RunAsync() OVERRIDE; 203 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); 207 }; 208 209 // Implements the chrome.fileBrowserPrivate.getShareUrl method. 210 class FileBrowserPrivateGetShareUrlFunction 211 : public LoggedAsyncExtensionFunction { 212 public: 213 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl", 214 FILEBROWSERPRIVATE_GETSHAREURL) 215 216 protected: 217 virtual ~FileBrowserPrivateGetShareUrlFunction() {} 218 219 // AsyncExtensionFunction overrides. 220 virtual bool RunAsync() OVERRIDE; 221 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); 225 }; 226 227 // Implements the chrome.fileBrowserPrivate.requestDriveShare method. 228 class FileBrowserPrivateRequestDriveShareFunction 229 : public LoggedAsyncExtensionFunction { 230 public: 231 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestDriveShare", 232 FILEBROWSERPRIVATE_REQUESTDRIVESHARE); 233 234 protected: 235 virtual ~FileBrowserPrivateRequestDriveShareFunction() {} 236 virtual bool RunAsync() OVERRIDE; 237 238 private: 239 // Called back after the drive file system operation is finished. 240 void OnAddPermission(drive::FileError error); 241 }; 242 243 } // namespace extensions 244 245 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 246