summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/file_system
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-04 21:16:48 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-04 21:16:48 +0000
commitac401f06cb07185c56f0ccaff9c59efc7caf31c5 (patch)
treef5db23ec7787a08c427da92863c2aebc633aa3e4 /chrome/browser/extensions/api/file_system
parenta04b64ee7f3b2229cfb7482022e08bf5125fee30 (diff)
downloadchromium_src-ac401f06cb07185c56f0ccaff9c59efc7caf31c5.zip
chromium_src-ac401f06cb07185c56f0ccaff9c59efc7caf31c5.tar.gz
chromium_src-ac401f06cb07185c56f0ccaff9c59efc7caf31c5.tar.bz2
Simplify file_system_api::GetLastChooseEntryDirectory().
Review URL: https://codereview.chromium.org/57193002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232800 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/file_system')
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_api.cc42
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_api.h7
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_apitest.cc21
3 files changed, 30 insertions, 40 deletions
diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc
index 3397850..942b3a1 100644
--- a/chrome/browser/extensions/api/file_system/file_system_api.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_api.cc
@@ -279,18 +279,16 @@ namespace extensions {
namespace file_system_api {
-bool GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
- const std::string& extension_id,
- base::FilePath* path) {
+base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
+ const std::string& extension_id) {
+ base::FilePath path;
std::string string_path;
- if (!prefs->ReadPrefAsString(extension_id,
- kLastChooseEntryDirectory,
- &string_path)) {
- return false;
+ if (prefs->ReadPrefAsString(extension_id,
+ kLastChooseEntryDirectory,
+ &string_path)) {
+ path = base::FilePath::FromUTF8Unsafe(string_path);
}
-
- *path = base::FilePath::FromUTF8Unsafe(string_path);
- return true;
+ return path;
}
void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
@@ -914,19 +912,20 @@ bool FileSystemChooseEntryFunction::RunImpl() {
file_type_info.support_drive = true;
- base::FilePath previous_path;
- file_system_api::GetLastChooseEntryDirectory(
- ExtensionPrefs::Get(GetProfile()), GetExtension()->id(), &previous_path);
+ base::FilePath previous_path = file_system_api::GetLastChooseEntryDirectory(
+ ExtensionPrefs::Get(GetProfile()), GetExtension()->id());
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::FILE,
FROM_HERE,
- base::Bind(
- &FileSystemChooseEntryFunction::SetInitialPathOnFileThread, this,
- suggested_name, previous_path),
- base::Bind(
- &FileSystemChooseEntryFunction::ShowPicker, this, file_type_info,
- picker_type));
+ base::Bind(&FileSystemChooseEntryFunction::SetInitialPathOnFileThread,
+ this,
+ suggested_name,
+ previous_path),
+ base::Bind(&FileSystemChooseEntryFunction::ShowPicker,
+ this,
+ file_type_info,
+ picker_type));
return true;
}
@@ -953,8 +952,9 @@ bool FileSystemRetainEntryFunction::RunImpl() {
FROM_HERE,
base::Bind(&FileSystemRetainEntryFunction::SetIsDirectoryOnFileThread,
this),
- base::Bind(
- &FileSystemRetainEntryFunction::RetainFileEntry, this, entry_id));
+ base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry,
+ this,
+ entry_id));
return true;
}
diff --git a/chrome/browser/extensions/api/file_system/file_system_api.h b/chrome/browser/extensions/api/file_system/file_system_api.h
index 52f516f..492bebb 100644
--- a/chrome/browser/extensions/api/file_system/file_system_api.h
+++ b/chrome/browser/extensions/api/file_system/file_system_api.h
@@ -22,10 +22,9 @@ namespace file_system_api {
// chosen by the user in response to a chrome.fileSystem.chooseEntry() call for
// the given extension.
-// Returns true and populates result on success; false on failure.
-bool GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
- const std::string& extension_id,
- base::FilePath* path);
+// Returns an empty path on failure.
+base::FilePath GetLastChooseEntryDirectory(const ExtensionPrefs* prefs,
+ const std::string& extension_id);
void SetLastChooseEntryDirectory(ExtensionPrefs* prefs,
const std::string& extension_id,
diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest.cc b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
index 549ca32d..b3348ba 100644
--- a/chrome/browser/extensions/api/file_system/file_system_apitest.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
@@ -48,13 +48,6 @@ void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory,
prefs, extension->id(), choose_entry_directory);
}
-void SetLastChooseEntryDirectoryToAppDirectory(
- ExtensionPrefs* prefs,
- const Extension* extension) {
- file_system_api::SetLastChooseEntryDirectory(
- prefs, extension->id(), extension->path());
-}
-
void AddSavedEntry(const base::FilePath& path_to_save,
bool is_directory,
apps::SavedFilesService* service,
@@ -139,13 +132,11 @@ class FileSystemApiTest : public PlatformAppBrowserTest {
ASSERT_TRUE(extension);
std::string extension_id = extension->id();
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
- base::FilePath stored_value;
+ base::FilePath stored_value =
+ file_system_api::GetLastChooseEntryDirectory(prefs, extension_id);
if (filename.empty()) {
- EXPECT_FALSE(file_system_api::GetLastChooseEntryDirectory(
- prefs, extension_id, &stored_value));
+ EXPECT_TRUE(stored_value.empty());
} else {
- EXPECT_TRUE(file_system_api::GetLastChooseEntryDirectory(
- prefs, extension_id, &stored_value));
EXPECT_EQ(base::MakeAbsoluteFilePath(filename.DirName()),
base::MakeAbsoluteFilePath(stored_value));
}
@@ -619,9 +610,9 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
&test_file);
AppInstallObserver observer(
base::Bind(AddSavedEntry,
- test_file,
- false,
- apps::SavedFilesService::Get(profile())));
+ test_file,
+ false,
+ apps::SavedFilesService::Get(profile())));
ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry"))
<< message_;
}