Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / file_manager / private_api_drive.h
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 "base/files/file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/chromeos/drive/file_system_interface.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
15 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
16
17 namespace drive {
18 class FileCacheEntry;
19 class ResourceEntry;
20 struct SearchResultInfo;
21 }
22
23 namespace google_apis {
24 class AuthService;
25 }
26
27 namespace extensions {
28
29 namespace api {
30 namespace file_manager_private {
31 struct EntryProperties;
32 }  // namespace file_manager_private
33 }  // namespace api
34
35 // Retrieves property information for an entry and returns it as a dictionary.
36 // On error, returns a dictionary with the key "error" set to the error number
37 // (base::File::Error).
38 class FileManagerPrivateGetEntryPropertiesFunction
39     : public LoggedAsyncExtensionFunction {
40  public:
41   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getEntryProperties",
42                              FILEMANAGERPRIVATE_GETENTRYPROPERTIES)
43
44   FileManagerPrivateGetEntryPropertiesFunction();
45
46  protected:
47   virtual ~FileManagerPrivateGetEntryPropertiesFunction();
48
49   // AsyncExtensionFunction overrides.
50   virtual bool RunAsync() OVERRIDE;
51
52  private:
53   void CompleteGetEntryProperties(
54       size_t index,
55       scoped_ptr<api::file_manager_private::EntryProperties> properties,
56       base::File::Error error);
57
58   size_t processed_count_;
59   std::vector<linked_ptr<api::file_manager_private::EntryProperties> >
60       properties_list_;
61 };
62
63 // Implements the chrome.fileManagerPrivate.pinDriveFile method.
64 class FileManagerPrivatePinDriveFileFunction
65     : public LoggedAsyncExtensionFunction {
66  public:
67   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.pinDriveFile",
68                              FILEMANAGERPRIVATE_PINDRIVEFILE)
69
70  protected:
71   virtual ~FileManagerPrivatePinDriveFileFunction() {}
72
73   // AsyncExtensionFunction overrides.
74   virtual bool RunAsync() OVERRIDE;
75
76  private:
77   // Callback for RunAsync().
78   void OnPinStateSet(drive::FileError error);
79 };
80
81 // Implements the chrome.fileManagerPrivate.cancelFileTransfers method.
82 class FileManagerPrivateCancelFileTransfersFunction
83     : public LoggedAsyncExtensionFunction {
84  public:
85   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.cancelFileTransfers",
86                              FILEMANAGERPRIVATE_CANCELFILETRANSFERS)
87
88  protected:
89   virtual ~FileManagerPrivateCancelFileTransfersFunction() {}
90
91   // AsyncExtensionFunction overrides.
92   virtual bool RunAsync() OVERRIDE;
93 };
94
95 class FileManagerPrivateSearchDriveFunction
96     : public LoggedAsyncExtensionFunction {
97  public:
98   typedef std::vector<drive::SearchResultInfo> SearchResultInfoList;
99
100   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDrive",
101                              FILEMANAGERPRIVATE_SEARCHDRIVE)
102
103  protected:
104   virtual ~FileManagerPrivateSearchDriveFunction() {}
105
106   virtual bool RunAsync() OVERRIDE;
107
108  private:
109   // Callback for Search().
110   void OnSearch(drive::FileError error,
111                 const GURL& next_link,
112                 scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
113
114   // Called when |result_paths| in OnSearch() are converted to a list of
115   // entry definitions.
116   void OnEntryDefinitionList(
117       const GURL& next_link,
118       scoped_ptr<SearchResultInfoList> search_result_info_list,
119       scoped_ptr<file_manager::util::EntryDefinitionList>
120           entry_definition_list);
121 };
122
123 // Similar to FileManagerPrivateSearchDriveFunction but this one is used for
124 // searching drive metadata which is stored locally.
125 class FileManagerPrivateSearchDriveMetadataFunction
126     : public LoggedAsyncExtensionFunction {
127  public:
128   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.searchDriveMetadata",
129                              FILEMANAGERPRIVATE_SEARCHDRIVEMETADATA)
130
131  protected:
132   virtual ~FileManagerPrivateSearchDriveMetadataFunction() {}
133
134   virtual bool RunAsync() OVERRIDE;
135
136  private:
137   // Callback for SearchMetadata();
138   void OnSearchMetadata(drive::FileError error,
139                         scoped_ptr<drive::MetadataSearchResultVector> results);
140
141   // Called when |results| in OnSearchMetadata() are converted to a list of
142   // entry definitions.
143   void OnEntryDefinitionList(
144       scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
145       scoped_ptr<file_manager::util::EntryDefinitionList>
146           entry_definition_list);
147 };
148
149 // Implements the chrome.fileManagerPrivate.getDriveConnectionState method.
150 class FileManagerPrivateGetDriveConnectionStateFunction
151     : public ChromeSyncExtensionFunction {
152  public:
153   DECLARE_EXTENSION_FUNCTION(
154       "fileManagerPrivate.getDriveConnectionState",
155       FILEMANAGERPRIVATE_GETDRIVECONNECTIONSTATE);
156
157  protected:
158   virtual ~FileManagerPrivateGetDriveConnectionStateFunction() {}
159
160   virtual bool RunSync() OVERRIDE;
161 };
162
163 // Implements the chrome.fileManagerPrivate.requestAccessToken method.
164 class FileManagerPrivateRequestAccessTokenFunction
165     : public LoggedAsyncExtensionFunction {
166  public:
167   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestAccessToken",
168                              FILEMANAGERPRIVATE_REQUESTACCESSTOKEN)
169
170  protected:
171   virtual ~FileManagerPrivateRequestAccessTokenFunction() {}
172
173   // AsyncExtensionFunction overrides.
174   virtual bool RunAsync() OVERRIDE;
175
176   // Callback with a cached auth token (if available) or a fetched one.
177   void OnAccessTokenFetched(google_apis::GDataErrorCode code,
178                             const std::string& access_token);
179 };
180
181 // Implements the chrome.fileManagerPrivate.getShareUrl method.
182 class FileManagerPrivateGetShareUrlFunction
183     : public LoggedAsyncExtensionFunction {
184  public:
185   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getShareUrl",
186                              FILEMANAGERPRIVATE_GETSHAREURL)
187
188  protected:
189   virtual ~FileManagerPrivateGetShareUrlFunction() {}
190
191   // AsyncExtensionFunction overrides.
192   virtual bool RunAsync() OVERRIDE;
193
194   // Callback with an url to the sharing dialog as |share_url|, called by
195   // FileSystem::GetShareUrl.
196   void OnGetShareUrl(drive::FileError error, const GURL& share_url);
197 };
198
199 // Implements the chrome.fileManagerPrivate.requestDriveShare method.
200 class FileManagerPrivateRequestDriveShareFunction
201     : public LoggedAsyncExtensionFunction {
202  public:
203   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.requestDriveShare",
204                              FILEMANAGERPRIVATE_REQUESTDRIVESHARE);
205
206  protected:
207   virtual ~FileManagerPrivateRequestDriveShareFunction() {}
208   virtual bool RunAsync() OVERRIDE;
209
210  private:
211   // Called back after the drive file system operation is finished.
212   void OnAddPermission(drive::FileError error);
213 };
214
215 // Implements the chrome.fileManagerPrivate.getDownloadUrl method.
216 class FileManagerPrivateGetDownloadUrlFunction
217     : public LoggedAsyncExtensionFunction {
218  public:
219   FileManagerPrivateGetDownloadUrlFunction();
220
221   DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getDownloadUrl",
222                              FILEMANAGERPRIVATE_GETDOWNLOADURL)
223
224  protected:
225   virtual ~FileManagerPrivateGetDownloadUrlFunction();
226
227   // AsyncExtensionFunction overrides.
228   virtual bool RunAsync() OVERRIDE;
229
230   void OnGetResourceEntry(drive::FileError error,
231                           scoped_ptr<drive::ResourceEntry> entry);
232
233   // Callback with an |access_token|, called by
234   // drive::DriveReadonlyTokenFetcher.
235   void OnTokenFetched(google_apis::GDataErrorCode code,
236                       const std::string& access_token);
237
238  private:
239   std::string download_url_;
240   scoped_ptr<google_apis::AuthService> auth_service_;
241 };
242
243 }  // namespace extensions
244
245 #endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_