OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/fake_provided_file_system
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 FROM_HERE, | 139 FROM_HERE, |
140 base::Bind( | 140 base::Bind( |
141 callback, base::File::FILE_OK, entry_list, false /* has_more */)); | 141 callback, base::File::FILE_OK, entry_list, false /* has_more */)); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path, | 145 void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path, |
146 OpenFileMode mode, | 146 OpenFileMode mode, |
147 bool create, | 147 bool create, |
148 const OpenFileCallback& callback) { | 148 const OpenFileCallback& callback) { |
149 if (file_path.AsUTF8Unsafe() != "/hello.txt" || | 149 if (mode == OPEN_FILE_MODE_WRITE || create) { |
150 mode == OPEN_FILE_MODE_WRITE || create) { | 150 base::MessageLoopProxy::current()->PostTask( |
| 151 FROM_HERE, |
| 152 base::Bind(callback, |
| 153 0 /* file_handle */, |
| 154 base::File::FILE_ERROR_ACCESS_DENIED)); |
| 155 } |
| 156 |
| 157 if (file_path.AsUTF8Unsafe() != "/hello.txt") { |
151 base::MessageLoopProxy::current()->PostTask( | 158 base::MessageLoopProxy::current()->PostTask( |
152 FROM_HERE, | 159 FROM_HERE, |
153 base::Bind( | 160 base::Bind( |
154 callback, 0 /* file_handle */, base::File::FILE_ERROR_SECURITY)); | 161 callback, 0 /* file_handle */, base::File::FILE_ERROR_NOT_FOUND)); |
155 return; | 162 return; |
156 } | 163 } |
157 | 164 |
158 const int file_handle = ++last_file_handle_; | 165 const int file_handle = ++last_file_handle_; |
159 opened_files_[file_handle] = file_path; | 166 opened_files_[file_handle] = file_path; |
160 base::MessageLoopProxy::current()->PostTask( | 167 base::MessageLoopProxy::current()->PostTask( |
161 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK)); | 168 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK)); |
162 } | 169 } |
163 | 170 |
164 void FakeProvidedFileSystem::CloseFile( | 171 void FakeProvidedFileSystem::CloseFile( |
(...skipping 20 matching lines...) Expand all Loading... |
185 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { | 192 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) { |
186 const OpenedFilesMap::iterator opened_file_it = | 193 const OpenedFilesMap::iterator opened_file_it = |
187 opened_files_.find(file_handle); | 194 opened_files_.find(file_handle); |
188 if (opened_file_it == opened_files_.end() || | 195 if (opened_file_it == opened_files_.end() || |
189 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { | 196 opened_file_it->second.AsUTF8Unsafe() != kFakeFilePath) { |
190 base::MessageLoopProxy::current()->PostTask( | 197 base::MessageLoopProxy::current()->PostTask( |
191 FROM_HERE, | 198 FROM_HERE, |
192 base::Bind(callback, | 199 base::Bind(callback, |
193 0 /* chunk_length */, | 200 0 /* chunk_length */, |
194 false /* has_next */, | 201 false /* has_next */, |
195 base::File::FILE_ERROR_SECURITY)); | 202 base::File::FILE_ERROR_INVALID_OPERATION)); |
196 return; | 203 return; |
197 } | 204 } |
198 | 205 |
199 // Send the response byte by byte. | 206 // Send the response byte by byte. |
200 size_t current_offset = static_cast<size_t>(offset); | 207 size_t current_offset = static_cast<size_t>(offset); |
201 size_t current_length = static_cast<size_t>(length); | 208 size_t current_length = static_cast<size_t>(length); |
202 | 209 |
203 // Reading behind EOF is fine, it will just return 0 bytes. | 210 // Reading behind EOF is fine, it will just return 0 bytes. |
204 if (current_offset >= kFakeFileSize || !current_length) { | 211 if (current_offset >= kFakeFileSize || !current_length) { |
205 base::MessageLoopProxy::current()->PostTask( | 212 base::MessageLoopProxy::current()->PostTask( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return new FakeProvidedFileSystem(file_system_info); | 246 return new FakeProvidedFileSystem(file_system_info); |
240 } | 247 } |
241 | 248 |
242 base::WeakPtr<ProvidedFileSystemInterface> | 249 base::WeakPtr<ProvidedFileSystemInterface> |
243 FakeProvidedFileSystem::GetWeakPtr() { | 250 FakeProvidedFileSystem::GetWeakPtr() { |
244 return weak_ptr_factory_.GetWeakPtr(); | 251 return weak_ptr_factory_.GetWeakPtr(); |
245 } | 252 } |
246 | 253 |
247 } // namespace file_system_provider | 254 } // namespace file_system_provider |
248 } // namespace chromeos | 255 } // namespace chromeos |
OLD | NEW |