Ensure low-memory renderers retry failed loads correctly.
[chromium-blink-merge.git] / components / drive / file_system / copy_operation.h
blob1f92bd4332a406b37c2230535215e2cdce4bef10
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.
5 #ifndef COMPONENTS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_
6 #define COMPONENTS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "components/drive/file_errors.h"
17 #include "google_apis/drive/drive_api_error_codes.h"
19 namespace base {
20 class FilePath;
21 class SequencedTaskRunner;
22 class Time;
23 } // namespace base
25 namespace google_apis {
26 class FileResource;
27 } // namespace google_apis
29 namespace drive {
31 class JobScheduler;
32 class ResourceEntry;
34 namespace internal {
35 class FileCache;
36 class ResourceMetadata;
37 } // namespace internal
39 namespace file_system {
41 class CreateFileOperation;
42 class OperationDelegate;
44 // This class encapsulates the drive Copy function. It is responsible for
45 // sending the request to the drive API, then updating the local state and
46 // metadata to reflect the new state.
47 class CopyOperation {
48 public:
49 CopyOperation(base::SequencedTaskRunner* blocking_task_runner,
50 OperationDelegate* delegate,
51 JobScheduler* scheduler,
52 internal::ResourceMetadata* metadata,
53 internal::FileCache* cache);
54 ~CopyOperation();
56 // Performs the copy operation on the file at drive path |src_file_path|
57 // with a target of |dest_file_path|.
58 // If |preserve_last_modified| is set to true, this tries to preserve
59 // last modified time stamp. This is supported only on Drive API v2.
60 // Invokes |callback| when finished with the result of the operation.
61 // |callback| must not be null.
62 void Copy(const base::FilePath& src_file_path,
63 const base::FilePath& dest_file_path,
64 bool preserve_last_modified,
65 const FileOperationCallback& callback);
67 // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|.
68 // |local_src_file_path| must be a file from the local file system.
69 // |remote_dest_file_path| is the virtual destination path within Drive file
70 // system.
72 // |callback| must not be null.
73 void TransferFileFromLocalToRemote(
74 const base::FilePath& local_src_file_path,
75 const base::FilePath& remote_dest_file_path,
76 const FileOperationCallback& callback);
78 // Params for Copy().
79 struct CopyParams;
81 // Params for TransferJsonGdocFileAfterLocalWork.
82 struct TransferJsonGdocParams;
84 private:
85 // Part of Copy(). Called after trying to copy locally.
86 void CopyAfterTryToCopyLocally(
87 const CopyParams* params,
88 const std::vector<std::string>* updated_local_ids,
89 const bool* directory_changed,
90 const bool* should_copy_on_server,
91 FileError error);
93 // Part of Copy(). Called after the parent entry gets synced.
94 void CopyAfterParentSync(const CopyParams& params, FileError error);
96 // Part of Copy(). Called after the parent resource ID is resolved.
97 void CopyAfterGetParentResourceId(const CopyParams& params,
98 const ResourceEntry* parent,
99 FileError error);
101 // Part of TransferFileFromLocalToRemote(). Called after preparation is done.
102 // |gdoc_resource_id| and |parent_resource_id| is available only if the file
103 // is JSON GDoc file.
104 void TransferFileFromLocalToRemoteAfterPrepare(
105 const base::FilePath& local_src_path,
106 const base::FilePath& remote_dest_path,
107 const FileOperationCallback& callback,
108 std::string* gdoc_resource_id,
109 ResourceEntry* parent_entry,
110 FileError error);
112 // Part of TransferFileFromLocalToRemote().
113 void TransferJsonGdocFileAfterLocalWork(TransferJsonGdocParams* params,
114 FileError error);
116 // Copies resource with |resource_id| into the directory |parent_resource_id|
117 // with renaming it to |new_title|.
118 void CopyResourceOnServer(const std::string& resource_id,
119 const std::string& parent_resource_id,
120 const std::string& new_title,
121 const base::Time& last_modified,
122 const FileOperationCallback& callback);
124 // Part of CopyResourceOnServer and TransferFileFromLocalToRemote.
125 // Called after server side operation is done.
126 void UpdateAfterServerSideOperation(
127 const FileOperationCallback& callback,
128 google_apis::DriveApiErrorCode status,
129 scoped_ptr<google_apis::FileResource> entry);
131 // Part of CopyResourceOnServer and TransferFileFromLocalToRemote.
132 // Called after local state update is done.
133 void UpdateAfterLocalStateUpdate(const FileOperationCallback& callback,
134 base::FilePath* file_path,
135 const ResourceEntry* entry,
136 FileError error);
138 // Creates an empty file on the server at |remote_dest_path| to ensure
139 // the location, stores a file at |local_file_path| in cache and marks it
140 // dirty, so that SyncClient will upload the data later.
141 void ScheduleTransferRegularFile(const base::FilePath& local_src_path,
142 const base::FilePath& remote_dest_path,
143 const FileOperationCallback& callback);
145 // Part of ScheduleTransferRegularFile(). Called after file creation.
146 void ScheduleTransferRegularFileAfterCreate(
147 const base::FilePath& local_src_path,
148 const base::FilePath& remote_dest_path,
149 const FileOperationCallback& callback,
150 FileError error);
152 // Part of ScheduleTransferRegularFile(). Called after updating local state
153 // is completed.
154 void ScheduleTransferRegularFileAfterUpdateLocalState(
155 const FileOperationCallback& callback,
156 const base::FilePath& remote_dest_path,
157 const ResourceEntry* entry,
158 std::string* local_id,
159 FileError error);
161 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
162 OperationDelegate* delegate_;
163 JobScheduler* scheduler_;
164 internal::ResourceMetadata* metadata_;
165 internal::FileCache* cache_;
167 // Uploading a new file is internally implemented by creating a dirty file.
168 scoped_ptr<CreateFileOperation> create_file_operation_;
170 base::ThreadChecker thread_checker_;
172 // Note: This should remain the last member so it'll be destroyed and
173 // invalidate the weak pointers before any other members are destroyed.
174 base::WeakPtrFactory<CopyOperation> weak_ptr_factory_;
175 DISALLOW_COPY_AND_ASSIGN(CopyOperation);
178 } // namespace file_system
179 } // namespace drive
181 #endif // COMPONENTS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_