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_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "chrome/browser/chromeos/drive/file_errors.h" | 11 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
12 #include "chrome/browser/google_apis/gdata_errorcode.h" | 13 #include "chrome/browser/google_apis/gdata_errorcode.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class FilePath; | 16 class FilePath; |
16 } // namespace base | 17 } // namespace base |
17 | 18 |
18 namespace drive { | 19 namespace drive { |
19 | 20 |
20 class JobScheduler; | 21 class JobScheduler; |
21 class ResourceEntry; | 22 class ResourceEntry; |
(...skipping 11 matching lines...) Expand all Loading... |
33 // sending the request to the drive API, then updating the local state and | 34 // sending the request to the drive API, then updating the local state and |
34 // metadata to reflect the new state. | 35 // metadata to reflect the new state. |
35 class RemoveOperation { | 36 class RemoveOperation { |
36 public: | 37 public: |
37 RemoveOperation(OperationObserver* observer, | 38 RemoveOperation(OperationObserver* observer, |
38 JobScheduler* scheduler, | 39 JobScheduler* scheduler, |
39 internal::ResourceMetadata* metadata, | 40 internal::ResourceMetadata* metadata, |
40 internal::FileCache* cache); | 41 internal::FileCache* cache); |
41 ~RemoveOperation(); | 42 ~RemoveOperation(); |
42 | 43 |
43 // Perform the remove operation on the file at drive path |file_path|. | 44 // Removes the resource at |path|. If |path| is a directory and |is_recursive| |
44 // Invokes |callback| when finished with the result of the operation. | 45 // is set, it recursively removes all the descendants. If |is_recursive| is |
| 46 // not set, it succeeds only when the directory is empty. |
| 47 // |
45 // |callback| must not be null. | 48 // |callback| must not be null. |
46 void Remove(const base::FilePath& file_path, | 49 void Remove(const base::FilePath& path, |
47 bool is_recursive, | 50 bool is_recursive, |
48 const FileOperationCallback& callback); | 51 const FileOperationCallback& callback); |
49 | 52 |
50 private: | 53 private: |
51 // Part of Remove(). Called after GetResourceEntryByPath() is complete. | 54 // Part of Remove(). Called after GetResourceEntryByPath() is complete. |
52 void RemoveAfterGetResourceEntry(const FileOperationCallback& callback, | 55 void RemoveAfterGetResourceEntry(const base::FilePath& path, |
| 56 bool is_recursive, |
| 57 const FileOperationCallback& callback, |
53 FileError error, | 58 FileError error, |
54 scoped_ptr<ResourceEntry> entry); | 59 scoped_ptr<ResourceEntry> entry); |
55 | 60 |
56 // Callback for DriveServiceInterface::DeleteResource. Removes the entry with | 61 // Part of Remove(). Called when is_recursive = false and trying to remove |
57 // |resource_id| from the local snapshot of the filesystem and the cache. | 62 // a directory. In this case the emptiness of directory must be checked. |
| 63 void RemoveAfterReadDirectory(const std::string& resource_id, |
| 64 const FileOperationCallback& callback, |
| 65 FileError error, |
| 66 scoped_ptr<ResourceEntryVector> entries); |
| 67 |
| 68 // Part of Remove(). Called after server-side removal is done. Removes the |
| 69 // entry with |resource_id| from the resource metadata and the cache. |
58 void RemoveResourceLocally(const FileOperationCallback& callback, | 70 void RemoveResourceLocally(const FileOperationCallback& callback, |
59 const std::string& resource_id, | 71 const std::string& resource_id, |
60 google_apis::GDataErrorCode status); | 72 google_apis::GDataErrorCode status); |
61 | 73 |
62 // Sends notification for directory changes. Notifies of directory changes, | 74 // Part of Remove(). Sends notification for directory changes, and runs |
63 // and runs |callback| with |error|. | 75 // |callback| with |error|. |
64 void NotifyDirectoryChanged(const FileOperationCallback& callback, | 76 void NotifyDirectoryChanged(const FileOperationCallback& callback, |
65 FileError error, | 77 FileError error, |
66 const base::FilePath& directory_path); | 78 const base::FilePath& directory_path); |
67 | 79 |
68 OperationObserver* observer_; | 80 OperationObserver* observer_; |
69 JobScheduler* scheduler_; | 81 JobScheduler* scheduler_; |
70 internal::ResourceMetadata* metadata_; | 82 internal::ResourceMetadata* metadata_; |
71 internal::FileCache* cache_; | 83 internal::FileCache* cache_; |
72 | 84 |
73 // Note: This should remain the last member so it'll be destroyed and | 85 // Note: This should remain the last member so it'll be destroyed and |
74 // invalidate the weak pointers before any other members are destroyed. | 86 // invalidate the weak pointers before any other members are destroyed. |
75 base::WeakPtrFactory<RemoveOperation> weak_ptr_factory_; | 87 base::WeakPtrFactory<RemoveOperation> weak_ptr_factory_; |
76 DISALLOW_COPY_AND_ASSIGN(RemoveOperation); | 88 DISALLOW_COPY_AND_ASSIGN(RemoveOperation); |
77 }; | 89 }; |
78 | 90 |
79 } // namespace file_system | 91 } // namespace file_system |
80 } // namespace drive | 92 } // namespace drive |
81 | 93 |
82 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ | 94 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_REMOVE_OPERATION_H_ |
OLD | NEW |