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 "base/threading/thread_checker.h"
13 #include "components/drive/file_errors.h"
14 #include "google_apis/drive/drive_api_error_codes.h"
17 class ScopedClosureRunner
;
18 class SequencedTaskRunner
;
21 namespace google_apis
{
23 } // namespace google_apis
32 namespace file_system
{
33 class OperationDelegate
;
34 } // namespace file_system
38 class EntryRevertPerformer
;
40 class LoaderController
;
41 class RemovePerformer
;
42 class ResourceMetadata
;
44 // This class is responsible to perform server side update of an entry.
45 class EntryUpdatePerformer
{
47 EntryUpdatePerformer(base::SequencedTaskRunner
* blocking_task_runner
,
48 file_system::OperationDelegate
* delegate
,
49 JobScheduler
* scheduler
,
50 ResourceMetadata
* metadata
,
52 LoaderController
* loader_controller
);
53 ~EntryUpdatePerformer();
55 // Requests the server to update the metadata of the entry specified by
56 // |local_id| with the locally stored one.
57 // Invokes |callback| when finished with the result of the operation.
58 // |callback| must not be null.
59 void UpdateEntry(const std::string
& local_id
,
60 const ClientContext
& context
,
61 const FileOperationCallback
& callback
);
66 // Part of UpdateEntry(). Called after local metadata look up.
67 void UpdateEntryAfterPrepare(const ClientContext
& context
,
68 const FileOperationCallback
& callback
,
69 scoped_ptr
<LocalState
> local_state
,
72 // Part of UpdateEntry(). Called after UpdateResource is completed.
73 void UpdateEntryAfterUpdateResource(
74 const ClientContext
& context
,
75 const FileOperationCallback
& callback
,
76 scoped_ptr
<LocalState
> local_state
,
77 scoped_ptr
<base::ScopedClosureRunner
> loader_lock
,
78 google_apis::DriveApiErrorCode status
,
79 scoped_ptr
<google_apis::FileResource
> entry
);
81 // Part of UpdateEntry(). Called after FinishUpdate is completed.
82 void UpdateEntryAfterFinish(const FileOperationCallback
& callback
,
83 const FileChange
* changed_files
,
86 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
87 file_system::OperationDelegate
* delegate_
;
88 JobScheduler
* scheduler_
;
89 ResourceMetadata
* metadata_
;
91 LoaderController
* loader_controller_
;
92 scoped_ptr
<RemovePerformer
> remove_performer_
;
93 scoped_ptr
<EntryRevertPerformer
> entry_revert_performer_
;
95 base::ThreadChecker thread_checker_
;
97 // Note: This should remain the last member so it'll be destroyed and
98 // invalidate the weak pointers before any other members are destroyed.
99 base::WeakPtrFactory
<EntryUpdatePerformer
> weak_ptr_factory_
;
100 DISALLOW_COPY_AND_ASSIGN(EntryUpdatePerformer
);
103 } // namespace internal
106 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_ENTRY_UPDATE_PERFORMER_H_