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