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

Side by Side Diff: chrome/browser/file_system/file_system_backend.cc

Issue 3212002: Changes for browser-side implementation for file api.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_util_proxy.h"
6 #include "base/platform_file.h"
7 #include "chrome/browser/chrome_thread.h"
8 #include "chrome/browser/file_system/file_system_backend.h"
9 #include "chrome/browser/file_system/file_system_backend_client.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
11
12 namespace {
13 // Utility method for error conversions.
14 WebKit::WebFileError PlatformToWebkitError(base::PlatformFileError rv) {
15 switch (rv) {
16 case base::PLATFORM_FILE_ERROR_NOT_FOUND:
17 return WebKit::WebFileErrorNotFound;
18 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION:
19 case base::PLATFORM_FILE_ERROR_EXISTS:
20 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
21 return WebKit::WebFileErrorInvalidModification;
22 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
23 return WebKit::WebFileErrorInvalidModification;
24 default:
25 return WebKit::WebFileErrorNoModificationAllowed;
26 }
27 }
28 } // namespace
29
30 FileSystemBackend::FileSystemBackend()
31 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
32
33 void FileSystemBackend::set_client(FileSystemBackendClient* client) {
34 client_ = client;
35 }
36
37 void FileSystemBackend::CreateFile(const FilePath& path,
38 bool exclusive,
39 int request_id) {
40 request_id_ = request_id;
41 base::FileUtilProxy::CreateOrOpen(
42 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
43 path, base::PLATFORM_FILE_CREATE,
44 callback_factory_.NewCallback(
45 exclusive ? &FileSystemBackend::DidCreateFileExclusive
46 : &FileSystemBackend::DidCreateFileNonExclusive));
47 }
48
49 void FileSystemBackend::CreateDirectory(const FilePath& path,
50 bool exclusive,
51 int request_id) {
52 request_id_ = request_id;
53 base::FileUtilProxy::CreateDirectory(
54 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
55 path, exclusive, callback_factory_.NewCallback(
56 &FileSystemBackend::DidFinishFileOperation));
57 }
58
59 void FileSystemBackend::Copy(const FilePath& src_path,
60 const FilePath& dest_path,
61 int request_id) {
62 request_id_ = request_id;
63 base::FileUtilProxy::Copy(
64 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
65 src_path, dest_path, callback_factory_.NewCallback(
66 &FileSystemBackend::DidFinishFileOperation));
67 }
68
69 void FileSystemBackend::Move(const FilePath& src_path,
70 const FilePath& dest_path,
71 int request_id) {
72 request_id_ = request_id;
73 base::FileUtilProxy::Move(
74 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
75 src_path, dest_path, callback_factory_.NewCallback(
76 &FileSystemBackend::DidFinishFileOperation));
77 }
78
79 void FileSystemBackend::DirectoryExists(const FilePath& path, int request_id) {
80 request_id_ = request_id;
81 base::FileUtilProxy::GetFileInfo(
82 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
83 path, callback_factory_.NewCallback(
84 &FileSystemBackend::DidDirectoryExists));
85 }
86
87 void FileSystemBackend::FileExists(const FilePath& path, int request_id) {
88 request_id_ = request_id;
89 base::FileUtilProxy::GetFileInfo(
90 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
91 path, callback_factory_.NewCallback(&FileSystemBackend::DidFileExists));
92 }
93
94 void FileSystemBackend::GetMetadata(const FilePath& path, int request_id) {
95 request_id_ = request_id;
96 base::FileUtilProxy::GetFileInfo(
97 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
98 path, callback_factory_.NewCallback(&FileSystemBackend::DidGetMetadata));
99 }
100
101 void FileSystemBackend::ReadDirectory(
102 const FilePath& path, int request_id) {
103 request_id_ = request_id;
104 base::FileUtilProxy::ReadDirectory(
105 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
106 path, callback_factory_.NewCallback(
107 &FileSystemBackend::DidReadDirectory));
108 }
109
110 void FileSystemBackend::Remove(const FilePath& path, int request_id) {
111 request_id_ = request_id;
112 base::FileUtilProxy::Delete(
113 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE),
114 path, callback_factory_.NewCallback(
115 &FileSystemBackend::DidFinishFileOperation));
116 }
117
118 void FileSystemBackend::DidCreateFileExclusive(base::PlatformFileError rv,
119 base::PassPlatformFile file,
120 bool created) {
121 DidFinishFileOperation(rv);
122 }
123
124 void FileSystemBackend::DidCreateFileNonExclusive(base::PlatformFileError rv,
125 base::PassPlatformFile file,
126 bool created) {
127 // Supress the already exists error and report success.
128 if (rv == base::PLATFORM_FILE_OK ||
129 rv == base::PLATFORM_FILE_ERROR_EXISTS)
130 client_->DidSucceed(rv);
131 else
132 client_->DidFail(PlatformToWebkitError(rv), request_id_);
133 }
134
135 void FileSystemBackend::DidFinishFileOperation(base::PlatformFileError rv) {
136 DCHECK(client_);
137 if (rv == base::PLATFORM_FILE_OK)
138 client_->DidSucceed(request_id_);
139 else
140 client_->DidFail(PlatformToWebkitError(rv), request_id_);
141 }
142
143 void FileSystemBackend::DidDirectoryExists(
144 base::PlatformFileError rv, const file_util::FileInfo& file_info) {
145 DCHECK(client_);
146 if (rv == base::PLATFORM_FILE_OK) {
147 if (file_info.is_directory)
148 client_->DidSucceed(request_id_);
149 else
150 client_->DidFail(WebKit::WebFileErrorInvalidState, request_id_);
151 } else {
152 // Something else went wrong.
153 client_->DidFail(PlatformToWebkitError(rv), request_id_);
154 }
155 }
156
157 void FileSystemBackend::DidFileExists(base::PlatformFileError rv,
158 const file_util::FileInfo& file_info) {
159 DCHECK(client_);
160 if (rv == base::PLATFORM_FILE_OK) {
161 if (file_info.is_directory)
162 client_->DidFail(WebKit::WebFileErrorInvalidState, request_id_);
163 else
164 client_->DidSucceed(request_id_);
165 } else {
166 // Something else went wrong.
167 client_->DidFail(PlatformToWebkitError(rv), request_id_);
168 }
169 }
170
171 void FileSystemBackend::DidGetMetadata(base::PlatformFileError rv,
172 const file_util::FileInfo& file_info) {
173 DCHECK(client_);
174 if (rv == base::PLATFORM_FILE_OK)
175 client_->DidReadMetadata(file_info, request_id_);
176 else
177 client_->DidFail(PlatformToWebkitError(rv), request_id_);
178 }
179
180 void FileSystemBackend::DidReadDirectory(
181 base::PlatformFileError rv,
182 const std::vector<base::file_util_proxy::Entry>& entries) {
183 DCHECK(client_);
184 if (rv == base::PLATFORM_FILE_OK)
185 client_->DidReadDirectory(entries, false /* has_more */ , request_id_);
186 else
187 client_->DidFail(PlatformToWebkitError(rv), request_id_);
188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698