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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 656733002: Fix filesystem.retainEntry API to handle non-native directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "chrome/browser/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "apps/saved_files_service.h" 9 #include "apps/saved_files_service.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/value_conversions.h" 19 #include "base/value_conversions.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
22 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_util.h"
23 #include "chrome/browser/extensions/path_util.h" 24 #include "chrome/browser/extensions/path_util.h"
24 #include "chrome/browser/platform_util.h" 25 #include "chrome/browser/platform_util.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h" 27 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h"
27 #include "chrome/browser/ui/chrome_select_file_policy.h" 28 #include "chrome/browser/ui/chrome_select_file_policy.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/extensions/api/file_system.h" 30 #include "chrome/common/extensions/api/file_system.h"
30 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 33 #include "content/public/browser/child_process_security_policy.h"
33 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/storage_partition.h"
35 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
36 #include "extensions/browser/app_window/app_window.h" 38 #include "extensions/browser/app_window/app_window.h"
37 #include "extensions/browser/app_window/app_window_registry.h" 39 #include "extensions/browser/app_window/app_window_registry.h"
38 #include "extensions/browser/extension_prefs.h" 40 #include "extensions/browser/extension_prefs.h"
39 #include "extensions/browser/extension_system.h" 41 #include "extensions/browser/extension_system.h"
40 #include "extensions/browser/granted_file_entry.h" 42 #include "extensions/browser/granted_file_entry.h"
41 #include "extensions/common/permissions/api_permission.h" 43 #include "extensions/common/permissions/api_permission.h"
42 #include "extensions/common/permissions/permissions_data.h" 44 #include "extensions/common/permissions/permissions_data.h"
43 #include "net/base/mime_util.h" 45 #include "net/base/mime_util.h"
44 #include "storage/browser/fileapi/external_mount_points.h" 46 #include "storage/browser/fileapi/external_mount_points.h"
47 #include "storage/browser/fileapi/file_system_operation_runner.h"
45 #include "storage/browser/fileapi/isolated_context.h" 48 #include "storage/browser/fileapi/isolated_context.h"
46 #include "storage/common/fileapi/file_system_types.h" 49 #include "storage/common/fileapi/file_system_types.h"
47 #include "storage/common/fileapi/file_system_util.h" 50 #include "storage/common/fileapi/file_system_util.h"
48 #include "ui/base/l10n/l10n_util.h" 51 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/shell_dialogs/select_file_dialog.h" 52 #include "ui/shell_dialogs/select_file_dialog.h"
50 #include "ui/shell_dialogs/selected_file_info.h" 53 #include "ui/shell_dialogs/selected_file_info.h"
51 54
52 #if defined(OS_MACOSX) 55 #if defined(OS_MACOSX)
53 #include <CoreFoundation/CoreFoundation.h> 56 #include <CoreFoundation/CoreFoundation.h>
54 #include "base/mac/foundation_util.h" 57 #include "base/mac/foundation_util.h"
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); 864 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name));
862 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); 865 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path));
863 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, 866 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name,
864 filesystem_path, 867 filesystem_path,
865 render_view_host_, 868 render_view_host_,
866 &path_, 869 &path_,
867 &error_)) { 870 &error_)) {
868 return false; 871 return false;
869 } 872 }
870 873
871 content::BrowserThread::PostTaskAndReply( 874 std::string filesystem_id;
872 content::BrowserThread::FILE, 875 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id))
876 return false;
877
878 const GURL site =
879 extensions::util::GetSiteForExtensionId(extension_id(), GetProfile());
880 storage::FileSystemContext* const context =
881 content::BrowserContext::GetStoragePartitionForSite(GetProfile(), site)
882 ->GetFileSystemContext();
883 const storage::FileSystemURL url = context->CreateCrackedFileSystemURL(
884 site,
885 storage::kFileSystemTypeIsolated,
886 IsolatedContext::GetInstance()
887 ->CreateVirtualRootPath(filesystem_id)
888 .Append(filesystem_path));
889
890 content::BrowserThread::PostTask(
891 content::BrowserThread::IO,
873 FROM_HERE, 892 FROM_HERE,
874 base::Bind(&FileSystemRetainEntryFunction::SetIsDirectoryOnFileThread, 893 base::Bind(
875 this), 894 base::IgnoreResult(
876 base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry, 895 &storage::FileSystemOperationRunner::GetMetadata),
877 this, 896 context->operation_runner()->AsWeakPtr(),
878 entry_id)); 897 url,
898 base::Bind(&FileSystemRetainEntryFunction::SetIsDirectoryOnIOThread,
899 this,
900 entry_id)));
879 return true; 901 return true;
880 } 902 }
881 903
882 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); 904 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id);
883 SendResponse(true); 905 SendResponse(true);
884 return true; 906 return true;
885 } 907 }
886 908
887 void FileSystemRetainEntryFunction::RetainFileEntry( 909 void FileSystemRetainEntryFunction::RetainFileEntry(
888 const std::string& entry_id) { 910 const std::string& entry_id) {
911 if (entry_id.empty()) {
912 SendResponse(false);
913 return;
914 }
915
889 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 916 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile());
890 saved_files_service->RegisterFileEntry( 917 saved_files_service->RegisterFileEntry(
891 extension_->id(), entry_id, path_, is_directory_); 918 extension_->id(), entry_id, path_, is_directory_);
892 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); 919 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id);
893 SendResponse(true); 920 SendResponse(true);
894 } 921 }
895 922
896 void FileSystemRetainEntryFunction::SetIsDirectoryOnFileThread() { 923 void FileSystemRetainEntryFunction::SetIsDirectoryOnIOThread(
mtomasz 2014/10/14 06:08:49 Calling SetIsDirectoryOnIOThread should only set "
hirono 2014/10/14 09:22:10 I removed the method and aggregated the procedures
897 is_directory_ = base::DirectoryExists(path_); 924 const std::string& entry_id,
925 base::File::Error result,
926 const base::File::Info& file_info) {
927 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
928
929 if (result == base::File::FILE_OK)
930 is_directory_ = file_info.is_directory;
931
932 content::BrowserThread::PostTask(
mtomasz 2014/10/14 06:08:50 IO -> UI?
hirono 2014/10/14 09:22:10 Thank you for catching it. Done.
933 content::BrowserThread::IO,
934 FROM_HERE,
935 base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry,
936 this,
937 result == base::File::FILE_OK ? entry_id : ""));
898 } 938 }
899 939
900 bool FileSystemIsRestorableFunction::RunSync() { 940 bool FileSystemIsRestorableFunction::RunSync() {
901 std::string entry_id; 941 std::string entry_id;
902 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 942 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
903 SetResult(new base::FundamentalValue(SavedFilesService::Get( 943 SetResult(new base::FundamentalValue(SavedFilesService::Get(
904 GetProfile())->IsRegistered(extension_->id(), entry_id))); 944 GetProfile())->IsRegistered(extension_->id(), entry_id)));
905 return true; 945 return true;
906 } 946 }
907 947
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 return false; 984 return false;
945 } 985 }
946 986
947 bool FileSystemGetObservedEntriesFunction::RunSync() { 987 bool FileSystemGetObservedEntriesFunction::RunSync() {
948 NOTIMPLEMENTED(); 988 NOTIMPLEMENTED();
949 error_ = kUnknownIdError; 989 error_ = kUnknownIdError;
950 return false; 990 return false;
951 } 991 }
952 992
953 } // namespace extensions 993 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698