entry_revert_performer.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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
17namespace base {
18class SequencedTaskRunner;
19}  // namespace base
20
21namespace google_apis {
22class ResourceEntry;
23}  // namespace google_apis
24
25namespace drive {
26
27class JobScheduler;
28class ResourceEntry;
29
30namespace file_system {
31class OperationObserver;
32}  // namespace file_system
33
34namespace internal {
35
36class ResourceMetadata;
37
38// This class is responsible to revert local changes of an entry.
39class EntryRevertPerformer {
40 public:
41  EntryRevertPerformer(base::SequencedTaskRunner* blocking_task_runner,
42                       file_system::OperationObserver* observer,
43                       JobScheduler* scheduler,
44                       ResourceMetadata* metadata);
45  ~EntryRevertPerformer();
46
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);
53
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);
59
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);
66
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);
72
73  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
74  file_system::OperationObserver* observer_;
75  JobScheduler* scheduler_;
76  ResourceMetadata* metadata_;
77
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);
82};
83
84}  // namespace internal
85}  // namespace drive
86
87#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_
88