- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / file_system / move_operation.h
1 // Copyright (c) 2012 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_FILE_SYSTEM_MOVE_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_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/resource_metadata.h"
13 #include "chrome/browser/google_apis/gdata_errorcode.h"
14
15 namespace base {
16 class FilePath;
17 class SequencedTaskRunner;
18 }  // namespace base
19
20 namespace google_apis {
21 class ResourceEntry;
22 }  // namespace google_apis
23
24 namespace drive {
25
26 class JobScheduler;
27 class ResourceEntry;
28
29 namespace file_system {
30
31 class OperationObserver;
32
33 // This class encapsulates the drive Move function.  It is responsible for
34 // sending the request to the drive API, then updating the local state and
35 // metadata to reflect the new state.
36 class MoveOperation {
37  public:
38   MoveOperation(base::SequencedTaskRunner* blocking_task_runner,
39                 OperationObserver* observer,
40                 JobScheduler* scheduler,
41                 internal::ResourceMetadata* metadata);
42   ~MoveOperation();
43
44   // Performs the move operation on the file at drive path |src_file_path|
45   // with a target of |dest_file_path|.
46   // If |preserve_last_modified| is set to true, this tries to preserve
47   // last modified time stamp. This is supported only on Drive API v2.
48   // Invokes |callback| when finished with the result of the operation.
49   // |callback| must not be null.
50   void Move(const base::FilePath& src_file_path,
51             const base::FilePath& dest_file_path,
52             bool preserve_last_modified,
53             const FileOperationCallback& callback);
54
55  private:
56   // Params of Move().
57   struct MoveParams;
58
59   // Part of Move(). Called after local metadata look up.
60   void MoveAfterPrepare(const MoveParams& params,
61                         scoped_ptr<ResourceEntry> src_entry,
62                         scoped_ptr<ResourceEntry> src_parent_entry,
63                         scoped_ptr<ResourceEntry> dest_parent_entry,
64                         FileError error);
65
66   // Part of Move(). Called after MoveResource is completed. This is only for
67   // Drive API v2.
68   void MoveAfterMoveResource(
69       const MoveParams& params,
70       google_apis::GDataErrorCode status,
71       scoped_ptr<google_apis::ResourceEntry> resource_entry);
72
73   // Part of Move(). Called after ResourceMetadata::RefreshEntry is completed.
74   // This is only for Drive API v2.
75   void MoveAfterRefreshEntry(const MoveParams& params, FileError error);
76
77   // Part of Move(). Called after renaming (without moving the directory)
78   // is completed.
79   void MoveAfterRename(const MoveParams& params,
80                        scoped_ptr<ResourceEntry> src_entry,
81                        scoped_ptr<ResourceEntry> src_parent_entry,
82                        scoped_ptr<ResourceEntry> dest_parent_entry,
83                        FileError error);
84
85   // Part of Move(). Called after adding the entry to the parent is done.
86   void MoveAfterAddToDirectory(const MoveParams& params,
87                                const std::string& resource_id,
88                                const std::string& old_parent_resource_id,
89                                FileError error);
90
91
92   // Renames the |entry| to |new_title|. Upon completion, |callback| will be
93   // called. Note that if |entry|'s title is same as |new_title|, does nothing
94   // and calls |callback|.
95   // |callback| must not be null.
96   void Rename(const ResourceEntry& entry,
97               const std::string& new_title,
98               const FileOperationCallback& callback);
99
100   // Part of Rename(). Called after server side renaming is done.
101   void RenameAfterRenameResource(const std::string& local_id,
102                                  const std::string& new_title,
103                                  const FileOperationCallback& callback,
104                                  google_apis::GDataErrorCode status);
105
106
107   // Adds the entry to the specified directory.
108   // Upon completion, |callback| will be called.
109   void AddToDirectory(scoped_ptr<ResourceEntry> entry,
110                       scoped_ptr<ResourceEntry> directory,
111                       const FileOperationCallback& callback);
112
113   // Part of AddToDirectory(). Called after server side updating is done.
114   void AddToDirectoryAfterAddResourceToDirectory(
115       const std::string& local_id,
116       const std::string& parent_local_id,
117       const FileOperationCallback& callback,
118       google_apis::GDataErrorCode status);
119
120   // Removes the resource with |resource_id| from the directory with
121   // |directory_resource_id|.
122   // Upon completion, |callback| will be called.
123   void RemoveFromDirectory(const std::string& resource_id,
124                            const std::string& directory_resource_id,
125                            const FileOperationCallback& callback);
126
127   // Part of RemoveFromDirectory(). Called after server side updating is done.
128   void RemoveFromDirectoryAfterRemoveResourceFromDirectory(
129       const FileOperationCallback& callback,
130       google_apis::GDataErrorCode status);
131
132   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
133   OperationObserver* observer_;
134   JobScheduler* scheduler_;
135   internal::ResourceMetadata* metadata_;
136
137   // Note: This should remain the last member so it'll be destroyed and
138   // invalidate the weak pointers before any other members are destroyed.
139   base::WeakPtrFactory<MoveOperation> weak_ptr_factory_;
140   DISALLOW_COPY_AND_ASSIGN(MoveOperation);
141 };
142
143 }  // namespace file_system
144 }  // namespace drive
145
146 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_