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

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

Issue 279213002: [fsp] Add support for closing 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"
(...skipping 14 matching lines...) Expand all
25 &last_modified_time); 25 &last_modified_time);
26 DCHECK(result); 26 DCHECK(result);
27 entry_list->push_back( 27 entry_list->push_back(
28 fileapi::DirectoryEntry(name, type, size, last_modified_time)); 28 fileapi::DirectoryEntry(name, type, size, last_modified_time));
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 FakeProvidedFileSystem::FakeProvidedFileSystem( 33 FakeProvidedFileSystem::FakeProvidedFileSystem(
34 const ProvidedFileSystemInfo& file_system_info) 34 const ProvidedFileSystemInfo& file_system_info)
35 : file_system_info_(file_system_info) { 35 : file_system_info_(file_system_info), last_file_handle_(0) {
36 } 36 }
37 37
38 FakeProvidedFileSystem::~FakeProvidedFileSystem() {} 38 FakeProvidedFileSystem::~FakeProvidedFileSystem() {}
39 39
40 void FakeProvidedFileSystem::RequestUnmount( 40 void FakeProvidedFileSystem::RequestUnmount(
41 const fileapi::AsyncFileUtil::StatusCallback& callback) { 41 const fileapi::AsyncFileUtil::StatusCallback& callback) {
42 base::MessageLoopProxy::current()->PostTask( 42 base::MessageLoopProxy::current()->PostTask(
43 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); 43 FROM_HERE, base::Bind(callback, base::File::FILE_OK));
44 } 44 }
45 45
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 0 /* size */, 111 0 /* size */,
112 "Tue May 22 00:40:50 UTC 2014"); 112 "Tue May 22 00:40:50 UTC 2014");
113 113
114 base::MessageLoopProxy::current()->PostTask( 114 base::MessageLoopProxy::current()->PostTask(
115 FROM_HERE, 115 FROM_HERE,
116 base::Bind( 116 base::Bind(
117 callback, base::File::FILE_OK, entry_list, false /* has_more */)); 117 callback, base::File::FILE_OK, entry_list, false /* has_more */));
118 } 118 }
119 } 119 }
120 120
121 void FakeProvidedFileSystem::OpenFile( 121 void FakeProvidedFileSystem::OpenFile(const base::FilePath& file_path,
122 const base::FilePath& file_path, 122 OpenFileMode mode,
123 OpenFileMode mode, 123 bool create,
124 bool create, 124 const OpenFileCallback& callback) {
125 const fileapi::AsyncFileUtil::StatusCallback& callback) {
126 if (file_path.AsUTF8Unsafe() != "/hello.txt" || 125 if (file_path.AsUTF8Unsafe() != "/hello.txt" ||
127 mode == OPEN_FILE_MODE_WRITE || create) { 126 mode == OPEN_FILE_MODE_WRITE || create) {
128 callback.Run(base::File::FILE_ERROR_SECURITY); 127 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY);
129 return; 128 return;
130 } 129 }
131 130
131 const int file_handle = ++last_file_handle_;
132 callback.Run(file_handle, base::File::FILE_OK);
133 }
134
135 void FakeProvidedFileSystem::CloseFile(
136 int file_handle,
137 const fileapi::AsyncFileUtil::StatusCallback& callback) {
138 const std::set<int>::iterator opened_file_it =
139 opened_files_.find(file_handle);
140 if (opened_file_it == opened_files_.end()) {
141 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
142 return;
143 }
144
145 opened_files_.erase(opened_file_it);
132 callback.Run(base::File::FILE_OK); 146 callback.Run(base::File::FILE_OK);
133 } 147 }
134 148
135 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() 149 const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
136 const { 150 const {
137 return file_system_info_; 151 return file_system_info_;
138 } 152 }
139 153
140 RequestManager* FakeProvidedFileSystem::GetRequestManager() { 154 RequestManager* FakeProvidedFileSystem::GetRequestManager() {
141 NOTREACHED(); 155 NOTREACHED();
142 return NULL; 156 return NULL;
143 } 157 }
144 158
145 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create( 159 ProvidedFileSystemInterface* FakeProvidedFileSystem::Create(
146 extensions::EventRouter* event_router, 160 extensions::EventRouter* event_router,
147 const ProvidedFileSystemInfo& file_system_info) { 161 const ProvidedFileSystemInfo& file_system_info) {
148 return new FakeProvidedFileSystem(file_system_info); 162 return new FakeProvidedFileSystem(file_system_info);
149 } 163 }
150 164
151 } // namespace file_system_provider 165 } // namespace file_system_provider
152 } // namespace chromeos 166 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698