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_ENTRY_REVERT_PERFORMER_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_ 7 8 #include <set> 9 10 #include "base/basictypes.h" 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/weak_ptr.h" 14 #include "chrome/browser/chromeos/drive/file_errors.h" 15 #include "google_apis/drive/gdata_errorcode.h" 16 17 namespace base { 18 class SequencedTaskRunner; 19 } // namespace base 20 21 namespace google_apis { 22 class FileResource; 23 } // namespace google_apis 24 25 namespace drive { 26 27 class FileChange; 28 class JobScheduler; 29 class ResourceEntry; 30 struct ClientContext; 31 32 namespace file_system { 33 class OperationDelegate; 34 } // namespace file_system 35 36 namespace internal { 37 38 class ResourceMetadata; 39 40 // This class is responsible to revert local changes of an entry. 41 class EntryRevertPerformer { 42 public: 43 EntryRevertPerformer(base::SequencedTaskRunner* blocking_task_runner, 44 file_system::OperationDelegate* delegate, 45 JobScheduler* scheduler, 46 ResourceMetadata* metadata); 47 ~EntryRevertPerformer(); 48 49 // Requests the server for metadata of the entry specified by |local_id| 50 // and overwrites the locally stored entry with it. 51 // Invokes |callback| when finished with the result of the operation. 52 // |callback| must not be null. 53 void RevertEntry(const std::string& local_id, 54 const ClientContext& context, 55 const FileOperationCallback& callback); 56 57 private: 58 // Part of RevertEntry(). Called after local metadata look up. 59 void RevertEntryAfterPrepare(const ClientContext& context, 60 const FileOperationCallback& callback, 61 scoped_ptr<ResourceEntry> entry, 62 FileError error); 63 64 // Part of RevertEntry(). Called after GetFileResource is completed. 65 void RevertEntryAfterGetFileResource( 66 const FileOperationCallback& callback, 67 const std::string& local_id, 68 google_apis::GDataErrorCode status, 69 scoped_ptr<google_apis::FileResource> entry); 70 71 // Part of RevertEntry(). Called after local metadata is updated. 72 void RevertEntryAfterFinishRevert(const FileOperationCallback& callback, 73 const FileChange* changed_files, 74 FileError error); 75 76 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 77 file_system::OperationDelegate* delegate_; 78 JobScheduler* scheduler_; 79 ResourceMetadata* metadata_; 80 81 // Note: This should remain the last member so it'll be destroyed and 82 // invalidate the weak pointers before any other members are destroyed. 83 base::WeakPtrFactory<EntryRevertPerformer> weak_ptr_factory_; 84 DISALLOW_COPY_AND_ASSIGN(EntryRevertPerformer); 85 }; 86 87 } // namespace internal 88 } // namespace drive 89 90 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_ 91