private_api_drive.h revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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 15namespace drive { 16class FileCacheEntry; 17class ResourceEntry; 18struct SearchResultInfo; 19} 20 21namespace extensions { 22 23namespace api { 24namespace file_browser_private { 25struct 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). 32class 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 RunImpl() OVERRIDE; 45 46 private: 47 void OnGetFileInfo(drive::FileError error, 48 scoped_ptr<drive::ResourceEntry> entry); 49 50 void CacheStateReceived(bool success, 51 const drive::FileCacheEntry& cache_entry); 52 53 void CompleteGetFileProperties(drive::FileError error); 54 55 base::FilePath file_path_; 56 Profile* file_owner_profile_; 57 const scoped_ptr<extensions::api::file_browser_private::DriveEntryProperties> 58 properties_; 59}; 60 61// Implements the chrome.fileBrowserPrivate.pinDriveFile method. 62class FileBrowserPrivatePinDriveFileFunction 63 : public LoggedAsyncExtensionFunction { 64 public: 65 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.pinDriveFile", 66 FILEBROWSERPRIVATE_PINDRIVEFILE) 67 68 protected: 69 virtual ~FileBrowserPrivatePinDriveFileFunction() {} 70 71 // AsyncExtensionFunction overrides. 72 virtual bool RunImpl() OVERRIDE; 73 74 private: 75 // Callback for RunImpl(). 76 void OnPinStateSet(drive::FileError error); 77}; 78 79// Get drive files for the given list of file URLs. Initiate downloading of 80// drive files if these are not cached. Return a list of local file names. 81// This function puts empty strings instead of local paths for files could 82// not be obtained. For instance, this can happen if the user specifies a new 83// file name to save a file on drive. There may be other reasons to fail. The 84// file manager should check if the local paths returned from getDriveFiles() 85// contain empty paths. 86// TODO(satorux): Should we propagate error types to the JavaScript layer? 87class FileBrowserPrivateGetDriveFilesFunction 88 : public LoggedAsyncExtensionFunction { 89 public: 90 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveFiles", 91 FILEBROWSERPRIVATE_GETDRIVEFILES) 92 93 FileBrowserPrivateGetDriveFilesFunction(); 94 95 protected: 96 virtual ~FileBrowserPrivateGetDriveFilesFunction(); 97 98 // AsyncExtensionFunction overrides. 99 virtual bool RunImpl() OVERRIDE; 100 101 private: 102 // Gets the file on the top of the |remaining_drive_paths_| or sends the 103 // response if the queue is empty. 104 void GetFileOrSendResponse(); 105 106 // Called by FileSystem::GetFile(). Pops the file from 107 // |remaining_drive_paths_|, and calls GetFileOrSendResponse(). 108 void OnFileReady(drive::FileError error, 109 const base::FilePath& local_path, 110 scoped_ptr<drive::ResourceEntry> entry); 111 112 std::queue<base::FilePath> remaining_drive_paths_; 113 std::vector<std::string> local_paths_; 114}; 115 116// Implements the chrome.fileBrowserPrivate.cancelFileTransfers method. 117class FileBrowserPrivateCancelFileTransfersFunction 118 : public LoggedAsyncExtensionFunction { 119 public: 120 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.cancelFileTransfers", 121 FILEBROWSERPRIVATE_CANCELFILETRANSFERS) 122 123 protected: 124 virtual ~FileBrowserPrivateCancelFileTransfersFunction() {} 125 126 // AsyncExtensionFunction overrides. 127 virtual bool RunImpl() OVERRIDE; 128}; 129 130class FileBrowserPrivateSearchDriveFunction 131 : public LoggedAsyncExtensionFunction { 132 public: 133 typedef std::vector<drive::SearchResultInfo> SearchResultInfoList; 134 135 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDrive", 136 FILEBROWSERPRIVATE_SEARCHDRIVE) 137 138 protected: 139 virtual ~FileBrowserPrivateSearchDriveFunction() {} 140 141 virtual bool RunImpl() OVERRIDE; 142 143 private: 144 // Callback for Search(). 145 void OnSearch(drive::FileError error, 146 const GURL& next_link, 147 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths); 148 149 // Called when |result_paths| in OnSearch() are converted to a list of 150 // entry definitions. 151 void OnEntryDefinitionList( 152 const GURL& next_link, 153 scoped_ptr<SearchResultInfoList> search_result_info_list, 154 scoped_ptr<file_manager::util::EntryDefinitionList> 155 entry_definition_list); 156}; 157 158// Similar to FileBrowserPrivateSearchDriveFunction but this one is used for 159// searching drive metadata which is stored locally. 160class FileBrowserPrivateSearchDriveMetadataFunction 161 : public LoggedAsyncExtensionFunction { 162 public: 163 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.searchDriveMetadata", 164 FILEBROWSERPRIVATE_SEARCHDRIVEMETADATA) 165 166 protected: 167 virtual ~FileBrowserPrivateSearchDriveMetadataFunction() {} 168 169 virtual bool RunImpl() OVERRIDE; 170 171 private: 172 // Callback for SearchMetadata(); 173 void OnSearchMetadata(drive::FileError error, 174 scoped_ptr<drive::MetadataSearchResultVector> results); 175 176 // Called when |results| in OnSearchMetadata() are converted to a list of 177 // entry definitions. 178 void OnEntryDefinitionList( 179 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list, 180 scoped_ptr<file_manager::util::EntryDefinitionList> 181 entry_definition_list); 182}; 183 184// Implements the chrome.fileBrowserPrivate.getDriveConnectionState method. 185class FileBrowserPrivateGetDriveConnectionStateFunction 186 : public ChromeSyncExtensionFunction { 187 public: 188 DECLARE_EXTENSION_FUNCTION( 189 "fileBrowserPrivate.getDriveConnectionState", 190 FILEBROWSERPRIVATE_GETDRIVECONNECTIONSTATE); 191 192 protected: 193 virtual ~FileBrowserPrivateGetDriveConnectionStateFunction() {} 194 195 virtual bool RunImpl() OVERRIDE; 196}; 197 198// Implements the chrome.fileBrowserPrivate.requestAccessToken method. 199class FileBrowserPrivateRequestAccessTokenFunction 200 : public LoggedAsyncExtensionFunction { 201 public: 202 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestAccessToken", 203 FILEBROWSERPRIVATE_REQUESTACCESSTOKEN) 204 205 protected: 206 virtual ~FileBrowserPrivateRequestAccessTokenFunction() {} 207 208 // AsyncExtensionFunction overrides. 209 virtual bool RunImpl() OVERRIDE; 210 211 // Callback with a cached auth token (if available) or a fetched one. 212 void OnAccessTokenFetched(google_apis::GDataErrorCode code, 213 const std::string& access_token); 214}; 215 216// Implements the chrome.fileBrowserPrivate.getShareUrl method. 217class FileBrowserPrivateGetShareUrlFunction 218 : public LoggedAsyncExtensionFunction { 219 public: 220 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getShareUrl", 221 FILEBROWSERPRIVATE_GETSHAREURL) 222 223 protected: 224 virtual ~FileBrowserPrivateGetShareUrlFunction() {} 225 226 // AsyncExtensionFunction overrides. 227 virtual bool RunImpl() OVERRIDE; 228 229 // Callback with an url to the sharing dialog as |share_url|, called by 230 // FileSystem::GetShareUrl. 231 void OnGetShareUrl(drive::FileError error, const GURL& share_url); 232}; 233 234// Implements the chrome.fileBrowserPrivate.requestDriveShare method. 235class FileBrowserPrivateRequestDriveShareFunction 236 : public LoggedAsyncExtensionFunction { 237 public: 238 DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestDriveShare", 239 FILEBROWSERPRIVATE_REQUESTDRIVESHARE); 240 241 protected: 242 virtual ~FileBrowserPrivateRequestDriveShareFunction() {} 243 virtual bool RunImpl() OVERRIDE; 244 245 private: 246 // Called back after the drive file system operation is finished. 247 void OnAddPermission(drive::FileError error); 248}; 249 250} // namespace extensions 251 252#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_ 253