Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / sync / remove_performer.h
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_REMOVE_PERFORMER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_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
15 namespace base {
16 class SequencedTaskRunner;
17 }
18
19 namespace google_apis {
20 class FileResource;
21 }
22
23 namespace drive {
24
25 class JobScheduler;
26 class ResourceEntry;
27 struct ClientContext;
28
29 namespace file_system {
30 class OperationDelegate;
31 }  // namespace file_system
32
33 namespace internal {
34
35 class EntryRevertPerformer;
36 class ResourceMetadata;
37
38 // This class encapsulates the drive Remove function.  It is responsible for
39 // sending the request to the drive API, then updating the local state and
40 // metadata to reflect the new state.
41 class RemovePerformer {
42  public:
43   RemovePerformer(base::SequencedTaskRunner* blocking_task_runner,
44                   file_system::OperationDelegate* delegate,
45                   JobScheduler* scheduler,
46                   ResourceMetadata* metadata);
47   ~RemovePerformer();
48
49   // Removes the resource.
50   //
51   // |callback| must not be null.
52   void Remove(const std::string& local_id,
53               const ClientContext& context,
54               const FileOperationCallback& callback);
55
56  private:
57   // Part of Remove(). Called after GetResourceEntry() completion.
58   void RemoveAfterGetResourceEntry(const ClientContext& context,
59                                    const FileOperationCallback& callback,
60                                    const ResourceEntry* entry,
61                                    FileError error);
62
63   // Requests the server to move the specified resource to the trash.
64   void TrashResource(const ClientContext& context,
65                      const FileOperationCallback& callback,
66                      const std::string& resource_id,
67                      const std::string& local_id);
68
69   // Part of TrashResource(). Called after server-side removal is done.
70   void TrashResourceAfterUpdateRemoteState(
71       const ClientContext& context,
72       const FileOperationCallback& callback,
73       const std::string& local_id,
74       google_apis::GDataErrorCode status);
75
76   // Requests the server to detach the specified resource from its parent.
77   void UnparentResource(const ClientContext& context,
78                         const FileOperationCallback& callback,
79                         const std::string& resource_id,
80                         const std::string& local_id);
81
82   // Part of UnparentResource().
83   void UnparentResourceAfterGetFileResource(
84       const ClientContext& context,
85       const FileOperationCallback& callback,
86       const std::string& local_id,
87       google_apis::GDataErrorCode status,
88       scoped_ptr<google_apis::FileResource> file_resource);
89
90   // Part of UnparentResource().
91   void UnparentResourceAfterUpdateRemoteState(
92       const FileOperationCallback& callback,
93       const std::string& local_id,
94       google_apis::GDataErrorCode status);
95
96   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
97   file_system::OperationDelegate* delegate_;
98   JobScheduler* scheduler_;
99   ResourceMetadata* metadata_;
100   scoped_ptr<EntryRevertPerformer> entry_revert_performer_;
101
102   // Note: This should remain the last member so it'll be destroyed and
103   // invalidate the weak pointers before any other members are destroyed.
104   base::WeakPtrFactory<RemovePerformer> weak_ptr_factory_;
105   DISALLOW_COPY_AND_ASSIGN(RemovePerformer);
106 };
107
108 }  // namespace internal
109 }  // namespace drive
110
111 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_SYNC_REMOVE_PERFORMER_H_