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

Side by Side Diff: content/browser/fileapi/fileapi_message_filter.cc

Issue 1000373002: favor DCHECK_CURRENTLY_ON for better logs in content/browser/[f-p]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/fileapi/fileapi_message_filter.h" 5 #include "content/browser/fileapi/fileapi_message_filter.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 request_context_(request_context), 99 request_context_(request_context),
100 blob_storage_context_(blob_storage_context), 100 blob_storage_context_(blob_storage_context),
101 stream_context_(stream_context) { 101 stream_context_(stream_context) {
102 DCHECK(context_); 102 DCHECK(context_);
103 DCHECK(request_context_); 103 DCHECK(request_context_);
104 DCHECK(blob_storage_context); 104 DCHECK(blob_storage_context);
105 DCHECK(stream_context); 105 DCHECK(stream_context);
106 } 106 }
107 107
108 void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) { 108 void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 109 DCHECK_CURRENTLY_ON(BrowserThread::IO);
110 110
111 if (request_context_getter_.get()) { 111 if (request_context_getter_.get()) {
112 DCHECK(!request_context_); 112 DCHECK(!request_context_);
113 request_context_ = request_context_getter_->GetURLRequestContext(); 113 request_context_ = request_context_getter_->GetURLRequestContext();
114 request_context_getter_ = NULL; 114 request_context_getter_ = NULL;
115 DCHECK(request_context_); 115 DCHECK(request_context_);
116 } 116 }
117 117
118 blob_storage_host_.reset( 118 blob_storage_host_.reset(
119 new BlobStorageHost(blob_storage_context_->context())); 119 new BlobStorageHost(blob_storage_context_->context()));
120 120
121 operation_runner_ = context_->CreateFileSystemOperationRunner(); 121 operation_runner_ = context_->CreateFileSystemOperationRunner();
122 } 122 }
123 123
124 void FileAPIMessageFilter::OnChannelClosing() { 124 void FileAPIMessageFilter::OnChannelClosing() {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 125 DCHECK_CURRENTLY_ON(BrowserThread::IO);
126 126
127 // Unregister all the blob and stream URLs that are previously registered in 127 // Unregister all the blob and stream URLs that are previously registered in
128 // this process. 128 // this process.
129 blob_storage_host_.reset(); 129 blob_storage_host_.reset();
130 for (base::hash_set<std::string>::const_iterator iter = stream_urls_.begin(); 130 for (base::hash_set<std::string>::const_iterator iter = stream_urls_.begin();
131 iter != stream_urls_.end(); ++iter) { 131 iter != stream_urls_.end(); ++iter) {
132 stream_context_->registry()->UnregisterStream(GURL(*iter)); 132 stream_context_->registry()->UnregisterStream(GURL(*iter));
133 } 133 }
134 134
135 in_transit_snapshot_files_.clear(); 135 in_transit_snapshot_files_.clear();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 FileAPIMessageFilter::~FileAPIMessageFilter() {} 199 FileAPIMessageFilter::~FileAPIMessageFilter() {}
200 200
201 void FileAPIMessageFilter::BadMessageReceived() { 201 void FileAPIMessageFilter::BadMessageReceived() {
202 RecordAction(base::UserMetricsAction("BadMessageTerminate_FAMF")); 202 RecordAction(base::UserMetricsAction("BadMessageTerminate_FAMF"));
203 BrowserMessageFilter::BadMessageReceived(); 203 BrowserMessageFilter::BadMessageReceived();
204 } 204 }
205 205
206 void FileAPIMessageFilter::OnOpenFileSystem(int request_id, 206 void FileAPIMessageFilter::OnOpenFileSystem(int request_id,
207 const GURL& origin_url, 207 const GURL& origin_url,
208 storage::FileSystemType type) { 208 storage::FileSystemType type) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK_CURRENTLY_ON(BrowserThread::IO);
210 if (type == storage::kFileSystemTypeTemporary) { 210 if (type == storage::kFileSystemTypeTemporary) {
211 RecordAction(base::UserMetricsAction("OpenFileSystemTemporary")); 211 RecordAction(base::UserMetricsAction("OpenFileSystemTemporary"));
212 } else if (type == storage::kFileSystemTypePersistent) { 212 } else if (type == storage::kFileSystemTypePersistent) {
213 RecordAction(base::UserMetricsAction("OpenFileSystemPersistent")); 213 RecordAction(base::UserMetricsAction("OpenFileSystemPersistent"));
214 } 214 }
215 storage::OpenFileSystemMode mode = 215 storage::OpenFileSystemMode mode =
216 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT; 216 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT;
217 context_->OpenFileSystem(origin_url, type, mode, base::Bind( 217 context_->OpenFileSystem(origin_url, type, mode, base::Bind(
218 &FileAPIMessageFilter::DidOpenFileSystem, this, request_id)); 218 &FileAPIMessageFilter::DidOpenFileSystem, this, request_id));
219 } 219 }
220 220
221 void FileAPIMessageFilter::OnResolveURL( 221 void FileAPIMessageFilter::OnResolveURL(
222 int request_id, 222 int request_id,
223 const GURL& filesystem_url) { 223 const GURL& filesystem_url) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 224 DCHECK_CURRENTLY_ON(BrowserThread::IO);
225 FileSystemURL url(context_->CrackURL(filesystem_url)); 225 FileSystemURL url(context_->CrackURL(filesystem_url));
226 if (!ValidateFileSystemURL(request_id, url)) 226 if (!ValidateFileSystemURL(request_id, url))
227 return; 227 return;
228 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { 228 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
229 Send(new FileSystemMsg_DidFail(request_id, 229 Send(new FileSystemMsg_DidFail(request_id,
230 base::File::FILE_ERROR_SECURITY)); 230 base::File::FILE_ERROR_SECURITY));
231 return; 231 return;
232 } 232 }
233 233
234 context_->ResolveURL(url, base::Bind( 234 context_->ResolveURL(url, base::Bind(
235 &FileAPIMessageFilter::DidResolveURL, this, request_id)); 235 &FileAPIMessageFilter::DidResolveURL, this, request_id));
236 } 236 }
237 237
238 void FileAPIMessageFilter::OnDeleteFileSystem(int request_id, 238 void FileAPIMessageFilter::OnDeleteFileSystem(int request_id,
239 const GURL& origin_url, 239 const GURL& origin_url,
240 storage::FileSystemType type) { 240 storage::FileSystemType type) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 241 DCHECK_CURRENTLY_ON(BrowserThread::IO);
242 context_->DeleteFileSystem(origin_url, type, base::Bind( 242 context_->DeleteFileSystem(origin_url, type, base::Bind(
243 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id)); 243 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id));
244 } 244 }
245 245
246 void FileAPIMessageFilter::OnMove( 246 void FileAPIMessageFilter::OnMove(
247 int request_id, const GURL& src_path, const GURL& dest_path) { 247 int request_id, const GURL& src_path, const GURL& dest_path) {
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 248 DCHECK_CURRENTLY_ON(BrowserThread::IO);
249 FileSystemURL src_url(context_->CrackURL(src_path)); 249 FileSystemURL src_url(context_->CrackURL(src_path));
250 FileSystemURL dest_url(context_->CrackURL(dest_path)); 250 FileSystemURL dest_url(context_->CrackURL(dest_path));
251 if (!ValidateFileSystemURL(request_id, src_url) || 251 if (!ValidateFileSystemURL(request_id, src_url) ||
252 !ValidateFileSystemURL(request_id, dest_url)) { 252 !ValidateFileSystemURL(request_id, dest_url)) {
253 return; 253 return;
254 } 254 }
255 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || 255 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) ||
256 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) || 256 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) ||
257 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) { 257 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) {
258 Send(new FileSystemMsg_DidFail(request_id, 258 Send(new FileSystemMsg_DidFail(request_id,
259 base::File::FILE_ERROR_SECURITY)); 259 base::File::FILE_ERROR_SECURITY));
260 return; 260 return;
261 } 261 }
262 262
263 operations_[request_id] = operation_runner()->Move( 263 operations_[request_id] = operation_runner()->Move(
264 src_url, 264 src_url,
265 dest_url, 265 dest_url,
266 storage::FileSystemOperation::OPTION_NONE, 266 storage::FileSystemOperation::OPTION_NONE,
267 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 267 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
268 } 268 }
269 269
270 void FileAPIMessageFilter::OnCopy( 270 void FileAPIMessageFilter::OnCopy(
271 int request_id, const GURL& src_path, const GURL& dest_path) { 271 int request_id, const GURL& src_path, const GURL& dest_path) {
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 272 DCHECK_CURRENTLY_ON(BrowserThread::IO);
273 FileSystemURL src_url(context_->CrackURL(src_path)); 273 FileSystemURL src_url(context_->CrackURL(src_path));
274 FileSystemURL dest_url(context_->CrackURL(dest_path)); 274 FileSystemURL dest_url(context_->CrackURL(dest_path));
275 if (!ValidateFileSystemURL(request_id, src_url) || 275 if (!ValidateFileSystemURL(request_id, src_url) ||
276 !ValidateFileSystemURL(request_id, dest_url)) { 276 !ValidateFileSystemURL(request_id, dest_url)) {
277 return; 277 return;
278 } 278 }
279 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || 279 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) ||
280 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) { 280 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) {
281 Send(new FileSystemMsg_DidFail(request_id, 281 Send(new FileSystemMsg_DidFail(request_id,
282 base::File::FILE_ERROR_SECURITY)); 282 base::File::FILE_ERROR_SECURITY));
283 return; 283 return;
284 } 284 }
285 285
286 operations_[request_id] = operation_runner()->Copy( 286 operations_[request_id] = operation_runner()->Copy(
287 src_url, 287 src_url,
288 dest_url, 288 dest_url,
289 storage::FileSystemOperation::OPTION_NONE, 289 storage::FileSystemOperation::OPTION_NONE,
290 storage::FileSystemOperationRunner::CopyProgressCallback(), 290 storage::FileSystemOperationRunner::CopyProgressCallback(),
291 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 291 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
292 } 292 }
293 293
294 void FileAPIMessageFilter::OnRemove( 294 void FileAPIMessageFilter::OnRemove(
295 int request_id, const GURL& path, bool recursive) { 295 int request_id, const GURL& path, bool recursive) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 296 DCHECK_CURRENTLY_ON(BrowserThread::IO);
297 FileSystemURL url(context_->CrackURL(path)); 297 FileSystemURL url(context_->CrackURL(path));
298 if (!ValidateFileSystemURL(request_id, url)) 298 if (!ValidateFileSystemURL(request_id, url))
299 return; 299 return;
300 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) { 300 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) {
301 Send(new FileSystemMsg_DidFail(request_id, 301 Send(new FileSystemMsg_DidFail(request_id,
302 base::File::FILE_ERROR_SECURITY)); 302 base::File::FILE_ERROR_SECURITY));
303 return; 303 return;
304 } 304 }
305 305
306 operations_[request_id] = operation_runner()->Remove( 306 operations_[request_id] = operation_runner()->Remove(
307 url, recursive, 307 url, recursive,
308 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 308 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
309 } 309 }
310 310
311 void FileAPIMessageFilter::OnReadMetadata( 311 void FileAPIMessageFilter::OnReadMetadata(
312 int request_id, const GURL& path) { 312 int request_id, const GURL& path) {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 313 DCHECK_CURRENTLY_ON(BrowserThread::IO);
314 FileSystemURL url(context_->CrackURL(path)); 314 FileSystemURL url(context_->CrackURL(path));
315 if (!ValidateFileSystemURL(request_id, url)) 315 if (!ValidateFileSystemURL(request_id, url))
316 return; 316 return;
317 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { 317 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
318 Send(new FileSystemMsg_DidFail(request_id, 318 Send(new FileSystemMsg_DidFail(request_id,
319 base::File::FILE_ERROR_SECURITY)); 319 base::File::FILE_ERROR_SECURITY));
320 return; 320 return;
321 } 321 }
322 322
323 operations_[request_id] = operation_runner()->GetMetadata( 323 operations_[request_id] = operation_runner()->GetMetadata(
324 url, base::Bind(&FileAPIMessageFilter::DidGetMetadata, this, request_id)); 324 url, base::Bind(&FileAPIMessageFilter::DidGetMetadata, this, request_id));
325 } 325 }
326 326
327 void FileAPIMessageFilter::OnCreate( 327 void FileAPIMessageFilter::OnCreate(
328 int request_id, const GURL& path, bool exclusive, 328 int request_id, const GURL& path, bool exclusive,
329 bool is_directory, bool recursive) { 329 bool is_directory, bool recursive) {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 330 DCHECK_CURRENTLY_ON(BrowserThread::IO);
331 FileSystemURL url(context_->CrackURL(path)); 331 FileSystemURL url(context_->CrackURL(path));
332 if (!ValidateFileSystemURL(request_id, url)) 332 if (!ValidateFileSystemURL(request_id, url))
333 return; 333 return;
334 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { 334 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) {
335 Send(new FileSystemMsg_DidFail(request_id, 335 Send(new FileSystemMsg_DidFail(request_id,
336 base::File::FILE_ERROR_SECURITY)); 336 base::File::FILE_ERROR_SECURITY));
337 return; 337 return;
338 } 338 }
339 339
340 if (is_directory) { 340 if (is_directory) {
341 operations_[request_id] = operation_runner()->CreateDirectory( 341 operations_[request_id] = operation_runner()->CreateDirectory(
342 url, exclusive, recursive, 342 url, exclusive, recursive,
343 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 343 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
344 } else { 344 } else {
345 operations_[request_id] = operation_runner()->CreateFile( 345 operations_[request_id] = operation_runner()->CreateFile(
346 url, exclusive, 346 url, exclusive,
347 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 347 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
348 } 348 }
349 } 349 }
350 350
351 void FileAPIMessageFilter::OnExists( 351 void FileAPIMessageFilter::OnExists(
352 int request_id, const GURL& path, bool is_directory) { 352 int request_id, const GURL& path, bool is_directory) {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 353 DCHECK_CURRENTLY_ON(BrowserThread::IO);
354 FileSystemURL url(context_->CrackURL(path)); 354 FileSystemURL url(context_->CrackURL(path));
355 if (!ValidateFileSystemURL(request_id, url)) 355 if (!ValidateFileSystemURL(request_id, url))
356 return; 356 return;
357 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { 357 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
358 Send(new FileSystemMsg_DidFail(request_id, 358 Send(new FileSystemMsg_DidFail(request_id,
359 base::File::FILE_ERROR_SECURITY)); 359 base::File::FILE_ERROR_SECURITY));
360 return; 360 return;
361 } 361 }
362 362
363 if (is_directory) { 363 if (is_directory) {
364 operations_[request_id] = operation_runner()->DirectoryExists( 364 operations_[request_id] = operation_runner()->DirectoryExists(
365 url, 365 url,
366 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 366 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
367 } else { 367 } else {
368 operations_[request_id] = operation_runner()->FileExists( 368 operations_[request_id] = operation_runner()->FileExists(
369 url, 369 url,
370 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 370 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
371 } 371 }
372 } 372 }
373 373
374 void FileAPIMessageFilter::OnReadDirectory( 374 void FileAPIMessageFilter::OnReadDirectory(
375 int request_id, const GURL& path) { 375 int request_id, const GURL& path) {
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 376 DCHECK_CURRENTLY_ON(BrowserThread::IO);
377 FileSystemURL url(context_->CrackURL(path)); 377 FileSystemURL url(context_->CrackURL(path));
378 if (!ValidateFileSystemURL(request_id, url)) 378 if (!ValidateFileSystemURL(request_id, url))
379 return; 379 return;
380 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { 380 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
381 Send(new FileSystemMsg_DidFail(request_id, 381 Send(new FileSystemMsg_DidFail(request_id,
382 base::File::FILE_ERROR_SECURITY)); 382 base::File::FILE_ERROR_SECURITY));
383 return; 383 return;
384 } 384 }
385 385
386 operations_[request_id] = operation_runner()->ReadDirectory( 386 operations_[request_id] = operation_runner()->ReadDirectory(
387 url, base::Bind(&FileAPIMessageFilter::DidReadDirectory, 387 url, base::Bind(&FileAPIMessageFilter::DidReadDirectory,
388 this, request_id)); 388 this, request_id));
389 } 389 }
390 390
391 void FileAPIMessageFilter::OnWrite( 391 void FileAPIMessageFilter::OnWrite(
392 int request_id, 392 int request_id,
393 const GURL& path, 393 const GURL& path,
394 const std::string& blob_uuid, 394 const std::string& blob_uuid,
395 int64 offset) { 395 int64 offset) {
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 396 DCHECK_CURRENTLY_ON(BrowserThread::IO);
397 if (!request_context_) { 397 if (!request_context_) {
398 // We can't write w/o a request context, trying to do so will crash. 398 // We can't write w/o a request context, trying to do so will crash.
399 NOTREACHED(); 399 NOTREACHED();
400 return; 400 return;
401 } 401 }
402 402
403 FileSystemURL url(context_->CrackURL(path)); 403 FileSystemURL url(context_->CrackURL(path));
404 if (!ValidateFileSystemURL(request_id, url)) 404 if (!ValidateFileSystemURL(request_id, url))
405 return; 405 return;
406 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { 406 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) {
(...skipping 26 matching lines...) Expand all
433 operations_[request_id] = operation_runner()->Truncate( 433 operations_[request_id] = operation_runner()->Truncate(
434 url, length, 434 url, length,
435 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 435 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
436 } 436 }
437 437
438 void FileAPIMessageFilter::OnTouchFile( 438 void FileAPIMessageFilter::OnTouchFile(
439 int request_id, 439 int request_id,
440 const GURL& path, 440 const GURL& path,
441 const base::Time& last_access_time, 441 const base::Time& last_access_time,
442 const base::Time& last_modified_time) { 442 const base::Time& last_modified_time) {
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 443 DCHECK_CURRENTLY_ON(BrowserThread::IO);
444 FileSystemURL url(context_->CrackURL(path)); 444 FileSystemURL url(context_->CrackURL(path));
445 if (!ValidateFileSystemURL(request_id, url)) 445 if (!ValidateFileSystemURL(request_id, url))
446 return; 446 return;
447 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { 447 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) {
448 Send(new FileSystemMsg_DidFail(request_id, 448 Send(new FileSystemMsg_DidFail(request_id,
449 base::File::FILE_ERROR_SECURITY)); 449 base::File::FILE_ERROR_SECURITY));
450 return; 450 return;
451 } 451 }
452 452
453 operations_[request_id] = operation_runner()->TouchFile( 453 operations_[request_id] = operation_runner()->TouchFile(
454 url, last_access_time, last_modified_time, 454 url, last_access_time, last_modified_time,
455 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 455 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
456 } 456 }
457 457
458 void FileAPIMessageFilter::OnCancel( 458 void FileAPIMessageFilter::OnCancel(
459 int request_id, 459 int request_id,
460 int request_id_to_cancel) { 460 int request_id_to_cancel) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 461 DCHECK_CURRENTLY_ON(BrowserThread::IO);
462 462
463 OperationsMap::iterator found = operations_.find(request_id_to_cancel); 463 OperationsMap::iterator found = operations_.find(request_id_to_cancel);
464 if (found != operations_.end()) { 464 if (found != operations_.end()) {
465 // The cancel will eventually send both the write failure and the cancel 465 // The cancel will eventually send both the write failure and the cancel
466 // success. 466 // success.
467 operation_runner()->Cancel( 467 operation_runner()->Cancel(
468 found->second, 468 found->second,
469 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); 469 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
470 } else { 470 } else {
471 // The write already finished; report that we failed to stop it. 471 // The write already finished; report that we failed to stop it.
472 Send(new FileSystemMsg_DidFail( 472 Send(new FileSystemMsg_DidFail(
473 request_id, base::File::FILE_ERROR_INVALID_OPERATION)); 473 request_id, base::File::FILE_ERROR_INVALID_OPERATION));
474 } 474 }
475 } 475 }
476 476
477 void FileAPIMessageFilter::OnSyncGetPlatformPath( 477 void FileAPIMessageFilter::OnSyncGetPlatformPath(
478 const GURL& path, base::FilePath* platform_path) { 478 const GURL& path, base::FilePath* platform_path) {
479 SyncGetPlatformPath(context_, process_id_, path, platform_path); 479 SyncGetPlatformPath(context_, process_id_, path, platform_path);
480 } 480 }
481 481
482 void FileAPIMessageFilter::OnCreateSnapshotFile( 482 void FileAPIMessageFilter::OnCreateSnapshotFile(
483 int request_id, const GURL& path) { 483 int request_id, const GURL& path) {
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 484 DCHECK_CURRENTLY_ON(BrowserThread::IO);
485 FileSystemURL url(context_->CrackURL(path)); 485 FileSystemURL url(context_->CrackURL(path));
486 486
487 // Make sure if this file can be read by the renderer as this is 487 // Make sure if this file can be read by the renderer as this is
488 // called when the renderer is about to create a new File object 488 // called when the renderer is about to create a new File object
489 // (for reading the file). 489 // (for reading the file).
490 if (!ValidateFileSystemURL(request_id, url)) 490 if (!ValidateFileSystemURL(request_id, url))
491 return; 491 return;
492 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { 492 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
493 Send(new FileSystemMsg_DidFail(request_id, 493 Send(new FileSystemMsg_DidFail(request_id,
494 base::File::FILE_ERROR_SECURITY)); 494 base::File::FILE_ERROR_SECURITY));
495 return; 495 return;
496 } 496 }
497 497
498 FileSystemBackend* backend = context_->GetFileSystemBackend(url.type()); 498 FileSystemBackend* backend = context_->GetFileSystemBackend(url.type());
499 if (backend->SupportsStreaming(url)) { 499 if (backend->SupportsStreaming(url)) {
500 operations_[request_id] = operation_runner()->GetMetadata( 500 operations_[request_id] = operation_runner()->GetMetadata(
501 url, 501 url,
502 base::Bind(&FileAPIMessageFilter::DidGetMetadataForStreaming, 502 base::Bind(&FileAPIMessageFilter::DidGetMetadataForStreaming,
503 this, request_id)); 503 this, request_id));
504 } else { 504 } else {
505 operations_[request_id] = operation_runner()->CreateSnapshotFile( 505 operations_[request_id] = operation_runner()->CreateSnapshotFile(
506 url, 506 url,
507 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot, 507 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot,
508 this, request_id, url)); 508 this, request_id, url));
509 } 509 }
510 } 510 }
511 511
512 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) { 512 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 513 DCHECK_CURRENTLY_ON(BrowserThread::IO);
514 in_transit_snapshot_files_.erase(request_id); 514 in_transit_snapshot_files_.erase(request_id);
515 } 515 }
516 516
517 void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) { 517 void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) {
518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 518 DCHECK_CURRENTLY_ON(BrowserThread::IO);
519 ignore_result(blob_storage_host_->StartBuildingBlob(uuid)); 519 ignore_result(blob_storage_host_->StartBuildingBlob(uuid));
520 } 520 }
521 521
522 void FileAPIMessageFilter::OnAppendBlobDataItemToBlob( 522 void FileAPIMessageFilter::OnAppendBlobDataItemToBlob(
523 const std::string& uuid, 523 const std::string& uuid,
524 const storage::DataElement& item) { 524 const storage::DataElement& item) {
525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 525 DCHECK_CURRENTLY_ON(BrowserThread::IO);
526 if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) { 526 if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) {
527 FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url())); 527 FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url()));
528 if (!FileSystemURLIsValid(context_, filesystem_url) || 528 if (!FileSystemURLIsValid(context_, filesystem_url) ||
529 !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) { 529 !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) {
530 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); 530 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid));
531 return; 531 return;
532 } 532 }
533 } 533 }
534 if (item.type() == storage::DataElement::TYPE_FILE && 534 if (item.type() == storage::DataElement::TYPE_FILE &&
535 !security_policy_->CanReadFile(process_id_, item.path())) { 535 !security_policy_->CanReadFile(process_id_, item.path())) {
(...skipping 27 matching lines...) Expand all
563 } 563 }
564 564
565 storage::DataElement item; 565 storage::DataElement item;
566 item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()), 566 item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()),
567 buffer_size); 567 buffer_size);
568 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); 568 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item));
569 } 569 }
570 570
571 void FileAPIMessageFilter::OnFinishBuildingBlob( 571 void FileAPIMessageFilter::OnFinishBuildingBlob(
572 const std::string& uuid, const std::string& content_type) { 572 const std::string& uuid, const std::string& content_type) {
573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 573 DCHECK_CURRENTLY_ON(BrowserThread::IO);
574 ignore_result(blob_storage_host_->FinishBuildingBlob(uuid, content_type)); 574 ignore_result(blob_storage_host_->FinishBuildingBlob(uuid, content_type));
575 // TODO(michaeln): check return values once blink has migrated, crbug/174200 575 // TODO(michaeln): check return values once blink has migrated, crbug/174200
576 } 576 }
577 577
578 void FileAPIMessageFilter::OnIncrementBlobRefCount(const std::string& uuid) { 578 void FileAPIMessageFilter::OnIncrementBlobRefCount(const std::string& uuid) {
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 579 DCHECK_CURRENTLY_ON(BrowserThread::IO);
580 ignore_result(blob_storage_host_->IncrementBlobRefCount(uuid)); 580 ignore_result(blob_storage_host_->IncrementBlobRefCount(uuid));
581 } 581 }
582 582
583 void FileAPIMessageFilter::OnDecrementBlobRefCount(const std::string& uuid) { 583 void FileAPIMessageFilter::OnDecrementBlobRefCount(const std::string& uuid) {
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 584 DCHECK_CURRENTLY_ON(BrowserThread::IO);
585 ignore_result(blob_storage_host_->DecrementBlobRefCount(uuid)); 585 ignore_result(blob_storage_host_->DecrementBlobRefCount(uuid));
586 } 586 }
587 587
588 void FileAPIMessageFilter::OnRegisterPublicBlobURL( 588 void FileAPIMessageFilter::OnRegisterPublicBlobURL(
589 const GURL& public_url, const std::string& uuid) { 589 const GURL& public_url, const std::string& uuid) {
590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 590 DCHECK_CURRENTLY_ON(BrowserThread::IO);
591 ignore_result(blob_storage_host_->RegisterPublicBlobURL(public_url, uuid)); 591 ignore_result(blob_storage_host_->RegisterPublicBlobURL(public_url, uuid));
592 } 592 }
593 593
594 void FileAPIMessageFilter::OnRevokePublicBlobURL(const GURL& public_url) { 594 void FileAPIMessageFilter::OnRevokePublicBlobURL(const GURL& public_url) {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 595 DCHECK_CURRENTLY_ON(BrowserThread::IO);
596 ignore_result(blob_storage_host_->RevokePublicBlobURL(public_url)); 596 ignore_result(blob_storage_host_->RevokePublicBlobURL(public_url));
597 } 597 }
598 598
599 void FileAPIMessageFilter::OnStartBuildingStream( 599 void FileAPIMessageFilter::OnStartBuildingStream(
600 const GURL& url, const std::string& content_type) { 600 const GURL& url, const std::string& content_type) {
601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 601 DCHECK_CURRENTLY_ON(BrowserThread::IO);
602 // Only an internal Blob URL is expected here. See the BlobURL of the Blink. 602 // Only an internal Blob URL is expected here. See the BlobURL of the Blink.
603 if (!StartsWithASCII( 603 if (!StartsWithASCII(
604 url.path(), "blobinternal%3A///", true /* case_sensitive */)) { 604 url.path(), "blobinternal%3A///", true /* case_sensitive */)) {
605 NOTREACHED() << "Malformed Stream URL: " << url.spec(); 605 NOTREACHED() << "Malformed Stream URL: " << url.spec();
606 BadMessageReceived(); 606 BadMessageReceived();
607 return; 607 return;
608 } 608 }
609 // Use an empty security origin for now. Stream accepts a security origin 609 // Use an empty security origin for now. Stream accepts a security origin
610 // but how it's handled is not fixed yet. 610 // but how it's handled is not fixed yet.
611 new Stream(stream_context_->registry(), 611 new Stream(stream_context_->registry(),
612 NULL /* write_observer */, 612 NULL /* write_observer */,
613 url); 613 url);
614 stream_urls_.insert(url.spec()); 614 stream_urls_.insert(url.spec());
615 } 615 }
616 616
617 void FileAPIMessageFilter::OnAppendBlobDataItemToStream( 617 void FileAPIMessageFilter::OnAppendBlobDataItemToStream(
618 const GURL& url, 618 const GURL& url,
619 const storage::DataElement& item) { 619 const storage::DataElement& item) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 620 DCHECK_CURRENTLY_ON(BrowserThread::IO);
621 621
622 scoped_refptr<Stream> stream(GetStreamForURL(url)); 622 scoped_refptr<Stream> stream(GetStreamForURL(url));
623 // Stream instances may be deleted on error. Just abort if there's no Stream 623 // Stream instances may be deleted on error. Just abort if there's no Stream
624 // instance for |url| in the registry. 624 // instance for |url| in the registry.
625 if (!stream.get()) 625 if (!stream.get())
626 return; 626 return;
627 627
628 // Data for stream is delivered as TYPE_BYTES item. 628 // Data for stream is delivered as TYPE_BYTES item.
629 if (item.type() != storage::DataElement::TYPE_BYTES) { 629 if (item.type() != storage::DataElement::TYPE_BYTES) {
630 BadMessageReceived(); 630 BadMessageReceived();
(...skipping 20 matching lines...) Expand all
651 } 651 }
652 652
653 scoped_refptr<Stream> stream(GetStreamForURL(url)); 653 scoped_refptr<Stream> stream(GetStreamForURL(url));
654 if (!stream.get()) 654 if (!stream.get())
655 return; 655 return;
656 656
657 stream->AddData(static_cast<char*>(shared_memory.memory()), buffer_size); 657 stream->AddData(static_cast<char*>(shared_memory.memory()), buffer_size);
658 } 658 }
659 659
660 void FileAPIMessageFilter::OnFlushStream(const GURL& url) { 660 void FileAPIMessageFilter::OnFlushStream(const GURL& url) {
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 661 DCHECK_CURRENTLY_ON(BrowserThread::IO);
662 scoped_refptr<Stream> stream(GetStreamForURL(url)); 662 scoped_refptr<Stream> stream(GetStreamForURL(url));
663 if (stream.get()) 663 if (stream.get())
664 stream->Flush(); 664 stream->Flush();
665 } 665 }
666 666
667 void FileAPIMessageFilter::OnFinishBuildingStream(const GURL& url) { 667 void FileAPIMessageFilter::OnFinishBuildingStream(const GURL& url) {
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 668 DCHECK_CURRENTLY_ON(BrowserThread::IO);
669 scoped_refptr<Stream> stream(GetStreamForURL(url)); 669 scoped_refptr<Stream> stream(GetStreamForURL(url));
670 if (stream.get()) 670 if (stream.get())
671 stream->Finalize(); 671 stream->Finalize();
672 } 672 }
673 673
674 void FileAPIMessageFilter::OnAbortBuildingStream(const GURL& url) { 674 void FileAPIMessageFilter::OnAbortBuildingStream(const GURL& url) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 675 DCHECK_CURRENTLY_ON(BrowserThread::IO);
676 scoped_refptr<Stream> stream(GetStreamForURL(url)); 676 scoped_refptr<Stream> stream(GetStreamForURL(url));
677 if (stream.get()) 677 if (stream.get())
678 stream->Abort(); 678 stream->Abort();
679 } 679 }
680 680
681 void FileAPIMessageFilter::OnCloneStream( 681 void FileAPIMessageFilter::OnCloneStream(
682 const GURL& url, const GURL& src_url) { 682 const GURL& url, const GURL& src_url) {
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 683 DCHECK_CURRENTLY_ON(BrowserThread::IO);
684 // Abort if there's no Stream instance for |src_url| (source Stream which 684 // Abort if there's no Stream instance for |src_url| (source Stream which
685 // we're going to make |url| point to) in the registry. 685 // we're going to make |url| point to) in the registry.
686 if (!GetStreamForURL(src_url).get()) 686 if (!GetStreamForURL(src_url).get())
687 return; 687 return;
688 688
689 stream_context_->registry()->CloneStream(url, src_url); 689 stream_context_->registry()->CloneStream(url, src_url);
690 stream_urls_.insert(url.spec()); 690 stream_urls_.insert(url.spec());
691 } 691 }
692 692
693 void FileAPIMessageFilter::OnRemoveStream(const GURL& url) { 693 void FileAPIMessageFilter::OnRemoveStream(const GURL& url) {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 694 DCHECK_CURRENTLY_ON(BrowserThread::IO);
695 695
696 if (!GetStreamForURL(url).get()) 696 if (!GetStreamForURL(url).get())
697 return; 697 return;
698 698
699 stream_context_->registry()->UnregisterStream(url); 699 stream_context_->registry()->UnregisterStream(url);
700 stream_urls_.erase(url.spec()); 700 stream_urls_.erase(url.spec());
701 } 701 }
702 702
703 void FileAPIMessageFilter::DidFinish(int request_id, 703 void FileAPIMessageFilter::DidFinish(int request_id,
704 base::File::Error result) { 704 base::File::Error result) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } else { 762 } else {
763 Send(new FileSystemMsg_DidFail(request_id, result)); 763 Send(new FileSystemMsg_DidFail(request_id, result));
764 operations_.erase(request_id); 764 operations_.erase(request_id);
765 } 765 }
766 } 766 }
767 767
768 void FileAPIMessageFilter::DidOpenFileSystem(int request_id, 768 void FileAPIMessageFilter::DidOpenFileSystem(int request_id,
769 const GURL& root, 769 const GURL& root,
770 const std::string& filesystem_name, 770 const std::string& filesystem_name,
771 base::File::Error result) { 771 base::File::Error result) {
772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 772 DCHECK_CURRENTLY_ON(BrowserThread::IO);
773 if (result == base::File::FILE_OK) { 773 if (result == base::File::FILE_OK) {
774 DCHECK(root.is_valid()); 774 DCHECK(root.is_valid());
775 Send(new FileSystemMsg_DidOpenFileSystem( 775 Send(new FileSystemMsg_DidOpenFileSystem(
776 request_id, filesystem_name, root)); 776 request_id, filesystem_name, root));
777 } else { 777 } else {
778 Send(new FileSystemMsg_DidFail(request_id, result)); 778 Send(new FileSystemMsg_DidFail(request_id, result));
779 } 779 }
780 // For OpenFileSystem we do not create a new operation, so no unregister here. 780 // For OpenFileSystem we do not create a new operation, so no unregister here.
781 } 781 }
782 782
783 void FileAPIMessageFilter::DidResolveURL( 783 void FileAPIMessageFilter::DidResolveURL(
784 int request_id, 784 int request_id,
785 base::File::Error result, 785 base::File::Error result,
786 const storage::FileSystemInfo& info, 786 const storage::FileSystemInfo& info,
787 const base::FilePath& file_path, 787 const base::FilePath& file_path,
788 storage::FileSystemContext::ResolvedEntryType type) { 788 storage::FileSystemContext::ResolvedEntryType type) {
789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 789 DCHECK_CURRENTLY_ON(BrowserThread::IO);
790 if (result == base::File::FILE_OK && 790 if (result == base::File::FILE_OK &&
791 type == storage::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND) 791 type == storage::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND)
792 result = base::File::FILE_ERROR_NOT_FOUND; 792 result = base::File::FILE_ERROR_NOT_FOUND;
793 793
794 if (result == base::File::FILE_OK) { 794 if (result == base::File::FILE_OK) {
795 DCHECK(info.root_url.is_valid()); 795 DCHECK(info.root_url.is_valid());
796 Send(new FileSystemMsg_DidResolveURL( 796 Send(new FileSystemMsg_DidResolveURL(
797 request_id, 797 request_id,
798 info, 798 info,
799 file_path, 799 file_path,
(...skipping 15 matching lines...) Expand all
815 // so no unregister here. 815 // so no unregister here.
816 } 816 }
817 817
818 void FileAPIMessageFilter::DidCreateSnapshot( 818 void FileAPIMessageFilter::DidCreateSnapshot(
819 int request_id, 819 int request_id,
820 const storage::FileSystemURL& url, 820 const storage::FileSystemURL& url,
821 base::File::Error result, 821 base::File::Error result,
822 const base::File::Info& info, 822 const base::File::Info& info,
823 const base::FilePath& platform_path, 823 const base::FilePath& platform_path,
824 const scoped_refptr<storage::ShareableFileReference>& /* unused */) { 824 const scoped_refptr<storage::ShareableFileReference>& /* unused */) {
825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 825 DCHECK_CURRENTLY_ON(BrowserThread::IO);
826 operations_.erase(request_id); 826 operations_.erase(request_id);
827 827
828 if (result != base::File::FILE_OK) { 828 if (result != base::File::FILE_OK) {
829 Send(new FileSystemMsg_DidFail(request_id, result)); 829 Send(new FileSystemMsg_DidFail(request_id, result));
830 return; 830 return;
831 } 831 }
832 832
833 scoped_refptr<storage::ShareableFileReference> file_ref = 833 scoped_refptr<storage::ShareableFileReference> file_ref =
834 storage::ShareableFileReference::Get(platform_path); 834 storage::ShareableFileReference::Get(platform_path);
835 if (!security_policy_->CanReadFile(process_id_, platform_path)) { 835 if (!security_policy_->CanReadFile(process_id_, platform_path)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 } 883 }
884 884
885 return true; 885 return true;
886 } 886 }
887 887
888 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { 888 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) {
889 return stream_context_->registry()->GetStream(url); 889 return stream_context_->registry()->GetStream(url);
890 } 890 }
891 891
892 } // namespace content 892 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/file_system_browsertest.cc ('k') | content/browser/frame_host/cross_site_transferring_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698