entry_update_performer.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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_UPDATE_PERFORMER_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_UPDATE_PERFORMER_H_
7
8#include "base/basictypes.h"
9#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/memory/weak_ptr.h"
12#include "chrome/browser/chromeos/drive/file_errors.h"
13#include "google_apis/drive/gdata_errorcode.h"
14
15namespace base {
16class ScopedClosureRunner;
17class SequencedTaskRunner;
18}  // namespace base
19
20namespace google_apis {
21class FileResource;
22}  // namespace google_apis
23
24namespace drive {
25
26class FileChange;
27class JobScheduler;
28class ResourceEntry;
29struct ClientContext;
30
31namespace file_system {
32class OperationDelegate;
33}  // namespace file_system
34
35namespace internal {
36
37class EntryRevertPerformer;
38class FileCache;
39class LoaderController;
40class RemovePerformer;
41class ResourceMetadata;
42
43// This class is responsible to perform server side update of an entry.
44class EntryUpdatePerformer {
45 public:
46  EntryUpdatePerformer(base::SequencedTaskRunner* blocking_task_runner,
47                       file_system::OperationDelegate* delegate,
48                       JobScheduler* scheduler,
49                       ResourceMetadata* metadata,
50                       FileCache* cache,
51                       LoaderController* loader_controller);
52  ~EntryUpdatePerformer();
53
54  // Requests the server to update the metadata of the entry specified by
55  // |local_id| with the locally stored one.
56  // Invokes |callback| when finished with the result of the operation.
57  // |callback| must not be null.
58  void UpdateEntry(const std::string& local_id,
59                   const ClientContext& context,
60                   const FileOperationCallback& callback);
61
62  struct LocalState;
63
64 private:
65  // Part of UpdateEntry(). Called after local metadata look up.
66  void UpdateEntryAfterPrepare(const ClientContext& context,
67                               const FileOperationCallback& callback,
68                               scoped_ptr<LocalState> local_state,
69                               FileError error);
70
71  // Part of UpdateEntry(). Called after UpdateResource is completed.
72  void UpdateEntryAfterUpdateResource(
73      const ClientContext& context,
74      const FileOperationCallback& callback,
75      const std::string& local_id,
76      scoped_ptr<base::ScopedClosureRunner> loader_lock,
77      google_apis::GDataErrorCode status,
78      scoped_ptr<google_apis::FileResource> entry);
79
80  // Part of UpdateEntry(). Called after FinishUpdate is completed.
81  void UpdateEntryAfterFinish(const FileOperationCallback& callback,
82                              const FileChange* changed_files,
83                              FileError error);
84
85  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
86  file_system::OperationDelegate* delegate_;
87  JobScheduler* scheduler_;
88  ResourceMetadata* metadata_;
89  FileCache* cache_;
90  LoaderController* loader_controller_;
91  scoped_ptr<RemovePerformer> remove_performer_;
92  scoped_ptr<EntryRevertPerformer> entry_revert_performer_;
93
94  // Note: This should remain the last member so it'll be destroyed and
95  // invalidate the weak pointers before any other members are destroyed.
96  base::WeakPtrFactory<EntryUpdatePerformer> weak_ptr_factory_;
97  DISALLOW_COPY_AND_ASSIGN(EntryUpdatePerformer);
98};
99
100}  // namespace internal
101}  // namespace drive
102
103#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_UPDATE_PERFORMER_H_
104