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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 10692146: Fix more incorrect usage of BrowserContext on the FILE thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix yet another misuse Created 8 years, 5 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 "chrome/browser/chromeos/extensions/file_browser_private_api.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 result_list->Append(task); 347 result_list->Append(task);
348 } 348 }
349 } 349 }
350 350
351 } // namespace 351 } // namespace
352 352
353 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { 353 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
354 public: 354 public:
355 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( 355 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
356 RequestLocalFileSystemFunction* function, 356 RequestLocalFileSystemFunction* function,
357 Profile* profile, 357 scoped_refptr<fileapi::FileSystemContext> file_system_context,
358 int child_id, 358 int child_id,
359 scoped_refptr<const Extension> extension) { 359 scoped_refptr<const Extension> extension) {
360 return base::Bind( 360 return base::Bind(
361 &LocalFileSystemCallbackDispatcher::DidOpenFileSystem, 361 &LocalFileSystemCallbackDispatcher::DidOpenFileSystem,
362 base::Owned(new LocalFileSystemCallbackDispatcher( 362 base::Owned(new LocalFileSystemCallbackDispatcher(
363 function, profile, child_id, extension))); 363 function, file_system_context, child_id, extension)));
364 } 364 }
365 365
366 void DidOpenFileSystem(base::PlatformFileError result, 366 void DidOpenFileSystem(base::PlatformFileError result,
367 const std::string& name, 367 const std::string& name,
368 const GURL& root_path) { 368 const GURL& root_path) {
369 if (result != base::PLATFORM_FILE_OK) { 369 if (result != base::PLATFORM_FILE_OK) {
370 DidFail(result); 370 DidFail(result);
371 return; 371 return;
372 } 372 }
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 17 matching lines...) Expand all
391 BrowserThread::UI, FROM_HERE, 391 BrowserThread::UI, FROM_HERE,
392 base::Bind( 392 base::Bind(
393 &RequestLocalFileSystemFunction::RespondFailedOnUIThread, 393 &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
394 function_, 394 function_,
395 error_code)); 395 error_code));
396 } 396 }
397 397
398 private: 398 private:
399 LocalFileSystemCallbackDispatcher( 399 LocalFileSystemCallbackDispatcher(
400 RequestLocalFileSystemFunction* function, 400 RequestLocalFileSystemFunction* function,
401 Profile* profile, 401 scoped_refptr<fileapi::FileSystemContext> file_system_context,
402 int child_id, 402 int child_id,
403 scoped_refptr<const Extension> extension) 403 scoped_refptr<const Extension> extension)
404 : function_(function), 404 : function_(function),
405 profile_(profile), 405 file_system_context_(file_system_context),
406 child_id_(child_id), 406 child_id_(child_id),
407 extension_(extension) { 407 extension_(extension) {
408 DCHECK(function_); 408 DCHECK(function_);
409 } 409 }
410 410
411 // Grants file system access permissions to file browser component. 411 // Grants file system access permissions to file browser component.
412 bool SetupFileSystemAccessPermissions() { 412 bool SetupFileSystemAccessPermissions() {
413 if (!extension_.get()) 413 if (!extension_.get())
414 return false; 414 return false;
415 415
416 // Make sure that only component extension can access the entire 416 // Make sure that only component extension can access the entire
417 // local file system. 417 // local file system.
418 if (extension_->location() != Extension::COMPONENT) { 418 if (extension_->location() != Extension::COMPONENT) {
419 NOTREACHED() << "Private method access by non-component extension " 419 NOTREACHED() << "Private method access by non-component extension "
420 << extension_->id(); 420 << extension_->id();
421 return false; 421 return false;
422 } 422 }
423 423
424 fileapi::ExternalFileSystemMountPointProvider* provider = 424 fileapi::ExternalFileSystemMountPointProvider* provider =
425 BrowserContext::GetFileSystemContext(profile_)->external_provider(); 425 file_system_context_->external_provider();
426 if (!provider) 426 if (!provider)
427 return false; 427 return false;
428 428
429 // Grant full access to File API from this component extension. 429 // Grant full access to File API from this component extension.
430 provider->GrantFullAccessToExtension(extension_->id()); 430 provider->GrantFullAccessToExtension(extension_->id());
431 431
432 // Grant R/W file permissions to the renderer hosting component 432 // Grant R/W file permissions to the renderer hosting component
433 // extension for all paths exposed by our local file system provider. 433 // extension for all paths exposed by our local file system provider.
434 std::vector<FilePath> root_dirs = provider->GetRootDirectories(); 434 std::vector<FilePath> root_dirs = provider->GetRootDirectories();
435 for (std::vector<FilePath>::iterator iter = root_dirs.begin(); 435 for (std::vector<FilePath>::iterator iter = root_dirs.begin();
436 iter != root_dirs.end(); 436 iter != root_dirs.end();
437 ++iter) { 437 ++iter) {
438 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 438 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
439 child_id_, *iter, file_handler_util::GetReadWritePermissions()); 439 child_id_, *iter, file_handler_util::GetReadWritePermissions());
440 } 440 }
441 return true; 441 return true;
442 } 442 }
443 443
444 RequestLocalFileSystemFunction* function_; 444 RequestLocalFileSystemFunction* function_;
445 Profile* profile_; 445 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
446 // Renderer process id. 446 // Renderer process id.
447 int child_id_; 447 int child_id_;
448 // Extension source URL. 448 // Extension source URL.
449 scoped_refptr<const Extension> extension_; 449 scoped_refptr<const Extension> extension_;
450 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); 450 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher);
451 }; 451 };
452 452
453 void RequestLocalFileSystemFunction::RequestOnFileThread( 453 void RequestLocalFileSystemFunction::RequestOnFileThread(
454 const GURL& source_url, int child_id) { 454 scoped_refptr<fileapi::FileSystemContext> file_system_context,
455 const GURL& source_url,
456 int child_id) {
455 GURL origin_url = source_url.GetOrigin(); 457 GURL origin_url = source_url.GetOrigin();
456 BrowserContext::GetFileSystemContext(profile())->OpenFileSystem( 458 file_system_context->OpenFileSystem(
457 origin_url, fileapi::kFileSystemTypeExternal, false, // create 459 origin_url, fileapi::kFileSystemTypeExternal, false, // create
458 LocalFileSystemCallbackDispatcher::CreateCallback( 460 LocalFileSystemCallbackDispatcher::CreateCallback(
459 this, 461 this,
460 profile(), 462 file_system_context,
461 child_id, 463 child_id,
462 GetExtension())); 464 GetExtension()));
463 } 465 }
464 466
465 bool RequestLocalFileSystemFunction::RunImpl() { 467 bool RequestLocalFileSystemFunction::RunImpl() {
466 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) 468 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess())
467 return false; 469 return false;
468 470
471 scoped_refptr<fileapi::FileSystemContext> file_system_context =
472 BrowserContext::GetFileSystemContext(profile_);
469 BrowserThread::PostTask( 473 BrowserThread::PostTask(
470 BrowserThread::FILE, FROM_HERE, 474 BrowserThread::FILE, FROM_HERE,
471 base::Bind( 475 base::Bind(
472 &RequestLocalFileSystemFunction::RequestOnFileThread, 476 &RequestLocalFileSystemFunction::RequestOnFileThread,
473 this, 477 this,
478 file_system_context,
474 source_url_, 479 source_url_,
475 render_view_host()->GetProcess()->GetID())); 480 render_view_host()->GetProcess()->GetID()));
476 // Will finish asynchronously. 481 // Will finish asynchronously.
477 return true; 482 return true;
478 } 483 }
479 484
480 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( 485 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread(
481 const std::string& name, const GURL& root_path) { 486 const std::string& name, const GURL& root_path) {
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
483 // Add gdata mount point immediately when we kick of first instance of file 488 // Add gdata mount point immediately when we kick of first instance of file
(...skipping 10 matching lines...) Expand all
494 } 499 }
495 500
496 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( 501 void RequestLocalFileSystemFunction::RespondFailedOnUIThread(
497 base::PlatformFileError error_code) { 502 base::PlatformFileError error_code) {
498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
499 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); 504 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code));
500 SendResponse(false); 505 SendResponse(false);
501 } 506 }
502 507
503 bool FileWatchBrowserFunctionBase::GetLocalFilePath( 508 bool FileWatchBrowserFunctionBase::GetLocalFilePath(
509 scoped_refptr<fileapi::FileSystemContext> file_system_context,
504 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { 510 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) {
505 GURL file_origin_url; 511 GURL file_origin_url;
506 fileapi::FileSystemType type; 512 fileapi::FileSystemType type;
507 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, 513 if (!CrackFileSystemURL(file_url, &file_origin_url, &type,
508 virtual_path)) { 514 virtual_path)) {
509 return false; 515 return false;
510 } 516 }
511 if (type != fileapi::kFileSystemTypeExternal) 517 if (type != fileapi::kFileSystemTypeExternal)
512 return false; 518 return false;
513 519
514 FilePath root_path = BrowserContext::GetFileSystemContext(profile_)-> 520 FilePath root_path = file_system_context->
515 external_provider()->GetFileSystemRootPathOnFileThread( 521 external_provider()->GetFileSystemRootPathOnFileThread(
516 file_origin_url, 522 file_origin_url,
517 fileapi::kFileSystemTypeExternal, 523 fileapi::kFileSystemTypeExternal,
518 *virtual_path, 524 *virtual_path,
519 false); 525 false);
520 if (root_path == FilePath()) 526 if (root_path == FilePath())
521 return false; 527 return false;
522 528
523 *local_path = root_path.Append(*virtual_path); 529 *local_path = root_path.Append(*virtual_path);
524 return true; 530 return true;
525 } 531 }
526 532
527 void FileWatchBrowserFunctionBase::RespondOnUIThread(bool success) { 533 void FileWatchBrowserFunctionBase::RespondOnUIThread(bool success) {
528 result_.reset(Value::CreateBooleanValue(success)); 534 result_.reset(Value::CreateBooleanValue(success));
529 SendResponse(success); 535 SendResponse(success);
530 } 536 }
531 537
532 bool FileWatchBrowserFunctionBase::RunImpl() { 538 bool FileWatchBrowserFunctionBase::RunImpl() {
533 if (!render_view_host() || !render_view_host()->GetProcess()) 539 if (!render_view_host() || !render_view_host()->GetProcess())
534 return false; 540 return false;
535 541
536 // First param is url of a file to watch. 542 // First param is url of a file to watch.
537 std::string url; 543 std::string url;
538 if (!args_->GetString(0, &url) || url.empty()) 544 if (!args_->GetString(0, &url) || url.empty())
539 return false; 545 return false;
540 546
541 GURL file_watch_url(url); 547 GURL file_watch_url(url);
548 scoped_refptr<fileapi::FileSystemContext> file_system_context =
549 BrowserContext::GetFileSystemContext(profile_);
542 BrowserThread::PostTask( 550 BrowserThread::PostTask(
543 BrowserThread::FILE, FROM_HERE, 551 BrowserThread::FILE, FROM_HERE,
544 base::Bind( 552 base::Bind(
545 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, 553 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread,
546 this, 554 this,
555 file_system_context,
547 FileBrowserEventRouterFactory::GetForProfile(profile_), 556 FileBrowserEventRouterFactory::GetForProfile(profile_),
548 file_watch_url, 557 file_watch_url,
549 extension_id())); 558 extension_id()));
550 559
551 return true; 560 return true;
552 } 561 }
553 562
554 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( 563 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread(
564 scoped_refptr<fileapi::FileSystemContext> file_system_context,
555 scoped_refptr<FileBrowserEventRouter> event_router, 565 scoped_refptr<FileBrowserEventRouter> event_router,
556 const GURL& file_url, const std::string& extension_id) { 566 const GURL& file_url, const std::string& extension_id) {
557 FilePath local_path; 567 FilePath local_path;
558 FilePath virtual_path; 568 FilePath virtual_path;
559 if (!GetLocalFilePath(file_url, &local_path, &virtual_path) || 569 if (!GetLocalFilePath(
570 file_system_context, file_url, &local_path, &virtual_path) ||
560 local_path == FilePath()) { 571 local_path == FilePath()) {
561 BrowserThread::PostTask( 572 BrowserThread::PostTask(
562 BrowserThread::UI, FROM_HERE, 573 BrowserThread::UI, FROM_HERE,
563 base::Bind( 574 base::Bind(
564 &FileWatchBrowserFunctionBase::RespondOnUIThread, 575 &FileWatchBrowserFunctionBase::RespondOnUIThread,
565 this, 576 this,
566 false)); 577 false));
567 } 578 }
568 if (!PerformFileWatchOperation(event_router, 579 if (!PerformFileWatchOperation(event_router,
569 local_path, 580 local_path,
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 gdata::GDataSystemService* system_service = 2421 gdata::GDataSystemService* system_service =
2411 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2422 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2412 if (!system_service || !system_service->file_system()) 2423 if (!system_service || !system_service->file_system())
2413 return false; 2424 return false;
2414 2425
2415 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2426 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2416 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2427 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2417 2428
2418 return true; 2429 return true;
2419 } 2430 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.h ('k') | chrome/browser/chromeos/extensions/file_handler_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698