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

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

Issue 257333002: Drive extension functions from ExtensionFunction::Run. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 years, 7 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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "apps/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/app_window_registry.h" 8 #include "apps/app_window_registry.h"
9 #include "apps/browser/file_handler_util.h" 9 #include "apps/browser/file_handler_util.h"
10 #include "apps/saved_files_service.h" 10 #include "apps/saved_files_service.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 346 }
347 347
348 void FileSystemEntryFunction::HandleWritableFileError( 348 void FileSystemEntryFunction::HandleWritableFileError(
349 const base::FilePath& error_path) { 349 const base::FilePath& error_path) {
350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
351 error_ = base::StringPrintf(kWritableFileErrorFormat, 351 error_ = base::StringPrintf(kWritableFileErrorFormat,
352 error_path.BaseName().AsUTF8Unsafe().c_str()); 352 error_path.BaseName().AsUTF8Unsafe().c_str());
353 SendResponse(false); 353 SendResponse(false);
354 } 354 }
355 355
356 bool FileSystemGetWritableEntryFunction::RunImpl() { 356 bool FileSystemGetWritableEntryFunction::RunAsync() {
357 std::string filesystem_name; 357 std::string filesystem_name;
358 std::string filesystem_path; 358 std::string filesystem_path;
359 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); 359 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name));
360 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); 360 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path));
361 361
362 if (!app_file_handler_util::HasFileSystemWritePermission(extension_)) { 362 if (!app_file_handler_util::HasFileSystemWritePermission(extension_)) {
363 error_ = kRequiresFileSystemWriteError; 363 error_ = kRequiresFileSystemWriteError;
364 return false; 364 return false;
365 } 365 }
366 366
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 *suggested_name = suggested_name->BaseName(); 826 *suggested_name = suggested_name->BaseName();
827 if (suggested_name->IsAbsolute()) 827 if (suggested_name->IsAbsolute())
828 *suggested_name = base::FilePath(); 828 *suggested_name = base::FilePath();
829 829
830 *suggested_extension = suggested_name->Extension(); 830 *suggested_extension = suggested_name->Extension();
831 if (!suggested_extension->empty()) 831 if (!suggested_extension->empty())
832 suggested_extension->erase(suggested_extension->begin()); // drop the . 832 suggested_extension->erase(suggested_extension->begin()); // drop the .
833 } 833 }
834 } 834 }
835 835
836 bool FileSystemChooseEntryFunction::RunImpl() { 836 bool FileSystemChooseEntryFunction::RunAsync() {
837 scoped_ptr<ChooseEntry::Params> params(ChooseEntry::Params::Create(*args_)); 837 scoped_ptr<ChooseEntry::Params> params(ChooseEntry::Params::Create(*args_));
838 EXTENSION_FUNCTION_VALIDATE(params.get()); 838 EXTENSION_FUNCTION_VALIDATE(params.get());
839 839
840 base::FilePath suggested_name; 840 base::FilePath suggested_name;
841 ui::SelectFileDialog::FileTypeInfo file_type_info; 841 ui::SelectFileDialog::FileTypeInfo file_type_info;
842 ui::SelectFileDialog::Type picker_type = 842 ui::SelectFileDialog::Type picker_type =
843 ui::SelectFileDialog::SELECT_OPEN_FILE; 843 ui::SelectFileDialog::SELECT_OPEN_FILE;
844 844
845 file_system::ChooseEntryOptions* options = params->options.get(); 845 file_system::ChooseEntryOptions* options = params->options.get();
846 if (options) { 846 if (options) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 this, 895 this,
896 suggested_name, 896 suggested_name,
897 previous_path), 897 previous_path),
898 base::Bind(&FileSystemChooseEntryFunction::ShowPicker, 898 base::Bind(&FileSystemChooseEntryFunction::ShowPicker,
899 this, 899 this,
900 file_type_info, 900 file_type_info,
901 picker_type)); 901 picker_type));
902 return true; 902 return true;
903 } 903 }
904 904
905 bool FileSystemRetainEntryFunction::RunImpl() { 905 bool FileSystemRetainEntryFunction::RunAsync() {
906 std::string entry_id; 906 std::string entry_id;
907 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 907 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
908 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 908 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile());
909 // Add the file to the retain list if it is not already on there. 909 // Add the file to the retain list if it is not already on there.
910 if (!saved_files_service->IsRegistered(extension_->id(), entry_id)) { 910 if (!saved_files_service->IsRegistered(extension_->id(), entry_id)) {
911 std::string filesystem_name; 911 std::string filesystem_name;
912 std::string filesystem_path; 912 std::string filesystem_path;
913 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); 913 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name));
914 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); 914 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path));
915 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, 915 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 950 }
951 951
952 bool FileSystemIsRestorableFunction::RunSync() { 952 bool FileSystemIsRestorableFunction::RunSync() {
953 std::string entry_id; 953 std::string entry_id;
954 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 954 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
955 SetResult(new base::FundamentalValue(SavedFilesService::Get( 955 SetResult(new base::FundamentalValue(SavedFilesService::Get(
956 GetProfile())->IsRegistered(extension_->id(), entry_id))); 956 GetProfile())->IsRegistered(extension_->id(), entry_id)));
957 return true; 957 return true;
958 } 958 }
959 959
960 bool FileSystemRestoreEntryFunction::RunImpl() { 960 bool FileSystemRestoreEntryFunction::RunAsync() {
961 std::string entry_id; 961 std::string entry_id;
962 bool needs_new_entry; 962 bool needs_new_entry;
963 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 963 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
964 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry)); 964 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry));
965 const SavedFileEntry* file_entry = SavedFilesService::Get( 965 const SavedFileEntry* file_entry = SavedFilesService::Get(
966 GetProfile())->GetFileEntry(extension_->id(), entry_id); 966 GetProfile())->GetFileEntry(extension_->id(), entry_id);
967 if (!file_entry) { 967 if (!file_entry) {
968 error_ = kUnknownIdError; 968 error_ = kUnknownIdError;
969 return false; 969 return false;
970 } 970 }
971 971
972 SavedFilesService::Get(GetProfile()) 972 SavedFilesService::Get(GetProfile())
973 ->EnqueueFileEntry(extension_->id(), entry_id); 973 ->EnqueueFileEntry(extension_->id(), entry_id);
974 974
975 // Only create a new file entry if the renderer requests one. 975 // Only create a new file entry if the renderer requests one.
976 // |needs_new_entry| will be false if the renderer already has an Entry for 976 // |needs_new_entry| will be false if the renderer already has an Entry for
977 // |entry_id|. 977 // |entry_id|.
978 if (needs_new_entry) { 978 if (needs_new_entry) {
979 is_directory_ = file_entry->is_directory; 979 is_directory_ = file_entry->is_directory;
980 CreateResponse(); 980 CreateResponse();
981 AddEntryToResponse(file_entry->path, file_entry->id); 981 AddEntryToResponse(file_entry->path, file_entry->id);
982 } 982 }
983 SendResponse(true); 983 SendResponse(true);
984 return true; 984 return true;
985 } 985 }
986 986
987 } // namespace extensions 987 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698