OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 void CreateFileOperation::CreateFile(const base::FilePath& file_path, | 139 void CreateFileOperation::CreateFile(const base::FilePath& file_path, |
140 bool is_exclusive, | 140 bool is_exclusive, |
141 const FileOperationCallback& callback) { | 141 const FileOperationCallback& callback) { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
143 DCHECK(!callback.is_null()); | 143 DCHECK(!callback.is_null()); |
144 | 144 |
145 std::string* parent_resource_id = new std::string; | 145 std::string* parent_resource_id = new std::string; |
146 std::string* mime_type = new std::string; | 146 std::string* mime_type = new std::string; |
147 base::PostTaskAndReplyWithResult( | 147 base::PostTaskAndReplyWithResult( |
148 blocking_task_runner_, | 148 blocking_task_runner_.get(), |
149 FROM_HERE, | 149 FROM_HERE, |
150 base::Bind(&CheckPreConditionForCreateFile, | 150 base::Bind(&CheckPreConditionForCreateFile, |
151 metadata_, file_path, is_exclusive, | 151 metadata_, |
152 parent_resource_id, mime_type), | 152 file_path, |
| 153 is_exclusive, |
| 154 parent_resource_id, |
| 155 mime_type), |
153 base::Bind(&CreateFileOperation::CreateFileAfterCheckPreCondition, | 156 base::Bind(&CreateFileOperation::CreateFileAfterCheckPreCondition, |
154 weak_ptr_factory_.GetWeakPtr(), | 157 weak_ptr_factory_.GetWeakPtr(), |
155 file_path, callback, | 158 file_path, |
156 base::Owned(parent_resource_id), base::Owned(mime_type))); | 159 callback, |
| 160 base::Owned(parent_resource_id), |
| 161 base::Owned(mime_type))); |
157 } | 162 } |
158 | 163 |
159 void CreateFileOperation::CreateFileAfterCheckPreCondition( | 164 void CreateFileOperation::CreateFileAfterCheckPreCondition( |
160 const base::FilePath& file_path, | 165 const base::FilePath& file_path, |
161 const FileOperationCallback& callback, | 166 const FileOperationCallback& callback, |
162 std::string* parent_resource_id, | 167 std::string* parent_resource_id, |
163 std::string* mime_type, | 168 std::string* mime_type, |
164 FileError error) { | 169 FileError error) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
166 DCHECK(!callback.is_null()); | 171 DCHECK(!callback.is_null()); |
(...skipping 27 matching lines...) Expand all Loading... |
194 | 199 |
195 FileError error = util::GDataToFileError(gdata_error); | 200 FileError error = util::GDataToFileError(gdata_error); |
196 if (error != FILE_ERROR_OK) { | 201 if (error != FILE_ERROR_OK) { |
197 callback.Run(error); | 202 callback.Run(error); |
198 return; | 203 return; |
199 } | 204 } |
200 DCHECK(resource_entry); | 205 DCHECK(resource_entry); |
201 | 206 |
202 base::FilePath* file_path = new base::FilePath; | 207 base::FilePath* file_path = new base::FilePath; |
203 base::PostTaskAndReplyWithResult( | 208 base::PostTaskAndReplyWithResult( |
204 blocking_task_runner_, | 209 blocking_task_runner_.get(), |
205 FROM_HERE, | 210 FROM_HERE, |
206 base::Bind(&UpdateLocalStateForCreateFile, | 211 base::Bind(&UpdateLocalStateForCreateFile, |
207 metadata_, cache_, base::Passed(&resource_entry), file_path), | 212 metadata_, |
| 213 cache_, |
| 214 base::Passed(&resource_entry), |
| 215 file_path), |
208 base::Bind(&CreateFileOperation::CreateFileAfterUpdateLocalState, | 216 base::Bind(&CreateFileOperation::CreateFileAfterUpdateLocalState, |
209 weak_ptr_factory_.GetWeakPtr(), | 217 weak_ptr_factory_.GetWeakPtr(), |
210 callback, base::Owned(file_path))); | 218 callback, |
| 219 base::Owned(file_path))); |
211 } | 220 } |
212 | 221 |
213 void CreateFileOperation::CreateFileAfterUpdateLocalState( | 222 void CreateFileOperation::CreateFileAfterUpdateLocalState( |
214 const FileOperationCallback& callback, | 223 const FileOperationCallback& callback, |
215 base::FilePath* file_path, | 224 base::FilePath* file_path, |
216 FileError error) { | 225 FileError error) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
218 DCHECK(!callback.is_null()); | 227 DCHECK(!callback.is_null()); |
219 DCHECK(file_path); | 228 DCHECK(file_path); |
220 | 229 |
221 // Notify observer if the file creation process is successfully done. | 230 // Notify observer if the file creation process is successfully done. |
222 if (error == FILE_ERROR_OK) | 231 if (error == FILE_ERROR_OK) |
223 observer_->OnDirectoryChangedByOperation(file_path->DirName()); | 232 observer_->OnDirectoryChangedByOperation(file_path->DirName()); |
224 | 233 |
225 callback.Run(error); | 234 callback.Run(error); |
226 } | 235 } |
227 | 236 |
228 } // namespace file_system | 237 } // namespace file_system |
229 } // namespace drive | 238 } // namespace drive |
OLD | NEW |