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

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

Issue 287673004: [fsp] First part of support for reading files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. 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
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"
11 #include "extensions/browser/event_router.h" 11 #include "extensions/browser/event_router.h"
12 #include "net/base/io_buffer.h"
12 13
13 namespace chromeos { 14 namespace chromeos {
14 namespace file_system_provider { 15 namespace file_system_provider {
15 namespace { 16 namespace {
16 17
17 // Adds a fake entry to the entry list. 18 // Adds a fake entry to the entry list.
18 void AddDirectoryEntry(fileapi::AsyncFileUtil::EntryList* entry_list, 19 void AddDirectoryEntry(fileapi::AsyncFileUtil::EntryList* entry_list,
19 const std::string& name, 20 const std::string& name,
20 fileapi::DirectoryEntry::DirectoryEntryType type, 21 fileapi::DirectoryEntry::DirectoryEntryType type,
21 int64 size, 22 int64 size,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 OpenFileMode mode, 123 OpenFileMode mode,
123 bool create, 124 bool create,
124 const OpenFileCallback& callback) { 125 const OpenFileCallback& callback) {
125 if (file_path.AsUTF8Unsafe() != "/hello.txt" || 126 if (file_path.AsUTF8Unsafe() != "/hello.txt" ||
126 mode == OPEN_FILE_MODE_WRITE || create) { 127 mode == OPEN_FILE_MODE_WRITE || create) {
127 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); 128 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY);
128 return; 129 return;
129 } 130 }
130 131
131 const int file_handle = ++last_file_handle_; 132 const int file_handle = ++last_file_handle_;
133 opened_files_.insert(file_handle);
132 callback.Run(file_handle, base::File::FILE_OK); 134 callback.Run(file_handle, base::File::FILE_OK);
133 } 135 }
134 136
135 void FakeProvidedFileSystem::CloseFile( 137 void FakeProvidedFileSystem::CloseFile(
136 int file_handle, 138 int file_handle,
137 const fileapi::AsyncFileUtil::StatusCallback& callback) { 139 const fileapi::AsyncFileUtil::StatusCallback& callback) {
138 const std::set<int>::iterator opened_file_it = 140 const std::set<int>::iterator opened_file_it =
139 opened_files_.find(file_handle); 141 opened_files_.find(file_handle);
140 if (opened_file_it == opened_files_.end()) { 142 if (opened_file_it == opened_files_.end()) {
141 callback.Run(base::File::FILE_ERROR_NOT_FOUND); 143 base::MessageLoopProxy::current()->PostTask(
144 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND));
142 return; 145 return;
143 } 146 }
144 147
145 opened_files_.erase(opened_file_it); 148 opened_files_.erase(opened_file_it);
146 callback.Run(base::File::FILE_OK); 149 base::MessageLoopProxy::current()->PostTask(
150 FROM_HERE, base::Bind(callback, base::File::FILE_OK));
151 }
152
153 void FakeProvidedFileSystem::ReadFile(
154 int file_handle,
155 net::IOBuffer* buffer,
156 int64 offset,
157 int length,
158 const ProvidedFileSystemInterface::ReadChunkReceivedCallback& callback) {
159 // TODO(mtomasz): Implement together with the FileStreamReader.
160 base::MessageLoopProxy::current()->PostTask(
161 FROM_HERE,
162 base::Bind(callback,
163 0 /* chunk_length */,
164 false /* has_next */,
165 base::File::FILE_ERROR_SECURITY));
147 } 166 }
148 167
149 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() 168 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
150 const { 169 const {
151 return file_system_info_; 170 return file_system_info_;
152 } 171 }
153 172
154 RequestManager* FakeProvidedFileSystem::GetRequestManager() { 173 RequestManager* FakeProvidedFileSystem::GetRequestManager() {
155 NOTREACHED(); 174 NOTREACHED();
156 return NULL; 175 return NULL;
157 } 176 }
158 177
159 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( 178 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create(
160 extensions::EventRouter* event_router, 179 extensions::EventRouter* event_router,
161 const ProvidedFileSystemInfo& file_system_info) { 180 const ProvidedFileSystemInfo& file_system_info) {
162 return new FakeProvidedFileSystem(file_system_info); 181 return new FakeProvidedFileSystem(file_system_info);
163 } 182 }
164 183
165 } // namespace file_system_provider 184 } // namespace file_system_provider
166 } // namespace chromeos 185 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698