| 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/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 CreateFileOperation::CreateFileOperation( | 73 CreateFileOperation::CreateFileOperation( |
| 74 base::SequencedTaskRunner* blocking_task_runner, | 74 base::SequencedTaskRunner* blocking_task_runner, |
| 75 OperationDelegate* delegate, | 75 OperationDelegate* delegate, |
| 76 internal::ResourceMetadata* metadata) | 76 internal::ResourceMetadata* metadata) |
| 77 : blocking_task_runner_(blocking_task_runner), | 77 : blocking_task_runner_(blocking_task_runner), |
| 78 delegate_(delegate), | 78 delegate_(delegate), |
| 79 metadata_(metadata), | 79 metadata_(metadata), |
| 80 weak_ptr_factory_(this) { | 80 weak_ptr_factory_(this) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 82 } | 82 } |
| 83 | 83 |
| 84 CreateFileOperation::~CreateFileOperation() { | 84 CreateFileOperation::~CreateFileOperation() { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void CreateFileOperation::CreateFile(const base::FilePath& file_path, | 88 void CreateFileOperation::CreateFile(const base::FilePath& file_path, |
| 89 bool is_exclusive, | 89 bool is_exclusive, |
| 90 const std::string& mime_type, | 90 const std::string& mime_type, |
| 91 const FileOperationCallback& callback) { | 91 const FileOperationCallback& callback) { |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 DCHECK(!callback.is_null()); | 93 DCHECK(!callback.is_null()); |
| 94 | 94 |
| 95 ResourceEntry* entry = new ResourceEntry; | 95 ResourceEntry* entry = new ResourceEntry; |
| 96 base::PostTaskAndReplyWithResult( | 96 base::PostTaskAndReplyWithResult( |
| 97 blocking_task_runner_.get(), | 97 blocking_task_runner_.get(), |
| 98 FROM_HERE, | 98 FROM_HERE, |
| 99 base::Bind(&UpdateLocalState, | 99 base::Bind(&UpdateLocalState, |
| 100 metadata_, | 100 metadata_, |
| 101 file_path, | 101 file_path, |
| 102 mime_type, | 102 mime_type, |
| 103 entry), | 103 entry), |
| 104 base::Bind(&CreateFileOperation::CreateFileAfterUpdateLocalState, | 104 base::Bind(&CreateFileOperation::CreateFileAfterUpdateLocalState, |
| 105 weak_ptr_factory_.GetWeakPtr(), | 105 weak_ptr_factory_.GetWeakPtr(), |
| 106 callback, | 106 callback, |
| 107 file_path, | 107 file_path, |
| 108 is_exclusive, | 108 is_exclusive, |
| 109 base::Owned(entry))); | 109 base::Owned(entry))); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void CreateFileOperation::CreateFileAfterUpdateLocalState( | 112 void CreateFileOperation::CreateFileAfterUpdateLocalState( |
| 113 const FileOperationCallback& callback, | 113 const FileOperationCallback& callback, |
| 114 const base::FilePath& file_path, | 114 const base::FilePath& file_path, |
| 115 bool is_exclusive, | 115 bool is_exclusive, |
| 116 ResourceEntry* entry, | 116 ResourceEntry* entry, |
| 117 FileError error) { | 117 FileError error) { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 DCHECK(!callback.is_null()); | 119 DCHECK(!callback.is_null()); |
| 120 | 120 |
| 121 if (error == FILE_ERROR_EXISTS) { | 121 if (error == FILE_ERROR_EXISTS) { |
| 122 // Error if an exclusive mode is requested, or the entry is not a file. | 122 // Error if an exclusive mode is requested, or the entry is not a file. |
| 123 error = (is_exclusive || | 123 error = (is_exclusive || |
| 124 entry->file_info().is_directory() || | 124 entry->file_info().is_directory() || |
| 125 entry->file_specific_info().is_hosted_document()) ? | 125 entry->file_specific_info().is_hosted_document()) ? |
| 126 FILE_ERROR_EXISTS : FILE_ERROR_OK; | 126 FILE_ERROR_EXISTS : FILE_ERROR_OK; |
| 127 } else if (error == FILE_ERROR_OK) { | 127 } else if (error == FILE_ERROR_OK) { |
| 128 DCHECK(!entry->file_info().is_directory()); | 128 DCHECK(!entry->file_info().is_directory()); |
| 129 | 129 |
| 130 // Notify delegate if the file was newly created. | 130 // Notify delegate if the file was newly created. |
| 131 FileChange changed_file; | 131 FileChange changed_file; |
| 132 changed_file.Update( | 132 changed_file.Update( |
| 133 file_path, FileChange::FILE_TYPE_FILE, FileChange::ADD_OR_UPDATE); | 133 file_path, FileChange::FILE_TYPE_FILE, FileChange::ADD_OR_UPDATE); |
| 134 delegate_->OnFileChangedByOperation(changed_file); | 134 delegate_->OnFileChangedByOperation(changed_file); |
| 135 // Synchronize in the background. | 135 // Synchronize in the background. |
| 136 delegate_->OnEntryUpdatedByOperation(ClientContext(BACKGROUND), | 136 delegate_->OnEntryUpdatedByOperation(ClientContext(BACKGROUND), |
| 137 entry->local_id()); | 137 entry->local_id()); |
| 138 } | 138 } |
| 139 callback.Run(error); | 139 callback.Run(error); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace file_system | 142 } // namespace file_system |
| 143 } // namespace drive | 143 } // namespace drive |
| OLD | NEW |