Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fake_provided_file_system.cc

Issue 307463002: [fsp] Polish FakeProvidedFileSystem methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (file_path.AsUTF8Unsafe() != "/hello.txt" ||
150 mode == OPEN_FILE_MODE_WRITE || create) { 150 mode == OPEN_FILE_MODE_WRITE || create) {
151 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); 151 base::MessageLoopProxy::current()->PostTask(
152 FROM_HERE,
153 base::Bind(
154 callback, 0 /* file_handle */, base::File::FILE_ERROR_SECURITY));
152 return; 155 return;
153 } 156 }
154 157
155 const int file_handle = ++last_file_handle_; 158 const int file_handle = ++last_file_handle_;
156 opened_files_[file_handle] = file_path; 159 opened_files_[file_handle] = file_path;
157 callback.Run(file_handle, base::File::FILE_OK); 160 base::MessageLoopProxy::current()->PostTask(
161 FROM_HERE, base::Bind(callback, file_handle, base::File::FILE_OK));
158 } 162 }
159 163
160 void FakeProvidedFileSystem::CloseFile( 164 void FakeProvidedFileSystem::CloseFile(
161 int file_handle, 165 int file_handle,
162 const fileapi::AsyncFileUtil::StatusCallback& callback) { 166 const fileapi::AsyncFileUtil::StatusCallback& callback) {
163 const OpenedFilesMap::iterator opened_file_it = 167 const OpenedFilesMap::iterator opened_file_it =
164 opened_files_.find(file_handle); 168 opened_files_.find(file_handle);
165 if (opened_file_it == opened_files_.end()) { 169 if (opened_file_it == opened_files_.end()) {
166 base::MessageLoopProxy::current()->PostTask( 170 base::MessageLoopProxy::current()->PostTask(
167 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); 171 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND));
(...skipping 21 matching lines...) Expand all
189 0 /* chunk_length */, 193 0 /* chunk_length */,
190 false /* has_next */, 194 false /* has_next */,
191 base::File::FILE_ERROR_SECURITY)); 195 base::File::FILE_ERROR_SECURITY));
192 return; 196 return;
193 } 197 }
194 198
195 // Send the response byte by byte. 199 // Send the response byte by byte.
196 size_t current_offset = static_cast<size_t>(offset); 200 size_t current_offset = static_cast<size_t>(offset);
197 size_t current_length = static_cast<size_t>(length); 201 size_t current_length = static_cast<size_t>(length);
198 202
199 // Reading behind EOF, is fine, it will just read 0 bytes. 203 // Reading behind EOF is fine, it will just return 0 bytes.
200 if (current_offset > kFakeFileSize || !current_length) { 204 if (current_offset >= kFakeFileSize || !current_length) {
201 base::MessageLoopProxy::current()->PostTask( 205 base::MessageLoopProxy::current()->PostTask(
202 FROM_HERE, 206 FROM_HERE,
203 base::Bind(callback, 207 base::Bind(callback,
204 0 /* chunk_length */, 208 0 /* chunk_length */,
205 false /* has_next */, 209 false /* has_next */,
206 base::File::FILE_OK)); 210 base::File::FILE_OK));
207 } 211 }
208 212
209 while (current_offset < kFakeFileSize && current_length) { 213 while (current_offset < kFakeFileSize && current_length) {
210 buffer->data()[current_offset - offset] = kFakeFileText[current_offset]; 214 buffer->data()[current_offset - offset] = kFakeFileText[current_offset];
211 const bool has_next = 215 const bool has_next =
212 (current_offset + 1 < kFakeFileSize) && (current_length - 1); 216 (current_offset + 1 < kFakeFileSize) && (current_length - 1);
213 callback.Run(1, has_next, base::File::FILE_OK); 217 base::MessageLoopProxy::current()->PostTask(
218 FROM_HERE,
219 base::Bind(
220 callback, 1 /* chunk_length */, has_next, base::File::FILE_OK));
214 current_offset++; 221 current_offset++;
215 current_length--; 222 current_length--;
216 } 223 }
217 } 224 }
218 225
219 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() 226 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
220 const { 227 const {
221 return file_system_info_; 228 return file_system_info_;
222 } 229 }
223 230
224 RequestManager* FakeProvidedFileSystem::GetRequestManager() { 231 RequestManager* FakeProvidedFileSystem::GetRequestManager() {
225 NOTREACHED(); 232 NOTREACHED();
226 return NULL; 233 return NULL;
227 } 234 }
228 235
229 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( 236 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create(
230 extensions::EventRouter* event_router, 237 extensions::EventRouter* event_router,
231 const ProvidedFileSystemInfo& file_system_info) { 238 const ProvidedFileSystemInfo& file_system_info) {
232 return new FakeProvidedFileSystem(file_system_info); 239 return new FakeProvidedFileSystem(file_system_info);
233 } 240 }
234 241
235 base::WeakPtr<ProvidedFileSystemInterface> 242 base::WeakPtr<ProvidedFileSystemInterface>
236 FakeProvidedFileSystem::GetWeakPtr() { 243 FakeProvidedFileSystem::GetWeakPtr() {
237 return weak_ptr_factory_.GetWeakPtr(); 244 return weak_ptr_factory_.GetWeakPtr();
238 } 245 }
239 246
240 } // namespace file_system_provider 247 } // namespace file_system_provider
241 } // namespace chromeos 248 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698