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_
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 "chrome/browser/chromeos/drive/file_errors.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
19 class SequencedTaskRunner
;
22 namespace google_apis
{
24 } // namespace google_apis
33 namespace file_system
{
34 class OperationDelegate
;
35 } // namespace file_system
39 class ResourceMetadata
;
41 // This class is responsible to revert local changes of an entry.
42 class EntryRevertPerformer
{
44 EntryRevertPerformer(base::SequencedTaskRunner
* blocking_task_runner
,
45 file_system::OperationDelegate
* delegate
,
46 JobScheduler
* scheduler
,
47 ResourceMetadata
* metadata
);
48 ~EntryRevertPerformer();
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
);
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
,
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
);
72 // Part of RevertEntry(). Called after local metadata is updated.
73 void RevertEntryAfterFinishRevert(const FileOperationCallback
& callback
,
74 const FileChange
* changed_files
,
77 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
78 file_system::OperationDelegate
* delegate_
;
79 JobScheduler
* scheduler_
;
80 ResourceMetadata
* metadata_
;
82 base::ThreadChecker thread_checker_
;
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
);
90 } // namespace internal
93 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_REVERT_PERFORMER_H_