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_UPDATE_PERFORMER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_UPDATE_PERFORMER_H_
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"
16 class ScopedClosureRunner;
17 class SequencedTaskRunner;
20 namespace google_apis {
22 } // namespace google_apis
30 namespace file_system {
31 class OperationObserver;
32 } // namespace file_system
36 class EntryRevertPerformer;
38 class LoaderController;
39 class RemovePerformer;
40 class ResourceMetadata;
42 // This class is responsible to perform server side update of an entry.
43 class EntryUpdatePerformer {
45 EntryUpdatePerformer(base::SequencedTaskRunner* blocking_task_runner,
46 file_system::OperationObserver* observer,
47 JobScheduler* scheduler,
48 ResourceMetadata* metadata,
50 LoaderController* loader_controller);
51 ~EntryUpdatePerformer();
53 // Requests the server to update the metadata of the entry specified by
54 // |local_id| with the locally stored one.
55 // Invokes |callback| when finished with the result of the operation.
56 // |callback| must not be null.
57 void UpdateEntry(const std::string& local_id,
58 const ClientContext& context,
59 const FileOperationCallback& callback);
64 // Part of UpdateEntry(). Called after local metadata look up.
65 void UpdateEntryAfterPrepare(const ClientContext& context,
66 const FileOperationCallback& callback,
67 scoped_ptr<LocalState> local_state,
70 // Part of UpdateEntry(). Called after UpdateResource is completed.
71 void UpdateEntryAfterUpdateResource(
72 const ClientContext& context,
73 const FileOperationCallback& callback,
74 const std::string& local_id,
75 scoped_ptr<base::ScopedClosureRunner> loader_lock,
76 google_apis::GDataErrorCode status,
77 scoped_ptr<google_apis::ResourceEntry> resource_entry);
79 // Part of UpdateEntry(). Called after FinishUpdate is completed.
80 void UpdateEntryAfterFinish(const FileOperationCallback& callback,
81 const base::FilePath* changed_directory,
84 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
85 file_system::OperationObserver* observer_;
86 JobScheduler* scheduler_;
87 ResourceMetadata* metadata_;
89 LoaderController* loader_controller_;
90 scoped_ptr<RemovePerformer> remove_performer_;
91 scoped_ptr<EntryRevertPerformer> entry_revert_performer_;
93 // Note: This should remain the last member so it'll be destroyed and
94 // invalidate the weak pointers before any other members are destroyed.
95 base::WeakPtrFactory<EntryUpdatePerformer> weak_ptr_factory_;
96 DISALLOW_COPY_AND_ASSIGN(EntryUpdatePerformer);
99 } // namespace internal
102 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_UPDATE_PERFORMER_H_