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

Unified Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 137313003: Media Galleries API Extension functions: Refactor Preference initialization block. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/media_galleries/media_galleries_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
index 228d6ee91fcd89e985d738d5c1913e0240fee272..7c0d13479b58a09e27fbd58e655b355617eda923 100644
--- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
+++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
@@ -66,22 +66,26 @@ const char kIsMediaDeviceKey[] = "isMediaDevice";
const char kIsRemovableKey[] = "isRemovable";
const char kNameKey[] = "name";
+MediaFileSystemRegistry* media_file_system_registry() {
+ return g_browser_process->media_file_system_registry();
+}
+
// Checks whether the MediaGalleries API is currently accessible (it may be
-// disallowed even if an extension has the requisite permission).
-bool ApiIsAccessible(std::string* error) {
+// disallowed even if an extension has the requisite permission). Then
+// initializes the MediaGalleriesPreferences
+bool SetupCall(Profile* profile, std::string* error, base::Closure callback) {
vandebo (ex-Chrome) 2014/01/14 17:03:39 nit: Initialize or Setup
tommycli 2014/01/14 17:42:41 Done.
if (!ChromeSelectFilePolicy::FileSelectDialogsAllowed()) {
*error = std::string(kDisallowedByPolicy) +
prefs::kAllowFileSelectionDialogs;
return false;
}
+ MediaGalleriesPreferences* preferences =
+ media_file_system_registry()->GetPreferences(profile);
+ preferences->EnsureInitialized(callback);
return true;
}
-MediaFileSystemRegistry* media_file_system_registry() {
- return g_browser_process->media_file_system_registry();
-}
-
WebContents* GetWebContents(content::RenderViewHost* rvh,
Profile* profile,
const std::string& app_id) {
@@ -228,9 +232,11 @@ MediaGalleriesGetMediaFileSystemsFunction::
~MediaGalleriesGetMediaFileSystemsFunction() {}
bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() {
- if (!ApiIsAccessible(&error_))
- return false;
+ return SetupCall(GetProfile(), &error_, base::Bind(
+ &MediaGalleriesGetMediaFileSystemsFunction::OnPreferencesInit, this));
+}
+void MediaGalleriesGetMediaFileSystemsFunction::OnPreferencesInit() {
media_galleries::UsageCount(media_galleries::GET_MEDIA_FILE_SYSTEMS);
scoped_ptr<GetMediaFileSystems::Params> params(
GetMediaFileSystems::Params::Create(*args_));
@@ -242,17 +248,6 @@ bool MediaGalleriesGetMediaFileSystemsFunction::RunImpl() {
interactive = params->details->interactive;
}
- MediaGalleriesPreferences* preferences =
- media_file_system_registry()->GetPreferences(GetProfile());
- preferences->EnsureInitialized(base::Bind(
- &MediaGalleriesGetMediaFileSystemsFunction::OnPreferencesInit,
- this,
- interactive));
- return true;
-}
-
-void MediaGalleriesGetMediaFileSystemsFunction::OnPreferencesInit(
- MediaGalleries::GetMediaFileSystemsInteractivity interactive) {
switch (interactive) {
case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: {
// The MediaFileSystemRegistry only updates preferences for extensions
@@ -339,20 +334,15 @@ MediaGalleriesGetAllMediaFileSystemMetadataFunction::
~MediaGalleriesGetAllMediaFileSystemMetadataFunction() {}
bool MediaGalleriesGetAllMediaFileSystemMetadataFunction::RunImpl() {
- if (!ApiIsAccessible(&error_))
- return false;
-
- media_galleries::UsageCount(
- media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA);
- MediaGalleriesPreferences* preferences =
- media_file_system_registry()->GetPreferences(GetProfile());
- preferences->EnsureInitialized(base::Bind(
+ return SetupCall(GetProfile(), &error_, base::Bind(
&MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit,
this));
- return true;
}
void MediaGalleriesGetAllMediaFileSystemMetadataFunction::OnPreferencesInit() {
+ media_galleries::UsageCount(
+ media_galleries::GET_ALL_MEDIA_FILE_SYSTEM_METADATA);
+
MediaFileSystemRegistry* registry = media_file_system_registry();
MediaGalleriesPreferences* prefs = registry->GetPreferences(GetProfile());
DCHECK(prefs->IsInitialized());
@@ -407,19 +397,13 @@ MediaGalleriesAddUserSelectedFolderFunction::
~MediaGalleriesAddUserSelectedFolderFunction() {}
bool MediaGalleriesAddUserSelectedFolderFunction::RunImpl() {
- if (!ApiIsAccessible(&error_))
- return false;
-
- media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER);
- MediaGalleriesPreferences* preferences =
- media_file_system_registry()->GetPreferences(GetProfile());
- preferences->EnsureInitialized(base::Bind(
- &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit,
- this));
- return true;
+ return SetupCall(GetProfile(), &error_, base::Bind(
+ &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this));
}
void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() {
+ media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER);
+
if (!user_gesture()) {
OnDirectorySelected(base::FilePath());
return;
@@ -508,35 +492,30 @@ MediaGalleriesAddUserSelectedFolderFunction::GetMediaFileSystemsForExtension(
MediaGalleriesGetMetadataFunction::~MediaGalleriesGetMetadataFunction() {}
bool MediaGalleriesGetMetadataFunction::RunImpl() {
- if (!ApiIsAccessible(&error_))
- return false;
+ return SetupCall(GetProfile(), &error_, base::Bind(
+ &MediaGalleriesGetMetadataFunction::OnPreferencesInit, this));
+}
+
+void MediaGalleriesGetMetadataFunction::OnPreferencesInit() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
std::string blob_uuid;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &blob_uuid));
const base::Value* options_value = NULL;
- if (!args_->Get(1, &options_value))
- return false;
+ if (!args_->Get(1, &options_value)) {
vandebo (ex-Chrome) 2014/01/14 17:03:39 And here
tommycli 2014/01/14 17:42:41 Done.
+ SendResponse(false);
+ return;
+ }
scoped_ptr<MediaGalleries::MediaMetadataOptions> options =
MediaGalleries::MediaMetadataOptions::FromValue(*options_value);
- if (!options)
- return false;
+ if (!options) {
+ SendResponse(false);
+ return;
+ }
- MediaGalleriesPreferences* preferences =
- media_file_system_registry()->GetPreferences(GetProfile());
bool mime_type_only = options->metadata_type ==
MediaGalleries::GET_METADATA_TYPE_MIMETYPEONLY;
- preferences->EnsureInitialized(base::Bind(
- &MediaGalleriesGetMetadataFunction::OnPreferencesInit,
- this, mime_type_only, blob_uuid));
-
- return true;
-}
-
-void MediaGalleriesGetMetadataFunction::OnPreferencesInit(
- bool mime_type_only,
- const std::string& blob_uuid) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// BlobReader is self-deleting.
BlobReader* reader = new BlobReader(
« no previous file with comments | « chrome/browser/extensions/api/media_galleries/media_galleries_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698