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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_ref_impl.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_file_ref_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 if (file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 91 if (file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
92 file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) 92 file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY)
93 return 0; 93 return 0;
94 94
95 std::string validated_path(path); 95 std::string validated_path(path);
96 if (!IsValidLocalPath(validated_path)) 96 if (!IsValidLocalPath(validated_path))
97 return 0; 97 return 0;
98 TrimTrailingSlash(&validated_path); 98 TrimTrailingSlash(&validated_path);
99 99
100 PPB_FileRef_Impl* file_ref = 100 return (new PPB_FileRef_Impl(file_system->instance(),
101 new PPB_FileRef_Impl(file_system->instance(), 101 file_system, validated_path))->GetReference();
102 file_system, validated_path);
103 return file_ref->GetReference();
104 } 102 }
105 103
106 PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() { 104 PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() {
107 return this; 105 return this;
108 } 106 }
109 107
110 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() { 108 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() {
111 return this; 109 return this;
112 } 110 }
113 111
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return parent_ref->GetReference(); 167 return parent_ref->GetReference();
170 } 168 }
171 169
172 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, 170 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors,
173 PP_CompletionCallback callback) { 171 PP_CompletionCallback callback) {
174 if (!IsValidNonExternalFileSystem()) 172 if (!IsValidNonExternalFileSystem())
175 return PP_ERROR_NOACCESS; 173 return PP_ERROR_NOACCESS;
176 if (!instance()->delegate()->MakeDirectory( 174 if (!instance()->delegate()->MakeDirectory(
177 GetFileSystemURL(), PP_ToBool(make_ancestors), 175 GetFileSystemURL(), PP_ToBool(make_ancestors),
178 new FileCallbacks(instance()->module()->AsWeakPtr(), 176 new FileCallbacks(instance()->module()->AsWeakPtr(),
179 GetReferenceNoAddRef(), callback, 177 pp_resource(), callback, NULL, NULL, NULL)))
180 NULL, NULL, NULL)))
181 return PP_ERROR_FAILED; 178 return PP_ERROR_FAILED;
182 return PP_OK_COMPLETIONPENDING; 179 return PP_OK_COMPLETIONPENDING;
183 } 180 }
184 181
185 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, 182 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
186 PP_Time last_modified_time, 183 PP_Time last_modified_time,
187 PP_CompletionCallback callback) { 184 PP_CompletionCallback callback) {
188 if (!IsValidNonExternalFileSystem()) 185 if (!IsValidNonExternalFileSystem())
189 return PP_ERROR_NOACCESS; 186 return PP_ERROR_NOACCESS;
190 if (!instance()->delegate()->Touch( 187 if (!instance()->delegate()->Touch(
191 GetFileSystemURL(), 188 GetFileSystemURL(),
192 PPTimeToTime(last_access_time), 189 PPTimeToTime(last_access_time),
193 PPTimeToTime(last_modified_time), 190 PPTimeToTime(last_modified_time),
194 new FileCallbacks(instance()->module()->AsWeakPtr(), 191 new FileCallbacks(instance()->module()->AsWeakPtr(),
195 GetReferenceNoAddRef(), callback, 192 pp_resource(), callback, NULL, NULL, NULL)))
196 NULL, NULL, NULL)))
197 return PP_ERROR_FAILED; 193 return PP_ERROR_FAILED;
198 return PP_OK_COMPLETIONPENDING; 194 return PP_OK_COMPLETIONPENDING;
199 } 195 }
200 196
201 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { 197 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) {
202 if (!IsValidNonExternalFileSystem()) 198 if (!IsValidNonExternalFileSystem())
203 return PP_ERROR_NOACCESS; 199 return PP_ERROR_NOACCESS;
204 if (!instance()->delegate()->Delete( 200 if (!instance()->delegate()->Delete(
205 GetFileSystemURL(), 201 GetFileSystemURL(),
206 new FileCallbacks(instance()->module()->AsWeakPtr(), 202 new FileCallbacks(instance()->module()->AsWeakPtr(),
207 GetReferenceNoAddRef(), callback, 203 pp_resource(), callback, NULL, NULL, NULL)))
208 NULL, NULL, NULL)))
209 return PP_ERROR_FAILED; 204 return PP_ERROR_FAILED;
210 return PP_OK_COMPLETIONPENDING; 205 return PP_OK_COMPLETIONPENDING;
211 } 206 }
212 207
213 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, 208 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref,
214 PP_CompletionCallback callback) { 209 PP_CompletionCallback callback) {
215 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); 210 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true);
216 if (enter.failed()) 211 if (enter.failed())
217 return PP_ERROR_BADRESOURCE; 212 return PP_ERROR_BADRESOURCE;
218 PPB_FileRef_Impl* new_file_ref = 213 PPB_FileRef_Impl* new_file_ref =
219 static_cast<PPB_FileRef_Impl*>(enter.object()); 214 static_cast<PPB_FileRef_Impl*>(enter.object());
220 215
221 if (!IsValidNonExternalFileSystem() || 216 if (!IsValidNonExternalFileSystem() ||
222 file_system_.get() != new_file_ref->file_system_.get()) 217 file_system_.get() != new_file_ref->file_system_.get())
223 return PP_ERROR_NOACCESS; 218 return PP_ERROR_NOACCESS;
224 219
225 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? 220 // TODO(viettrungluu): Also cancel when the new file ref is destroyed?
226 // http://crbug.com/67624 221 // http://crbug.com/67624
227 if (!instance()->delegate()->Rename( 222 if (!instance()->delegate()->Rename(
228 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), 223 GetFileSystemURL(), new_file_ref->GetFileSystemURL(),
229 new FileCallbacks(instance()->module()->AsWeakPtr(), 224 new FileCallbacks(instance()->module()->AsWeakPtr(),
230 GetReferenceNoAddRef(), callback, 225 pp_resource(), callback, NULL, NULL, NULL)))
231 NULL, NULL, NULL)))
232 return PP_ERROR_FAILED; 226 return PP_ERROR_FAILED;
233 return PP_OK_COMPLETIONPENDING; 227 return PP_OK_COMPLETIONPENDING;
234 } 228 }
235 229
236 FilePath PPB_FileRef_Impl::GetSystemPath() const { 230 FilePath PPB_FileRef_Impl::GetSystemPath() const {
237 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { 231 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) {
238 NOTREACHED(); 232 NOTREACHED();
239 return FilePath(); 233 return FilePath();
240 } 234 }
241 return system_path_; 235 return system_path_;
(...skipping 15 matching lines...) Expand all
257 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); 251 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1));
258 } 252 }
259 253
260 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { 254 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const {
261 return file_system_ && file_system_->opened() && 255 return file_system_ && file_system_->opened() &&
262 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; 256 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL;
263 } 257 }
264 258
265 } // namespace ppapi 259 } // namespace ppapi
266 } // namespace webkit 260 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698