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

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

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix self-assignment 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"
11 #include "ppapi/thunk/enter.h" 11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_file_system_api.h" 12 #include "ppapi/thunk/ppb_file_system_api.h"
13 #include "ppapi/shared_impl/time_conversion.h" 13 #include "ppapi/shared_impl/time_conversion.h"
14 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
15 #include "webkit/plugins/ppapi/common.h" 15 #include "webkit/plugins/ppapi/common.h"
16 #include "webkit/plugins/ppapi/file_callbacks.h" 16 #include "webkit/plugins/ppapi/file_callbacks.h"
17 #include "webkit/plugins/ppapi/plugin_delegate.h" 17 #include "webkit/plugins/ppapi/plugin_delegate.h"
18 #include "webkit/plugins/ppapi/plugin_module.h" 18 #include "webkit/plugins/ppapi/plugin_module.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" 21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
22 #include "webkit/plugins/ppapi/resource_helper.h"
22 23
23 using ppapi::PPTimeToTime; 24 using ppapi::PPTimeToTime;
24 using ppapi::StringVar; 25 using ppapi::StringVar;
25 using ppapi::thunk::EnterResourceNoLock; 26 using ppapi::thunk::EnterResourceNoLock;
26 using ppapi::thunk::PPB_FileRef_API; 27 using ppapi::thunk::PPB_FileRef_API;
27 using ppapi::thunk::PPB_FileSystem_API; 28 using ppapi::thunk::PPB_FileSystem_API;
28 29
29 namespace webkit { 30 namespace webkit {
30 namespace ppapi { 31 namespace ppapi {
31 32
(...skipping 19 matching lines...) Expand all
51 } 52 }
52 53
53 } // namespace 54 } // namespace
54 55
55 PPB_FileRef_Impl::PPB_FileRef_Impl() 56 PPB_FileRef_Impl::PPB_FileRef_Impl()
56 : Resource(NULL), 57 : Resource(NULL),
57 file_system_(NULL) { 58 file_system_(NULL) {
58 } 59 }
59 60
60 PPB_FileRef_Impl::PPB_FileRef_Impl( 61 PPB_FileRef_Impl::PPB_FileRef_Impl(
61 PluginInstance* instance, 62 PP_Instance instance,
62 scoped_refptr<PPB_FileSystem_Impl> file_system, 63 scoped_refptr<PPB_FileSystem_Impl> file_system,
63 const std::string& validated_path) 64 const std::string& validated_path)
64 : Resource(instance), 65 : Resource(instance),
65 file_system_(file_system), 66 file_system_(file_system),
66 virtual_path_(validated_path) { 67 virtual_path_(validated_path) {
67 } 68 }
68 69
69 PPB_FileRef_Impl::PPB_FileRef_Impl(PluginInstance* instance, 70 PPB_FileRef_Impl::PPB_FileRef_Impl(PP_Instance instance,
70 const FilePath& external_file_path) 71 const FilePath& external_file_path)
71 : Resource(instance), 72 : Resource(instance),
72 file_system_(NULL), 73 file_system_(NULL),
73 system_path_(external_file_path) { 74 system_path_(external_file_path) {
74 } 75 }
75 76
76 PPB_FileRef_Impl::~PPB_FileRef_Impl() { 77 PPB_FileRef_Impl::~PPB_FileRef_Impl() {
77 } 78 }
78 79
79 // static 80 // static
80 PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, 81 PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system,
81 const char* path) { 82 const char* path) {
82 EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true); 83 EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true);
83 if (enter.failed()) 84 if (enter.failed())
84 return 0; 85 return 0;
85 86
86 PPB_FileSystem_Impl* file_system = 87 PPB_FileSystem_Impl* file_system =
87 static_cast<PPB_FileSystem_Impl*>(enter.object()); 88 static_cast<PPB_FileSystem_Impl*>(enter.object());
88 if (!file_system->instance()) 89 if (!file_system->pp_instance())
89 return 0; 90 return 0;
90 91
91 if (file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 92 if (file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
92 file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) 93 file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY)
93 return 0; 94 return 0;
94 95
95 std::string validated_path(path); 96 std::string validated_path(path);
96 if (!IsValidLocalPath(validated_path)) 97 if (!IsValidLocalPath(validated_path))
97 return 0; 98 return 0;
98 TrimTrailingSlash(&validated_path); 99 TrimTrailingSlash(&validated_path);
99 100
100 return (new PPB_FileRef_Impl(file_system->instance(), 101 return (new PPB_FileRef_Impl(file_system->pp_instance(),
101 file_system, validated_path))->GetReference(); 102 file_system, validated_path))->GetReference();
102 } 103 }
103 104
104 PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() { 105 PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() {
105 return this; 106 return this;
106 } 107 }
107 108
108 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() { 109 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() {
109 return this; 110 return this;
110 } 111 }
(...skipping 21 matching lines...) Expand all
132 #endif 133 #endif
133 } else if (virtual_path_.size() == 1 && virtual_path_[0] == '/') { 134 } else if (virtual_path_.size() == 1 && virtual_path_[0] == '/') {
134 result = virtual_path_; 135 result = virtual_path_;
135 } else { 136 } else {
136 // There should always be a leading slash at least! 137 // There should always be a leading slash at least!
137 size_t pos = virtual_path_.rfind('/'); 138 size_t pos = virtual_path_.rfind('/');
138 DCHECK(pos != std::string::npos); 139 DCHECK(pos != std::string::npos);
139 result = virtual_path_.substr(pos + 1); 140 result = virtual_path_.substr(pos + 1);
140 } 141 }
141 142
142 return StringVar::StringToPPVar(instance()->module()->pp_module(), result); 143 return StringVar::StringToPPVar(
144 ResourceHelper::GetPluginModule(this)->pp_module(), result);
143 } 145 }
144 146
145 PP_Var PPB_FileRef_Impl::GetPath() const { 147 PP_Var PPB_FileRef_Impl::GetPath() const {
146 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) 148 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
147 return PP_MakeUndefined(); 149 return PP_MakeUndefined();
148 return StringVar::StringToPPVar(instance()->module()->pp_module(), 150 return StringVar::StringToPPVar(
149 virtual_path_); 151 ResourceHelper::GetPluginModule(this)->pp_module(), virtual_path_);
150 } 152 }
151 153
152 PP_Resource PPB_FileRef_Impl::GetParent() { 154 PP_Resource PPB_FileRef_Impl::GetParent() {
153 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) 155 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
154 return 0; 156 return 0;
155 157
156 // There should always be a leading slash at least! 158 // There should always be a leading slash at least!
157 size_t pos = virtual_path_.rfind('/'); 159 size_t pos = virtual_path_.rfind('/');
158 DCHECK(pos != std::string::npos); 160 DCHECK(pos != std::string::npos);
159 161
160 // If the path is "/foo", then we want to include the slash. 162 // If the path is "/foo", then we want to include the slash.
161 if (pos == 0) 163 if (pos == 0)
162 pos++; 164 pos++;
163 std::string parent_path = virtual_path_.substr(0, pos); 165 std::string parent_path = virtual_path_.substr(0, pos);
164 166
165 scoped_refptr<PPB_FileRef_Impl> parent_ref( 167 scoped_refptr<PPB_FileRef_Impl> parent_ref(
166 new PPB_FileRef_Impl(instance(), file_system_, parent_path)); 168 new PPB_FileRef_Impl(pp_instance(), file_system_, parent_path));
167 return parent_ref->GetReference(); 169 return parent_ref->GetReference();
168 } 170 }
169 171
170 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, 172 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors,
171 PP_CompletionCallback callback) { 173 PP_CompletionCallback callback) {
172 if (!IsValidNonExternalFileSystem()) 174 if (!IsValidNonExternalFileSystem())
173 return PP_ERROR_NOACCESS; 175 return PP_ERROR_NOACCESS;
174 if (!instance()->delegate()->MakeDirectory( 176
177 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
178 if (!instance->delegate()->MakeDirectory(
175 GetFileSystemURL(), PP_ToBool(make_ancestors), 179 GetFileSystemURL(), PP_ToBool(make_ancestors),
176 new FileCallbacks(instance()->module()->AsWeakPtr(), 180 new FileCallbacks(instance->module()->AsWeakPtr(),
177 pp_resource(), callback, NULL, NULL, NULL))) 181 pp_resource(), callback, NULL, NULL, NULL)))
178 return PP_ERROR_FAILED; 182 return PP_ERROR_FAILED;
179 return PP_OK_COMPLETIONPENDING; 183 return PP_OK_COMPLETIONPENDING;
180 } 184 }
181 185
182 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, 186 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
183 PP_Time last_modified_time, 187 PP_Time last_modified_time,
184 PP_CompletionCallback callback) { 188 PP_CompletionCallback callback) {
185 if (!IsValidNonExternalFileSystem()) 189 if (!IsValidNonExternalFileSystem())
186 return PP_ERROR_NOACCESS; 190 return PP_ERROR_NOACCESS;
187 if (!instance()->delegate()->Touch( 191 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
192 if (!instance->delegate()->Touch(
188 GetFileSystemURL(), 193 GetFileSystemURL(),
189 PPTimeToTime(last_access_time), 194 PPTimeToTime(last_access_time),
190 PPTimeToTime(last_modified_time), 195 PPTimeToTime(last_modified_time),
191 new FileCallbacks(instance()->module()->AsWeakPtr(), 196 new FileCallbacks(instance->module()->AsWeakPtr(),
192 pp_resource(), callback, NULL, NULL, NULL))) 197 pp_resource(), callback, NULL, NULL, NULL)))
193 return PP_ERROR_FAILED; 198 return PP_ERROR_FAILED;
194 return PP_OK_COMPLETIONPENDING; 199 return PP_OK_COMPLETIONPENDING;
195 } 200 }
196 201
197 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { 202 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) {
198 if (!IsValidNonExternalFileSystem()) 203 if (!IsValidNonExternalFileSystem())
199 return PP_ERROR_NOACCESS; 204 return PP_ERROR_NOACCESS;
200 if (!instance()->delegate()->Delete( 205 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
206 if (!instance->delegate()->Delete(
201 GetFileSystemURL(), 207 GetFileSystemURL(),
202 new FileCallbacks(instance()->module()->AsWeakPtr(), 208 new FileCallbacks(instance->module()->AsWeakPtr(),
203 pp_resource(), callback, NULL, NULL, NULL))) 209 pp_resource(), callback, NULL, NULL, NULL)))
204 return PP_ERROR_FAILED; 210 return PP_ERROR_FAILED;
205 return PP_OK_COMPLETIONPENDING; 211 return PP_OK_COMPLETIONPENDING;
206 } 212 }
207 213
208 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, 214 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref,
209 PP_CompletionCallback callback) { 215 PP_CompletionCallback callback) {
210 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); 216 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true);
211 if (enter.failed()) 217 if (enter.failed())
212 return PP_ERROR_BADRESOURCE; 218 return PP_ERROR_BADRESOURCE;
213 PPB_FileRef_Impl* new_file_ref = 219 PPB_FileRef_Impl* new_file_ref =
214 static_cast<PPB_FileRef_Impl*>(enter.object()); 220 static_cast<PPB_FileRef_Impl*>(enter.object());
215 221
216 if (!IsValidNonExternalFileSystem() || 222 if (!IsValidNonExternalFileSystem() ||
217 file_system_.get() != new_file_ref->file_system_.get()) 223 file_system_.get() != new_file_ref->file_system_.get())
218 return PP_ERROR_NOACCESS; 224 return PP_ERROR_NOACCESS;
219 225
220 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? 226 // TODO(viettrungluu): Also cancel when the new file ref is destroyed?
221 // http://crbug.com/67624 227 // http://crbug.com/67624
222 if (!instance()->delegate()->Rename( 228 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
229 if (!instance->delegate()->Rename(
223 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), 230 GetFileSystemURL(), new_file_ref->GetFileSystemURL(),
224 new FileCallbacks(instance()->module()->AsWeakPtr(), 231 new FileCallbacks(instance->module()->AsWeakPtr(),
225 pp_resource(), callback, NULL, NULL, NULL))) 232 pp_resource(), callback, NULL, NULL, NULL)))
226 return PP_ERROR_FAILED; 233 return PP_ERROR_FAILED;
227 return PP_OK_COMPLETIONPENDING; 234 return PP_OK_COMPLETIONPENDING;
228 } 235 }
229 236
230 FilePath PPB_FileRef_Impl::GetSystemPath() const { 237 FilePath PPB_FileRef_Impl::GetSystemPath() const {
231 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { 238 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) {
232 NOTREACHED(); 239 NOTREACHED();
233 return FilePath(); 240 return FilePath();
234 } 241 }
(...skipping 16 matching lines...) Expand all
251 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); 258 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1));
252 } 259 }
253 260
254 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { 261 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const {
255 return file_system_ && file_system_->opened() && 262 return file_system_ && file_system_->opened() &&
256 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; 263 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL;
257 } 264 }
258 265
259 } // namespace ppapi 266 } // namespace ppapi
260 } // namespace webkit 267 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698