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

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

Issue 10823273: Integrate external mount points to IsolatedContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros test fix Created 8 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) 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "grit/generated_resources.h" 50 #include "grit/generated_resources.h"
51 #include "grit/platform_locale_settings.h" 51 #include "grit/platform_locale_settings.h"
52 #include "net/base/escape.h" 52 #include "net/base/escape.h"
53 #include "ui/base/dialogs/selected_file_info.h" 53 #include "ui/base/dialogs/selected_file_info.h"
54 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
55 #include "webkit/fileapi/file_system_context.h" 55 #include "webkit/fileapi/file_system_context.h"
56 #include "webkit/fileapi/file_system_file_util.h" 56 #include "webkit/fileapi/file_system_file_util.h"
57 #include "webkit/fileapi/file_system_mount_point_provider.h" 57 #include "webkit/fileapi/file_system_mount_point_provider.h"
58 #include "webkit/fileapi/file_system_operation_context.h" 58 #include "webkit/fileapi/file_system_operation_context.h"
59 #include "webkit/fileapi/file_system_types.h" 59 #include "webkit/fileapi/file_system_types.h"
60 #include "webkit/fileapi/file_system_url.h"
60 #include "webkit/fileapi/file_system_util.h" 61 #include "webkit/fileapi/file_system_util.h"
61 62
62 using chromeos::disks::DiskMountManager; 63 using chromeos::disks::DiskMountManager;
63 using content::BrowserContext; 64 using content::BrowserContext;
64 using content::BrowserThread; 65 using content::BrowserThread;
65 using content::ChildProcessSecurityPolicy; 66 using content::ChildProcessSecurityPolicy;
66 using content::SiteInstance; 67 using content::SiteInstance;
67 using content::WebContents; 68 using content::WebContents;
68 using extensions::Extension; 69 using extensions::Extension;
69 using file_handler_util::FileTaskExecutor; 70 using file_handler_util::FileTaskExecutor;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 gdata::GDataCache::CACHE_TYPE_PERSISTENT), 222 gdata::GDataCache::CACHE_TYPE_PERSISTENT),
222 file_handler_util::GetReadOnlyPermissions()); 223 file_handler_util::GetReadOnlyPermissions());
223 224
224 FilePath mount_point_virtual; 225 FilePath mount_point_virtual;
225 if (provider->GetVirtualPath(mount_point, &mount_point_virtual)) 226 if (provider->GetVirtualPath(mount_point, &mount_point_virtual))
226 provider->GrantFileAccessToExtension(extension_id, mount_point_virtual); 227 provider->GrantFileAccessToExtension(extension_id, mount_point_virtual);
227 } 228 }
228 229
229 // Given a file url, find the virtual FilePath associated with it. 230 // Given a file url, find the virtual FilePath associated with it.
230 FilePath GetVirtualPathFromURL(const GURL& file_url) { 231 FilePath GetVirtualPathFromURL(const GURL& file_url) {
231 FilePath virtual_path; 232 fileapi::FileSystemURL url(file_url);
232 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; 233 if (!url.is_valid() || !fileapi::IsCrosManagedFileSystemType(url.type())) {
233 GURL file_origin_url;
234 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) ||
235 type != fileapi::kFileSystemTypeExternal) {
236 NOTREACHED(); 234 NOTREACHED();
237 return FilePath(); 235 return FilePath();
238 } 236 }
239 return virtual_path; 237 return url.virtual_path();
240 } 238 }
241 239
242 // Look up apps in the registry, and collect applications that match the file 240 // Look up apps in the registry, and collect applications that match the file
243 // paths given. Returns the intersection of all available application ids in 241 // paths given. Returns the intersection of all available application ids in
244 // |available_apps| and a map of application ID to the Drive web application 242 // |available_apps| and a map of application ID to the Drive web application
245 // info collected in |app_info| so details can be collected later. The caller 243 // info collected in |app_info| so details can be collected later. The caller
246 // takes ownership of the pointers in |app_info|. 244 // takes ownership of the pointers in |app_info|.
247 void IntersectAvailableDriveTasks( 245 void IntersectAvailableDriveTasks(
248 gdata::DriveWebAppsRegistry* registry, 246 gdata::DriveWebAppsRegistry* registry,
249 const std::vector<FilePath>& file_paths, 247 const std::vector<FilePath>& file_paths,
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 494 }
497 495
498 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( 496 void RequestLocalFileSystemFunction::RespondFailedOnUIThread(
499 base::PlatformFileError error_code) { 497 base::PlatformFileError error_code) {
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
501 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); 499 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code));
502 SendResponse(false); 500 SendResponse(false);
503 } 501 }
504 502
505 bool FileWatchBrowserFunctionBase::GetLocalFilePath( 503 bool FileWatchBrowserFunctionBase::GetLocalFilePath(
506 scoped_refptr<fileapi::FileSystemContext> file_system_context,
507 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { 504 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) {
508 GURL file_origin_url; 505 fileapi::FileSystemURL url(file_url);
509 fileapi::FileSystemType type; 506 if (!url.is_valid())
510 if (!CrackFileSystemURL(file_url, &file_origin_url, &type,
511 virtual_path)) {
512 return false; 507 return false;
513 } 508 if (!fileapi::IsCrosManagedFileSystemType(url.type()))
kmadhusu 2012/08/14 18:01:13 nit: if (!url.is_valid() || !fileapi::IsCros...)
kinuko 2012/08/20 08:54:35 Done.
514 if (type != fileapi::kFileSystemTypeExternal)
515 return false; 509 return false;
516 510 *local_path = url.path();
517 FilePath root_path = file_system_context-> 511 *virtual_path = url.virtual_path();
518 external_provider()->GetFileSystemRootPathOnFileThread(
519 file_origin_url,
520 fileapi::kFileSystemTypeExternal,
521 *virtual_path,
522 false);
523 if (root_path == FilePath())
524 return false;
525
526 *local_path = root_path.Append(*virtual_path);
527 return true; 512 return true;
528 } 513 }
529 514
530 void FileWatchBrowserFunctionBase::RespondOnUIThread(bool success) { 515 void FileWatchBrowserFunctionBase::RespondOnUIThread(bool success) {
531 SetResult(Value::CreateBooleanValue(success)); 516 SetResult(Value::CreateBooleanValue(success));
532 SendResponse(success); 517 SendResponse(success);
533 } 518 }
534 519
535 bool FileWatchBrowserFunctionBase::RunImpl() { 520 bool FileWatchBrowserFunctionBase::RunImpl() {
536 if (!render_view_host() || !render_view_host()->GetProcess()) 521 if (!render_view_host() || !render_view_host()->GetProcess())
(...skipping 19 matching lines...) Expand all
556 541
557 return true; 542 return true;
558 } 543 }
559 544
560 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( 545 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread(
561 scoped_refptr<fileapi::FileSystemContext> file_system_context, 546 scoped_refptr<fileapi::FileSystemContext> file_system_context,
562 scoped_refptr<FileBrowserEventRouter> event_router, 547 scoped_refptr<FileBrowserEventRouter> event_router,
563 const GURL& file_url, const std::string& extension_id) { 548 const GURL& file_url, const std::string& extension_id) {
564 FilePath local_path; 549 FilePath local_path;
565 FilePath virtual_path; 550 FilePath virtual_path;
566 if (!GetLocalFilePath( 551 if (!GetLocalFilePath(file_url, &local_path, &virtual_path) ||
567 file_system_context, file_url, &local_path, &virtual_path) ||
568 local_path == FilePath()) { 552 local_path == FilePath()) {
569 BrowserThread::PostTask( 553 BrowserThread::PostTask(
570 BrowserThread::UI, FROM_HERE, 554 BrowserThread::UI, FROM_HERE,
571 base::Bind( 555 base::Bind(
572 &FileWatchBrowserFunctionBase::RespondOnUIThread, 556 &FileWatchBrowserFunctionBase::RespondOnUIThread,
573 this, 557 this,
574 false)); 558 false));
575 } 559 }
576 if (!PerformFileWatchOperation(event_router, 560 if (!PerformFileWatchOperation(event_router,
577 local_path, 561 local_path,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // from drive. We'll know that they are drive apps because the extension id will 596 // from drive. We'll know that they are drive apps because the extension id will
613 // begin with kDriveTaskExtensionPrefix. 597 // begin with kDriveTaskExtensionPrefix.
614 bool GetFileTasksFileBrowserFunction::FindDriveAppTasks( 598 bool GetFileTasksFileBrowserFunction::FindDriveAppTasks(
615 const std::vector<GURL>& file_urls, 599 const std::vector<GURL>& file_urls,
616 ListValue* result_list) { 600 ListValue* result_list) {
617 601
618 // Crack all the urls into file paths. 602 // Crack all the urls into file paths.
619 std::vector<FilePath> file_paths; 603 std::vector<FilePath> file_paths;
620 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); 604 for (std::vector<GURL>::const_iterator iter = file_urls.begin();
621 iter != file_urls.end(); ++iter) { 605 iter != file_urls.end(); ++iter) {
622 FilePath raw_path; 606 fileapi::FileSystemURL url(*iter);
623 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; 607 if (url.is_valid() && fileapi::IsCrosManagedFileSystemType(url.type()))
624 if (fileapi::CrackFileSystemURL(*iter, NULL, &type, &raw_path) && 608 file_paths.push_back(url.virtual_path());
625 type == fileapi::kFileSystemTypeExternal) {
626 file_paths.push_back(raw_path);
627 }
628 } 609 }
629 610
630 gdata::GDataSystemService* system_service = 611 gdata::GDataSystemService* system_service =
631 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 612 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
632 // |system_service| is NULL if incognito window / guest login. We return true 613 // |system_service| is NULL if incognito window / guest login. We return true
633 // in this case because there might be other extension tasks, even if we don't 614 // in this case because there might be other extension tasks, even if we don't
634 // have any to add. 615 // have any to add.
635 if (!system_service || !system_service->webapps_registry()) 616 if (!system_service || !system_service->webapps_registry())
636 return true; 617 return true;
637 618
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 base::Bind( 809 base::Bind(
829 &FileBrowserFunction::GetLocalPathsOnFileThread, 810 &FileBrowserFunction::GetLocalPathsOnFileThread,
830 this, 811 this,
831 file_system_context, file_urls, callback)); 812 file_system_context, file_urls, callback));
832 } 813 }
833 814
834 // GetFileSystemRootPathOnFileThread can only be called from the file thread, 815 // GetFileSystemRootPathOnFileThread can only be called from the file thread,
835 // so here we are. This function takes a vector of virtual paths, converts 816 // so here we are. This function takes a vector of virtual paths, converts
836 // them to local paths and calls |callback| with the result vector, on the UI 817 // them to local paths and calls |callback| with the result vector, on the UI
837 // thread. 818 // thread.
819 // TODO(kinuko): We no longer call GetFileSystemRootPathOnFileThread and
820 // we can likely remove this cross-thread helper method.
838 void FileBrowserFunction::GetLocalPathsOnFileThread( 821 void FileBrowserFunction::GetLocalPathsOnFileThread(
839 scoped_refptr<fileapi::FileSystemContext> file_system_context, 822 scoped_refptr<fileapi::FileSystemContext> file_system_context,
840 const UrlList& file_urls, 823 const UrlList& file_urls,
841 GetLocalPathsCallback callback) { 824 GetLocalPathsCallback callback) {
842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
843 std::vector<ui::SelectedFileInfo> selected_files; 826 std::vector<ui::SelectedFileInfo> selected_files;
844 827
845 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS.
846 fileapi::ExternalFileSystemMountPointProvider* provider =
847 file_system_context->external_provider();
848 if (!provider) {
849 LOG(WARNING) << "External provider is not available";
850 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
851 base::Bind(callback, selected_files));
852 return;
853 }
854
855 GURL origin_url = source_url().GetOrigin(); 828 GURL origin_url = source_url().GetOrigin();
856 size_t len = file_urls.size(); 829 size_t len = file_urls.size();
857 selected_files.reserve(len); 830 selected_files.reserve(len);
858 for (size_t i = 0; i < len; ++i) { 831 for (size_t i = 0; i < len; ++i) {
859 FilePath local_path; 832 FilePath local_path;
860 const GURL& file_url = file_urls[i]; 833 const GURL& file_url = file_urls[i];
861 834
862 // If "localPath" parameter is set, use it as the real path. 835 // If "localPath" parameter is set, use it as the real path.
863 // TODO(satorux): Eventually, we should be able to get the real path 836 // TODO(satorux): Eventually, we should be able to get the real path
864 // from GDataFileSystem instead of passing through with filesystem 837 // from GDataFileSystem instead of passing through with filesystem
(...skipping 14 matching lines...) Expand all
879 net::UnescapeURLComponent(parameters[i].second, 852 net::UnescapeURLComponent(parameters[i].second,
880 kUnescapeRuleForQueryParameters); 853 kUnescapeRuleForQueryParameters);
881 local_path = FilePath::FromUTF8Unsafe(unescaped_value); 854 local_path = FilePath::FromUTF8Unsafe(unescaped_value);
882 break; 855 break;
883 } 856 }
884 } 857 }
885 } 858 }
886 } 859 }
887 860
888 // Extract the path from |file_url|. 861 // Extract the path from |file_url|.
889 GURL file_origin_url; 862 fileapi::FileSystemURL url(file_url);
890 FilePath virtual_path; 863 if (!url.is_valid())
891 fileapi::FileSystemType type;
892
893 if (!CrackFileSystemURL(file_url, &file_origin_url, &type,
894 &virtual_path)) {
895 continue; 864 continue;
896 } 865 if (!fileapi::IsCrosManagedFileSystemType(url.type())) {
897 if (type != fileapi::kFileSystemTypeExternal) {
898 NOTREACHED(); 866 NOTREACHED();
899 continue; 867 continue;
900 } 868 }
901 869
902 FilePath root = provider->GetFileSystemRootPathOnFileThread( 870 if (!url.path().empty()) {
903 origin_url, 871 DVLOG(1) << "Selected: file path: " << url.path().value()
904 fileapi::kFileSystemTypeExternal,
905 FilePath(virtual_path),
906 false);
907 FilePath file_path;
908 if (!root.empty()) {
909 file_path = root.Append(virtual_path);
910 } else {
911 LOG(WARNING) << "GetLocalPathsOnFileThread failed "
912 << file_url.spec();
913 }
914
915 if (!file_path.empty()) {
916 DVLOG(1) << "Selected: file path: " << file_path.value()
917 << " local path: " << local_path.value(); 872 << " local path: " << local_path.value();
918 selected_files.push_back( 873 selected_files.push_back(
919 ui::SelectedFileInfo(file_path, local_path)); 874 ui::SelectedFileInfo(url.path(), local_path));
920 } 875 }
921 } 876 }
922 877
923 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 878 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
924 base::Bind(callback, selected_files)); 879 base::Bind(callback, selected_files));
925 } 880 }
926 881
927 bool SelectFileFunction::RunImpl() { 882 bool SelectFileFunction::RunImpl() {
928 if (args_->GetSize() != 2) { 883 if (args_->GetSize() != 2) {
929 return false; 884 return false;
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 gdata::GDataSystemService* system_service = 2386 gdata::GDataSystemService* system_service =
2432 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2387 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2433 if (!system_service || !system_service->file_system()) 2388 if (!system_service || !system_service->file_system())
2434 return false; 2389 return false;
2435 2390
2436 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2391 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2437 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2392 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2438 2393
2439 return true; 2394 return true;
2440 } 2395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698