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 CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_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 "chrome/browser/drive/drive_service_interface.h"
14 #include "google_apis/drive/gdata_errorcode.h"
18 class SequencedTaskRunner
;
22 namespace google_apis
{
25 } // namespace google_apis
34 class ResourceMetadata
;
35 } // namespace internal
37 namespace file_system
{
39 class CreateFileOperation
;
40 class OperationObserver
;
42 // This class encapsulates the drive Copy function. It is responsible for
43 // sending the request to the drive API, then updating the local state and
44 // metadata to reflect the new state.
47 CopyOperation(base::SequencedTaskRunner
* blocking_task_runner
,
48 OperationObserver
* observer
,
49 JobScheduler
* scheduler
,
50 internal::ResourceMetadata
* metadata
,
51 internal::FileCache
* cache
,
52 const ResourceIdCanonicalizer
& id_canonicalizer
);
55 // Performs the copy operation on the file at drive path |src_file_path|
56 // with a target of |dest_file_path|.
57 // If |preserve_last_modified| is set to true, this tries to preserve
58 // last modified time stamp. This is supported only on Drive API v2.
59 // Invokes |callback| when finished with the result of the operation.
60 // |callback| must not be null.
61 void Copy(const base::FilePath
& src_file_path
,
62 const base::FilePath
& dest_file_path
,
63 bool preserve_last_modified
,
64 const FileOperationCallback
& callback
);
66 // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|.
67 // |local_src_file_path| must be a file from the local file system.
68 // |remote_dest_file_path| is the virtual destination path within Drive file
71 // |callback| must not be null.
72 void TransferFileFromLocalToRemote(
73 const base::FilePath
& local_src_file_path
,
74 const base::FilePath
& remote_dest_file_path
,
75 const FileOperationCallback
& callback
);
81 // Part of Copy(). Called after prepartion is done.
82 void CopyAfterPrepare(const CopyParams
& params
,
83 ResourceEntry
* src_entry
,
84 std::string
* parent_resource_id
,
87 // Part of TransferFileFromLocalToRemote(). Called after preparation is done.
88 // |gdoc_resource_id| and |parent_resource_id| is available only if the file
90 void TransferFileFromLocalToRemoteAfterPrepare(
91 const base::FilePath
& local_src_path
,
92 const base::FilePath
& remote_dest_path
,
93 const FileOperationCallback
& callback
,
94 std::string
* gdoc_resource_id
,
95 std::string
* parent_resource_id
,
98 // Copies resource with |resource_id| into the directory |parent_resource_id|
99 // with renaming it to |new_title|.
100 void CopyResourceOnServer(const std::string
& resource_id
,
101 const std::string
& parent_resource_id
,
102 const std::string
& new_title
,
103 const base::Time
& last_modified
,
104 const FileOperationCallback
& callback
);
106 // Part of CopyResourceOnServer. Called after server side copy is done.
107 void CopyResourceOnServerAfterServerSideCopy(
108 const FileOperationCallback
& callback
,
109 google_apis::GDataErrorCode status
,
110 scoped_ptr
<google_apis::ResourceEntry
> resource_entry
);
112 // Part of CopyResourceOnServer. Called after local state update is done.
113 void CopyResourceOnServerAfterUpdateLocalState(
114 const FileOperationCallback
& callback
,
115 base::FilePath
* file_path
,
118 // Creates an empty file on the server at |remote_dest_path| to ensure
119 // the location, stores a file at |local_file_path| in cache and marks it
120 // dirty, so that SyncClient will upload the data later.
121 void ScheduleTransferRegularFile(const base::FilePath
& local_src_path
,
122 const base::FilePath
& remote_dest_path
,
123 const FileOperationCallback
& callback
);
125 // Part of ScheduleTransferRegularFile(). Called after GetFileSize() is
127 void ScheduleTransferRegularFileAfterGetFileSize(
128 const base::FilePath
& local_src_path
,
129 const base::FilePath
& remote_dest_path
,
130 const FileOperationCallback
& callback
,
131 int64 local_file_size
);
133 // Part of ScheduleTransferRegularFile(). Called after GetAboutResource()
135 void ScheduleTransferRegularFileAfterGetAboutResource(
136 const base::FilePath
& local_src_path
,
137 const base::FilePath
& remote_dest_path
,
138 const FileOperationCallback
& callback
,
139 int64 local_file_size
,
140 google_apis::GDataErrorCode status
,
141 scoped_ptr
<google_apis::AboutResource
> about_resource
);
143 // Part of ScheduleTransferRegularFile(). Called after file creation.
144 void ScheduleTransferRegularFileAfterCreate(
145 const base::FilePath
& local_src_path
,
146 const base::FilePath
& remote_dest_path
,
147 const FileOperationCallback
& callback
,
150 // Part of ScheduleTransferRegularFile(). Called after updating local state
152 void ScheduleTransferRegularFileAfterUpdateLocalState(
153 const FileOperationCallback
& callback
,
154 std::string
* local_id
,
157 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
158 OperationObserver
* observer_
;
159 JobScheduler
* scheduler_
;
160 internal::ResourceMetadata
* metadata_
;
161 internal::FileCache
* cache_
;
162 ResourceIdCanonicalizer id_canonicalizer_
;
164 // Uploading a new file is internally implemented by creating a dirty file.
165 scoped_ptr
<CreateFileOperation
> create_file_operation_
;
167 // Note: This should remain the last member so it'll be destroyed and
168 // invalidate the weak pointers before any other members are destroyed.
169 base::WeakPtrFactory
<CopyOperation
> weak_ptr_factory_
;
170 DISALLOW_COPY_AND_ASSIGN(CopyOperation
);
173 } // namespace file_system
176 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_