OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
7 | 7 |
| 8 #include <sys/stat.h> |
| 9 |
8 #include <map> | 10 #include <map> |
9 #include <string> | 11 #include <string> |
10 #include <sys/stat.h> | |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "chrome/browser/chromeos/gdata/gdata.h" | 20 #include "chrome/browser/chromeos/gdata/gdata.h" |
20 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 // Finds file info by using virtual |file_path|. If |require_content| is set, | 119 // Finds file info by using virtual |file_path|. If |require_content| is set, |
119 // the found directory will be pre-populated before passed back to the | 120 // the found directory will be pre-populated before passed back to the |
120 // |delegate|. If |allow_refresh| is not set, directories' content | 121 // |delegate|. If |allow_refresh| is not set, directories' content |
121 // won't be performed. | 122 // won't be performed. |
122 // | 123 // |
123 // Can be called from any thread. | 124 // Can be called from any thread. |
124 void FindFileByPath(const FilePath& file_path, | 125 void FindFileByPath(const FilePath& file_path, |
125 scoped_refptr<FindFileDelegate> delegate); | 126 scoped_refptr<FindFileDelegate> delegate); |
126 | 127 |
| 128 // Copies |src_file_path| to |dest_file_path| on the file system. |
| 129 // |src_file_path| can be a hosted document (see limitations below). |
| 130 // |dest_file_path| is expected to be of the same type of |src_file_path| |
| 131 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as |
| 132 // a file). |
| 133 // |
| 134 // This method also has the following assumptions/limitations that may be |
| 135 // relaxed or addressed later: |
| 136 // - |src_file_path| cannot be a regular file (i.e. non-hosted document) |
| 137 // or a directory. |
| 138 // - |dest_file_path| must not exist. |
| 139 // - The parent of |dest_file_path| must already exist. |
| 140 // |
| 141 // The file entries represented by |src_file_path| and the parent directory |
| 142 // of |dest_file_path| need to be present in the in-memory representation |
| 143 // of the file system. |
| 144 // |
| 145 // Can be called from any thread. |
| 146 void Copy(const FilePath& src_file_path, |
| 147 const FilePath& dest_file_path, |
| 148 const FileOperationCallback& callback); |
| 149 |
| 150 // Moves |src_file_path| to |dest_file_path| on the file system. |
| 151 // |src_file_path| can be a file (regular or hosted document) or a directory. |
| 152 // |dest_file_path| is expected to be of the same type of |src_file_path| |
| 153 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as |
| 154 // a file). |
| 155 // |
| 156 // This method also has the following assumptions/limitations that may be |
| 157 // relaxed or addressed later: |
| 158 // - |dest_file_path| must not exist. |
| 159 // - The parent of |dest_file_path| must already exist. |
| 160 // |
| 161 // The file entries represented by |src_file_path| and the parent directory |
| 162 // of |dest_file_path| need to be present in the in-memory representation |
| 163 // of the file system. |
| 164 // |
| 165 // Can be called from any thread. |
| 166 void Move(const FilePath& src_file_path, |
| 167 const FilePath& dest_file_path, |
| 168 const FileOperationCallback& callback); |
| 169 |
127 // Removes |file_path| from the file system. If |is_recursive| is set and | 170 // Removes |file_path| from the file system. If |is_recursive| is set and |
128 // |file_path| represents a directory, we will also delete all of its | 171 // |file_path| represents a directory, we will also delete all of its |
129 // contained children elements. The file entry represented by |file_path| | 172 // contained children elements. The file entry represented by |file_path| |
130 // needs to be present in in-memory representation of the file system that | 173 // needs to be present in in-memory representation of the file system that |
131 // in order to be removed. | 174 // in order to be removed. |
132 // | 175 // |
133 // TODO(zelidrag): Wire |is_recursive| through gdata api | 176 // TODO(zelidrag): Wire |is_recursive| through gdata api |
134 // (find appropriate calls for it). | 177 // (find appropriate calls for it). |
135 // | 178 // |
136 // Can be called from any thread. |callback| is run on the calling thread. | 179 // Can be called from any thread. |callback| is run on the calling thread. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 private: | 221 private: |
179 friend class GDataUploader; | 222 friend class GDataUploader; |
180 friend class GDataFileSystemFactory; | 223 friend class GDataFileSystemFactory; |
181 friend class GDataFileSystemTestBase; | 224 friend class GDataFileSystemTestBase; |
182 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 225 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
183 FindFirstMissingParentDirectory); | 226 FindFirstMissingParentDirectory); |
184 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 227 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
185 GetGDataFileInfoFromPath); | 228 GetGDataFileInfoFromPath); |
186 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 229 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
187 GetFromCacheForPath); | 230 GetFromCacheForPath); |
| 231 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, GetCopyMoveFileParams); |
188 | 232 |
189 // Defines possible search results of FindFirstMissingParentDirectory(). | 233 // Defines possible search results of FindFirstMissingParentDirectory(). |
190 enum FindMissingDirectoryResult { | 234 enum FindMissingDirectoryResult { |
191 // Target directory found, it's not a directory. | 235 // Target directory found, it's not a directory. |
192 FOUND_INVALID, | 236 FOUND_INVALID, |
193 // Found missing directory segment while searching for given directory. | 237 // Found missing directory segment while searching for given directory. |
194 FOUND_MISSING, | 238 FOUND_MISSING, |
195 // Found target directory, it already exists. | 239 // Found target directory, it already exists. |
196 DIRECTORY_ALREADY_PRESENT, | 240 DIRECTORY_ALREADY_PRESENT, |
197 }; | 241 }; |
198 | 242 |
199 // Defines set of parameters passes to intermediate callbacks during | 243 // Defines set of parameters passes to intermediate callbacks during |
200 // execution of CreateDirectory() method. | 244 // execution of CreateDirectory() method. |
201 struct CreateDirectoryParams { | 245 struct CreateDirectoryParams { |
202 CreateDirectoryParams(const FilePath& created_directory_path, | 246 CreateDirectoryParams(const FilePath& created_directory_path, |
203 const FilePath& target_directory_path, | 247 const FilePath& target_directory_path, |
204 bool is_exclusive, | 248 bool is_exclusive, |
205 bool is_recursive, | 249 bool is_recursive, |
206 const FileOperationCallback& callback); | 250 const FileOperationCallback& callback); |
207 ~CreateDirectoryParams(); | 251 ~CreateDirectoryParams(); |
208 | 252 |
209 const FilePath created_directory_path; | 253 const FilePath created_directory_path; |
210 const FilePath target_directory_path; | 254 const FilePath target_directory_path; |
211 const bool is_exclusive; | 255 const bool is_exclusive; |
212 const bool is_recursive; | 256 const bool is_recursive; |
213 FileOperationCallback callback; | 257 FileOperationCallback callback; |
214 }; | 258 }; |
215 | 259 |
| 260 // Defines set of parameters of a file/directory that is needed for |
| 261 // copy/move related operations. |
| 262 struct CopyMoveFileParams { |
| 263 CopyMoveFileParams(); |
| 264 ~CopyMoveFileParams(); |
| 265 |
| 266 GURL self_url; |
| 267 GURL content_url; |
| 268 bool is_directory; |
| 269 bool is_root_directory; |
| 270 bool is_hosted_document; |
| 271 std::string resource_id; |
| 272 std::string document_extension; |
| 273 }; |
| 274 |
216 enum CacheType { // This indexes into |cache_paths_| vector. | 275 enum CacheType { // This indexes into |cache_paths_| vector. |
217 CACHE_TYPE_BLOBS = 0, | 276 CACHE_TYPE_BLOBS = 0, |
218 CACHE_TYPE_META, | 277 CACHE_TYPE_META, |
219 }; | 278 }; |
220 | 279 |
221 explicit GDataFileSystem(Profile* profile, | 280 // Callback similar to FileOperationCallback but with a given |
222 DocumentsServiceInterface* documents_service); | 281 // |file_path|. |
| 282 typedef base::Callback<void(base::PlatformFileError error, |
| 283 const FilePath& file_path)> |
| 284 FilePathUpdateCallback; |
| 285 |
| 286 GDataFileSystem(Profile* profile, |
| 287 DocumentsServiceInterface* documents_service); |
223 virtual ~GDataFileSystem(); | 288 virtual ~GDataFileSystem(); |
224 | 289 |
225 // Initiates upload operation of file defined with |file_name|, | 290 // Initiates upload operation of file defined with |file_name|, |
226 // |content_type| and |content_length|. The operation will place the newly | 291 // |content_type| and |content_length|. The operation will place the newly |
227 // created file entity into |destination_directory|. | 292 // created file entity into |destination_directory|. |
228 // | 293 // |
229 // Can be called from any thread. |callback| is run on the calling thread. | 294 // Can be called from any thread. |callback| is run on the calling thread. |
230 void InitiateUpload(const std::string& file_name, | 295 void InitiateUpload(const std::string& file_name, |
231 const std::string& content_type, | 296 const std::string& content_type, |
232 int64 content_length, | 297 int64 content_length, |
(...skipping 16 matching lines...) Expand all Loading... |
249 // DocumentsService. | 314 // DocumentsService. |
250 void ContinueDirectoryRefresh(const FindFileParams& params, | 315 void ContinueDirectoryRefresh(const FindFileParams& params, |
251 scoped_ptr<base::ListValue> feed_list); | 316 scoped_ptr<base::ListValue> feed_list); |
252 | 317 |
253 // Converts document feed from gdata service into DirectoryInfo. On failure, | 318 // Converts document feed from gdata service into DirectoryInfo. On failure, |
254 // returns NULL and fills in |error| with an appropriate value. | 319 // returns NULL and fills in |error| with an appropriate value. |
255 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 320 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
256 base::Value* data, | 321 base::Value* data, |
257 base::PlatformFileError *error); | 322 base::PlatformFileError *error); |
258 | 323 |
| 324 // Gets the parameters of a file or directory at |file_path| for copy/move |
| 325 // related operations. Returns false if |file_path| is not found. |
| 326 bool GetCopyMoveFileParams(const FilePath& file_path, |
| 327 CopyMoveFileParams* params); |
| 328 |
| 329 // Renames a file or directory at |file_path| to |new_name|. |
| 330 void Rename(const FilePath& file_path, |
| 331 const FilePath::StringType& new_name, |
| 332 const FilePathUpdateCallback& callback); |
| 333 |
| 334 // Adds a file or directory at |file_path| to the directory at |dir_path|. |
| 335 void AddFileToDirectory(const FilePath& dir_path, |
| 336 const FileOperationCallback& callback, |
| 337 base::PlatformFileError error, |
| 338 const FilePath& file_path); |
| 339 |
| 340 // Removes a file or directory at |file_path| from the directory at |
| 341 // |dir_path| and moves it to the root directory. |
| 342 void RemoveFileFromDirectory(const FilePath& dir_path, |
| 343 const FilePathUpdateCallback& callback, |
| 344 base::PlatformFileError error, |
| 345 const FilePath& file_path); |
| 346 |
259 // Callback for handling feed content fetching while searching for file info. | 347 // Callback for handling feed content fetching while searching for file info. |
260 // This callback is invoked after async feed fetch operation that was | 348 // This callback is invoked after async feed fetch operation that was |
261 // invoked by StartDirectoryRefresh() completes. This callback will update | 349 // invoked by StartDirectoryRefresh() completes. This callback will update |
262 // the content of the refreshed directory object and continue initially | 350 // the content of the refreshed directory object and continue initially |
263 // started FindFileByPath() request. | 351 // started FindFileByPath() request. |
264 void OnGetDocuments(const FindFileParams& params, | 352 void OnGetDocuments(const FindFileParams& params, |
265 scoped_ptr<base::ListValue> feed_list, | 353 scoped_ptr<base::ListValue> feed_list, |
266 GDataErrorCode status, | 354 GDataErrorCode status, |
267 scoped_ptr<base::Value> data); | 355 scoped_ptr<base::Value> data); |
268 | 356 |
| 357 // A pass-through callback used for bridging from |
| 358 // FilePathUpdateCallback to FileOperationCallback. |
| 359 void OnFilePathUpdated(const FileOperationCallback& cllback, |
| 360 base::PlatformFileError error, |
| 361 const FilePath& file_path); |
| 362 |
| 363 // Callback for handling resource rename attempt. |
| 364 void OnRenameResourceCompleted(const FilePath& file_path, |
| 365 const FilePath::StringType& new_name, |
| 366 const FilePathUpdateCallback& callback, |
| 367 GDataErrorCode status, |
| 368 const GURL& document_url); |
| 369 |
| 370 // Callback for handling document copy attempt. |
| 371 void OnCopyDocumentCompleted(const FilePathUpdateCallback& callback, |
| 372 GDataErrorCode status, |
| 373 scoped_ptr<base::Value> data); |
| 374 |
| 375 // Callback for handling an attempt to add a file or directory to another |
| 376 // directory. |
| 377 void OnAddFileToDirectoryCompleted(const FileOperationCallback& callback, |
| 378 const FilePath& file_path, |
| 379 const FilePath& dir_path, |
| 380 GDataErrorCode status, |
| 381 const GURL& document_url); |
| 382 |
| 383 // Callback for handling an attempt to remove a file or directory from |
| 384 // another directory. |
| 385 void OnRemoveFileFromDirectoryCompleted( |
| 386 const FilePathUpdateCallback& callback, |
| 387 const FilePath& file_path, |
| 388 const FilePath& dir_path, |
| 389 GDataErrorCode status, |
| 390 const GURL& document_url); |
| 391 |
269 // Callback for handling document remove attempt. | 392 // Callback for handling document remove attempt. |
270 void OnRemovedDocument( | 393 void OnRemovedDocument( |
271 const FileOperationCallback& callback, | 394 const FileOperationCallback& callback, |
272 const FilePath& file_path, | 395 const FilePath& file_path, |
273 GDataErrorCode status, | 396 GDataErrorCode status, |
274 const GURL& document_url); | 397 const GURL& document_url); |
275 | 398 |
276 // Callback for handling directory create requests. | 399 // Callback for handling directory create requests. |
277 void OnCreateDirectoryCompleted( | 400 void OnCreateDirectoryCompleted( |
278 const CreateDirectoryParams& params, | 401 const CreateDirectoryParams& params, |
(...skipping 15 matching lines...) Expand all Loading... |
294 const GURL& upload_location); | 417 const GURL& upload_location); |
295 | 418 |
296 // Callback for handling file upload resume requests. | 419 // Callback for handling file upload resume requests. |
297 void OnResumeUpload( | 420 void OnResumeUpload( |
298 const ResumeUploadOperationCallback& callback, | 421 const ResumeUploadOperationCallback& callback, |
299 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 422 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
300 GDataErrorCode code, | 423 GDataErrorCode code, |
301 int64 start_range_received, | 424 int64 start_range_received, |
302 int64 end_range_received); | 425 int64 end_range_received); |
303 | 426 |
| 427 // Renames a file or directory at |file_path| on in-memory snapshot |
| 428 // of the file system. Returns PLATFORM_FILE_OK if successful. |
| 429 base::PlatformFileError RenameFileOnFilesystem( |
| 430 const FilePath& file_path, const FilePath::StringType& new_name, |
| 431 FilePath* updated_file_path); |
| 432 |
| 433 // Adds a file or directory at |file_path| to another directory at |
| 434 // |dir_path| on in-memory snapshot of the file system. |
| 435 // Returns PLATFORM_FILE_OK if successful. |
| 436 base::PlatformFileError AddFileToDirectoryOnFilesystem( |
| 437 const FilePath& file_path, const FilePath& dir_path); |
| 438 |
| 439 // Removes a file or directory at |file_path| from another directory at |
| 440 // |dir_path| on in-memory snapshot of the file system. |
| 441 // Returns PLATFORM_FILE_OK if successful. |
| 442 base::PlatformFileError RemoveFileFromDirectoryOnFilesystem( |
| 443 const FilePath& file_path, const FilePath& dir_path, |
| 444 FilePath* updated_file_path); |
| 445 |
304 // Removes file under |file_path| from in-memory snapshot of the file system. | 446 // Removes file under |file_path| from in-memory snapshot of the file system. |
305 // Return PLATFORM_FILE_OK if successful. | 447 // Return PLATFORM_FILE_OK if successful. |
306 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); | 448 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); |
307 | 449 |
308 // Parses the content of |feed_data| and returns DocumentFeed instance | 450 // Parses the content of |feed_data| and returns DocumentFeed instance |
309 // represeting it. | 451 // represeting it. |
310 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); | 452 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); |
311 | 453 |
312 // Updates content of the directory identified with |directory_path| with | 454 // Updates content of the directory identified with |directory_path| with |
313 // feeds collected in |feed_list|. | 455 // feeds collected in |feed_list|. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 GDataDirectory*) OVERRIDE; | 689 GDataDirectory*) OVERRIDE; |
548 virtual void OnError(base::PlatformFileError) OVERRIDE; | 690 virtual void OnError(base::PlatformFileError) OVERRIDE; |
549 | 691 |
550 // File entry that was found. | 692 // File entry that was found. |
551 GDataFileBase* file_; | 693 GDataFileBase* file_; |
552 }; | 694 }; |
553 | 695 |
554 } // namespace gdata | 696 } // namespace gdata |
555 | 697 |
556 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 698 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |