Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / sync / entry_revert_performer.h
blob29424054cce16e10b0cf9c8ffdb67b1740afbb2b
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_
8 #include <set>
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"
17 namespace base {
18 class SequencedTaskRunner;
19 } // namespace base
21 namespace google_apis {
22 class ResourceEntry;
23 } // namespace google_apis
25 namespace drive {
27 class JobScheduler;
28 class ResourceEntry;
30 namespace file_system {
31 class OperationObserver;
32 } // namespace file_system
34 namespace internal {
36 class ResourceMetadata;
38 // This class is responsible to revert local changes of an entry.
39 class EntryRevertPerformer {
40 public:
41 EntryRevertPerformer(base::SequencedTaskRunner* blocking_task_runner,
42 file_system::OperationObserver* observer,
43 JobScheduler* scheduler,
44 ResourceMetadata* metadata);
45 ~EntryRevertPerformer();
47 // Requests the server for metadata of the entry specified by |local_id|
48 // and overwrites the locally stored entry with it.
49 // Invokes |callback| when finished with the result of the operation.
50 // |callback| must not be null.
51 void RevertEntry(const std::string& local_id,
52 const FileOperationCallback& callback);
54 private:
55 // Part of RevertEntry(). Called after local metadata look up.
56 void RevertEntryAfterPrepare(const FileOperationCallback& callback,
57 scoped_ptr<ResourceEntry> entry,
58 FileError error);
60 // Part of RevertEntry(). Called after GetResourceEntry is completed.
61 void RevertEntryAfterGetResourceEntry(
62 const FileOperationCallback& callback,
63 const std::string& local_id,
64 google_apis::GDataErrorCode status,
65 scoped_ptr<google_apis::ResourceEntry> resource_entry);
67 // Part of RevertEntry(). Called after local metadata is updated.
68 void RevertEntryAfterFinishRevert(
69 const FileOperationCallback& callback,
70 const std::set<base::FilePath>* changed_directories,
71 FileError error);
73 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
74 file_system::OperationObserver* observer_;
75 JobScheduler* scheduler_;
76 ResourceMetadata* metadata_;
78 // Note: This should remain the last member so it'll be destroyed and
79 // invalidate the weak pointers before any other members are destroyed.
80 base::WeakPtrFactory<EntryRevertPerformer> weak_ptr_factory_;
81 DISALLOW_COPY_AND_ASSIGN(EntryRevertPerformer);
84 } // namespace internal
85 } // namespace drive
87 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_