OLD | NEW |
| (Empty) |
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 #include "chrome/browser/chromeos/drive/file_system/operations.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" | |
9 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h
" | |
10 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | |
11 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | |
12 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" | |
13 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" | |
14 #include "chrome/browser/chromeos/drive/file_system/search_operation.h" | |
15 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h" | |
16 #include "chrome/browser/chromeos/drive/file_system/update_operation.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 | |
19 using content::BrowserThread; | |
20 | |
21 namespace drive { | |
22 namespace file_system { | |
23 | |
24 Operations::Operations() { | |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
26 } | |
27 | |
28 Operations::~Operations() { | |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
30 } | |
31 | |
32 void Operations::Init(OperationObserver* observer, | |
33 JobScheduler* scheduler, | |
34 internal::ResourceMetadata* metadata, | |
35 internal::FileCache* cache, | |
36 FileSystemInterface* file_system, | |
37 google_apis::DriveServiceInterface* drive_service, | |
38 base::SequencedTaskRunner* blocking_task_runner) { | |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
40 | |
41 copy_operation_.reset(new file_system::CopyOperation(blocking_task_runner, | |
42 observer, | |
43 scheduler, | |
44 metadata, | |
45 cache, | |
46 file_system, | |
47 drive_service)); | |
48 create_directory_operation_.reset(new CreateDirectoryOperation( | |
49 blocking_task_runner, | |
50 observer, | |
51 scheduler, | |
52 metadata)); | |
53 create_file_operation_.reset(new CreateFileOperation(blocking_task_runner, | |
54 observer, | |
55 scheduler, | |
56 metadata, | |
57 cache)); | |
58 move_operation_.reset( | |
59 new MoveOperation(observer, scheduler, metadata)); | |
60 remove_operation_.reset( | |
61 new RemoveOperation(observer, scheduler, metadata, cache)); | |
62 touch_operation_.reset( | |
63 new TouchOperation(blocking_task_runner, observer, scheduler, metadata)); | |
64 download_operation_.reset(new DownloadOperation( | |
65 blocking_task_runner, observer, scheduler, metadata, cache)); | |
66 update_operation_.reset(new UpdateOperation(blocking_task_runner, | |
67 observer, | |
68 scheduler, | |
69 metadata, | |
70 cache)); | |
71 search_operation_.reset( | |
72 new SearchOperation(blocking_task_runner, scheduler, metadata)); | |
73 } | |
74 | |
75 void Operations::Copy(const base::FilePath& src_file_path, | |
76 const base::FilePath& dest_file_path, | |
77 const FileOperationCallback& callback) { | |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
79 DCHECK(!callback.is_null()); | |
80 | |
81 copy_operation_->Copy(src_file_path, dest_file_path, callback); | |
82 } | |
83 | |
84 void Operations::TransferFileFromRemoteToLocal( | |
85 const base::FilePath& remote_src_file_path, | |
86 const base::FilePath& local_dest_file_path, | |
87 const FileOperationCallback& callback) { | |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
89 DCHECK(!callback.is_null()); | |
90 | |
91 copy_operation_->TransferFileFromRemoteToLocal(remote_src_file_path, | |
92 local_dest_file_path, | |
93 callback); | |
94 } | |
95 | |
96 void Operations::TransferFileFromLocalToRemote( | |
97 const base::FilePath& local_src_file_path, | |
98 const base::FilePath& remote_dest_file_path, | |
99 const FileOperationCallback& callback) { | |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
101 DCHECK(!callback.is_null()); | |
102 | |
103 copy_operation_->TransferFileFromLocalToRemote(local_src_file_path, | |
104 remote_dest_file_path, | |
105 callback); | |
106 } | |
107 | |
108 void Operations::CreateDirectory(const base::FilePath& directory_path, | |
109 bool is_exclusive, | |
110 bool is_recursive, | |
111 const FileOperationCallback& callback) { | |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
113 DCHECK(!callback.is_null()); | |
114 | |
115 create_directory_operation_->CreateDirectory( | |
116 directory_path, is_exclusive, is_recursive, callback); | |
117 } | |
118 | |
119 void Operations::CreateFile(const base::FilePath& remote_file_path, | |
120 bool is_exclusive, | |
121 const FileOperationCallback& callback) { | |
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
123 DCHECK(!callback.is_null()); | |
124 | |
125 create_file_operation_->CreateFile(remote_file_path, is_exclusive, callback); | |
126 } | |
127 | |
128 void Operations::Move(const base::FilePath& src_file_path, | |
129 const base::FilePath& dest_file_path, | |
130 const FileOperationCallback& callback) { | |
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
132 DCHECK(!callback.is_null()); | |
133 | |
134 move_operation_->Move(src_file_path, dest_file_path, callback); | |
135 } | |
136 | |
137 void Operations::Remove(const base::FilePath& file_path, | |
138 bool is_recursive, | |
139 const FileOperationCallback& callback) { | |
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
141 DCHECK(!callback.is_null()); | |
142 | |
143 remove_operation_->Remove(file_path, is_recursive, callback); | |
144 } | |
145 | |
146 void Operations::TouchFile(const base::FilePath& file_path, | |
147 const base::Time& last_access_time, | |
148 const base::Time& last_modified_time, | |
149 const FileOperationCallback& callback) { | |
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
151 DCHECK(!last_access_time.is_null()); | |
152 DCHECK(!last_modified_time.is_null()); | |
153 DCHECK(!callback.is_null()); | |
154 | |
155 touch_operation_->TouchFile( | |
156 file_path, last_access_time, last_modified_time, callback); | |
157 } | |
158 | |
159 void Operations::EnsureFileDownloadedByResourceId( | |
160 const std::string& resource_id, | |
161 const ClientContext& context, | |
162 const GetFileContentInitializedCallback& initialized_callback, | |
163 const google_apis::GetContentCallback& get_content_callback, | |
164 const GetFileCallback& completion_callback) { | |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
166 DCHECK(!completion_callback.is_null()); | |
167 | |
168 download_operation_->EnsureFileDownloadedByResourceId( | |
169 resource_id, context, initialized_callback, get_content_callback, | |
170 completion_callback); | |
171 } | |
172 | |
173 void Operations::EnsureFileDownloadedByPath( | |
174 const base::FilePath& file_path, | |
175 const ClientContext& context, | |
176 const GetFileContentInitializedCallback& initialized_callback, | |
177 const google_apis::GetContentCallback& get_content_callback, | |
178 const GetFileCallback& completion_callback) { | |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
180 DCHECK(!completion_callback.is_null()); | |
181 | |
182 download_operation_->EnsureFileDownloadedByPath( | |
183 file_path, context, initialized_callback, get_content_callback, | |
184 completion_callback); | |
185 } | |
186 | |
187 void Operations::UpdateFileByResourceId( | |
188 const std::string& resource_id, | |
189 const ClientContext& context, | |
190 const FileOperationCallback& callback) { | |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
192 DCHECK(!callback.is_null()); | |
193 | |
194 update_operation_->UpdateFileByResourceId(resource_id, context, callback); | |
195 } | |
196 | |
197 void Operations::Search(const std::string& search_query, | |
198 const GURL& next_feed, | |
199 const SearchOperationCallback& callback) { | |
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
201 DCHECK(!callback.is_null()); | |
202 | |
203 search_operation_->Search(search_query, next_feed, callback); | |
204 } | |
205 | |
206 } // namespace file_system | |
207 } // namespace drive | |
OLD | NEW |