| OLD | NEW |
| (Empty) |
| 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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #include "components/drive/file_errors.h" | |
| 14 #include "google_apis/drive/drive_api_error_codes.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SequencedTaskRunner; | |
| 18 } | |
| 19 | |
| 20 namespace google_apis { | |
| 21 class FileResource; | |
| 22 } | |
| 23 | |
| 24 namespace drive { | |
| 25 | |
| 26 class JobScheduler; | |
| 27 class ResourceEntry; | |
| 28 struct ClientContext; | |
| 29 | |
| 30 namespace file_system { | |
| 31 class OperationDelegate; | |
| 32 } // namespace file_system | |
| 33 | |
| 34 namespace internal { | |
| 35 | |
| 36 class EntryRevertPerformer; | |
| 37 class ResourceMetadata; | |
| 38 | |
| 39 // This class encapsulates the drive Remove function. It is responsible for | |
| 40 // sending the request to the drive API, then updating the local state and | |
| 41 // metadata to reflect the new state. | |
| 42 class RemovePerformer { | |
| 43 public: | |
| 44 RemovePerformer(base::SequencedTaskRunner* blocking_task_runner, | |
| 45 file_system::OperationDelegate* delegate, | |
| 46 JobScheduler* scheduler, | |
| 47 ResourceMetadata* metadata); | |
| 48 ~RemovePerformer(); | |
| 49 | |
| 50 // Removes the resource. | |
| 51 // | |
| 52 // |callback| must not be null. | |
| 53 void Remove(const std::string& local_id, | |
| 54 const ClientContext& context, | |
| 55 const FileOperationCallback& callback); | |
| 56 | |
| 57 private: | |
| 58 // Part of Remove(). Called after GetResourceEntry() completion. | |
| 59 void RemoveAfterGetResourceEntry(const ClientContext& context, | |
| 60 const FileOperationCallback& callback, | |
| 61 const ResourceEntry* entry, | |
| 62 FileError error); | |
| 63 | |
| 64 // Requests the server to move the specified resource to the trash. | |
| 65 void TrashResource(const ClientContext& context, | |
| 66 const FileOperationCallback& callback, | |
| 67 const std::string& resource_id, | |
| 68 const std::string& local_id); | |
| 69 | |
| 70 // Part of TrashResource(). Called after server-side removal is done. | |
| 71 void TrashResourceAfterUpdateRemoteState( | |
| 72 const ClientContext& context, | |
| 73 const FileOperationCallback& callback, | |
| 74 const std::string& local_id, | |
| 75 google_apis::DriveApiErrorCode status); | |
| 76 | |
| 77 // Requests the server to detach the specified resource from its parent. | |
| 78 void UnparentResource(const ClientContext& context, | |
| 79 const FileOperationCallback& callback, | |
| 80 const std::string& resource_id, | |
| 81 const std::string& local_id); | |
| 82 | |
| 83 // Part of UnparentResource(). | |
| 84 void UnparentResourceAfterGetFileResource( | |
| 85 const ClientContext& context, | |
| 86 const FileOperationCallback& callback, | |
| 87 const std::string& local_id, | |
| 88 google_apis::DriveApiErrorCode status, | |
| 89 scoped_ptr<google_apis::FileResource> file_resource); | |
| 90 | |
| 91 // Part of UnparentResource(). | |
| 92 void UnparentResourceAfterUpdateRemoteState( | |
| 93 const FileOperationCallback& callback, | |
| 94 const std::string& local_id, | |
| 95 google_apis::DriveApiErrorCode status); | |
| 96 | |
| 97 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 98 file_system::OperationDelegate* delegate_; | |
| 99 JobScheduler* scheduler_; | |
| 100 ResourceMetadata* metadata_; | |
| 101 scoped_ptr<EntryRevertPerformer> entry_revert_performer_; | |
| 102 | |
| 103 base::ThreadChecker thread_checker_; | |
| 104 | |
| 105 // Note: This should remain the last member so it'll be destroyed and | |
| 106 // invalidate the weak pointers before any other members are destroyed. | |
| 107 base::WeakPtrFactory<RemovePerformer> weak_ptr_factory_; | |
| 108 DISALLOW_COPY_AND_ASSIGN(RemovePerformer); | |
| 109 }; | |
| 110 | |
| 111 } // namespace internal | |
| 112 } // namespace drive | |
| 113 | |
| 114 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_ | |
| OLD | NEW |