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

Side by Side Diff: webkit/browser/fileapi/file_system_context.cc

Issue 242443004: Remove thread restriction of fileapi::FileSystemContext::ResolveURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix error code in DidResolveURL Created 6 years, 8 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) 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 "webkit/browser/fileapi/file_system_context.h" 5 #include "webkit/browser/fileapi/file_system_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 46
47 void DidGetMetadataForResolveURL( 47 void DidGetMetadataForResolveURL(
48 const base::FilePath& path, 48 const base::FilePath& path,
49 const FileSystemContext::ResolveURLCallback& callback, 49 const FileSystemContext::ResolveURLCallback& callback,
50 const FileSystemInfo& info, 50 const FileSystemInfo& info,
51 base::File::Error error, 51 base::File::Error error,
52 const base::File::Info& file_info) { 52 const base::File::Info& file_info) {
53 if (error != base::File::FILE_OK) { 53 if (error != base::File::FILE_OK) {
54 callback.Run(error, FileSystemInfo(), base::FilePath(), false); 54 if (error == base::File::FILE_ERROR_NOT_FOUND) {
55 callback.Run(base::File::FILE_OK, info, path,
56 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
57 } else {
58 callback.Run(error, FileSystemInfo(), base::FilePath(),
59 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
60 }
55 return; 61 return;
56 } 62 }
57 callback.Run(error, info, path, file_info.is_directory); 63 callback.Run(error, info, path, file_info.is_directory ?
64 FileSystemContext::RESOLVED_ENTRY_DIRECTORY :
65 FileSystemContext::RESOLVED_ENTRY_FILE);
66 }
67
68 void RelayResolveURLCallback(
69 scoped_refptr<base::MessageLoopProxy> message_loop,
70 const FileSystemContext::ResolveURLCallback& callback,
71 base::File::Error result,
72 const FileSystemInfo& info,
73 const base::FilePath& file_path,
74 FileSystemContext::ResolvedEntryType type) {
75 message_loop->PostTask(
76 FROM_HERE, base::Bind(callback, result, info, file_path, type));
58 } 77 }
59 78
60 } // namespace 79 } // namespace
61 80
62 // static 81 // static
63 int FileSystemContext::GetPermissionPolicy(FileSystemType type) { 82 int FileSystemContext::GetPermissionPolicy(FileSystemType type) {
64 switch (type) { 83 switch (type) {
65 case kFileSystemTypeTemporary: 84 case kFileSystemTypeTemporary:
66 case kFileSystemTypePersistent: 85 case kFileSystemTypePersistent:
67 case kFileSystemTypeSyncable: 86 case kFileSystemTypeSyncable:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 334
316 backend->ResolveURL( 335 backend->ResolveURL(
317 CreateCrackedFileSystemURL(origin_url, type, base::FilePath()), 336 CreateCrackedFileSystemURL(origin_url, type, base::FilePath()),
318 mode, 337 mode,
319 callback); 338 callback);
320 } 339 }
321 340
322 void FileSystemContext::ResolveURL( 341 void FileSystemContext::ResolveURL(
323 const FileSystemURL& url, 342 const FileSystemURL& url,
324 const ResolveURLCallback& callback) { 343 const ResolveURLCallback& callback) {
325 // TODO(nhiroki, kinuko): Remove this thread restriction, so it can be called
326 // on either UI or IO thread.
327 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
328 DCHECK(!callback.is_null()); 344 DCHECK(!callback.is_null());
329 345
346 // If not on IO thread, forward before passing the task to the backend.
347 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
348 ResolveURLCallback relay_callback =
349 base::Bind(&RelayResolveURLCallback,
350 base::MessageLoopProxy::current(), callback);
351 io_task_runner_->PostTask(
352 FROM_HERE,
353 base::Bind(&FileSystemContext::ResolveURL, this, url, relay_callback));
354 return;
355 }
356
330 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 357 FileSystemBackend* backend = GetFileSystemBackend(url.type());
331 if (!backend) { 358 if (!backend) {
332 callback.Run(base::File::FILE_ERROR_SECURITY, 359 callback.Run(base::File::FILE_ERROR_SECURITY,
333 FileSystemInfo(), base::FilePath(), false); 360 FileSystemInfo(), base::FilePath(),
361 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
334 return; 362 return;
335 } 363 }
336 364
337 backend->ResolveURL( 365 backend->ResolveURL(
338 url, 366 url,
339 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 367 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
340 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL, 368 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL,
341 this, 369 this,
342 url, 370 url,
343 callback)); 371 callback));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 581
554 void FileSystemContext::DidOpenFileSystemForResolveURL( 582 void FileSystemContext::DidOpenFileSystemForResolveURL(
555 const FileSystemURL& url, 583 const FileSystemURL& url,
556 const FileSystemContext::ResolveURLCallback& callback, 584 const FileSystemContext::ResolveURLCallback& callback,
557 const GURL& filesystem_root, 585 const GURL& filesystem_root,
558 const std::string& filesystem_name, 586 const std::string& filesystem_name,
559 base::File::Error error) { 587 base::File::Error error) {
560 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 588 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
561 589
562 if (error != base::File::FILE_OK) { 590 if (error != base::File::FILE_OK) {
563 callback.Run(error, FileSystemInfo(), base::FilePath(), false); 591 callback.Run(error, FileSystemInfo(), base::FilePath(),
592 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
564 return; 593 return;
565 } 594 }
566 595
567 fileapi::FileSystemInfo info( 596 fileapi::FileSystemInfo info(
568 filesystem_name, filesystem_root, url.mount_type()); 597 filesystem_name, filesystem_root, url.mount_type());
569 598
570 // Extract the virtual path not containing a filesystem type part from |url|. 599 // Extract the virtual path not containing a filesystem type part from |url|.
571 base::FilePath parent = CrackURL(filesystem_root).virtual_path(); 600 base::FilePath parent = CrackURL(filesystem_root).virtual_path();
572 base::FilePath child = url.virtual_path(); 601 base::FilePath child = url.virtual_path();
573 base::FilePath path; 602 base::FilePath path;
574 603
575 if (parent.empty()) { 604 if (parent.empty()) {
576 path = child; 605 path = child;
577 } else if (parent != child) { 606 } else if (parent != child) {
578 bool result = parent.AppendRelativePath(child, &path); 607 bool result = parent.AppendRelativePath(child, &path);
579 DCHECK(result); 608 DCHECK(result);
580 } 609 }
581 610
582 operation_runner()->GetMetadata( 611 operation_runner()->GetMetadata(
583 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info)); 612 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info));
584 } 613 }
585 614
586 } // namespace fileapi 615 } // namespace fileapi
OLDNEW
« webkit/browser/fileapi/file_system_context.h ('K') | « webkit/browser/fileapi/file_system_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698