Skip to content

Commit

Permalink
Migrate FileSystemContext and FileSystemBackend to OnceCallback
Browse files Browse the repository at this point in the history
This CL convert legacy base::Callbacks on FileSystem classes that have
smaller number of dependencies and subclasses.
After this, FileSystemBackend and FileSystemContext starts using
OnceCallback.

Change-Id: I4ce5db277b675f09d8174c3cda8c4b2c56adba9b
Reviewed-on: https://chromium-review.googlesource.com/627941
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496892}
  • Loading branch information
tzik authored and Commit Bot committed Aug 24, 2017
1 parent 77759bd commit 7f1c54b
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 255 deletions.
20 changes: 10 additions & 10 deletions chrome/browser/media_galleries/fileapi/media_file_system_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,25 @@ void OnPreferencesInit(
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const extensions::Extension* extension,
MediaGalleryPrefId pref_id,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
content::WebContents* contents = web_contents_getter.Run();
if (!contents) {
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, base::File::FILE_ERROR_FAILED));
base::BindOnce(std::move(callback), base::File::FILE_ERROR_FAILED));
return;
}
MediaFileSystemRegistry* registry =
g_browser_process->media_file_system_registry();
registry->RegisterMediaFileSystemForExtension(contents, extension, pref_id,
callback);
std::move(callback));
}

void AttemptAutoMountOnUIThread(
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const std::string& storage_domain,
const std::string& mount_point,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::WebContents* web_contents = web_contents_getter.Run();
if (web_contents) {
Expand All @@ -115,16 +115,16 @@ void AttemptAutoMountOnUIThread(
profile);
// Pass the WebContentsGetter to the closure to prevent a use-after-free
// in the case that the web_contents is destroyed before the closure runs.
preferences->EnsureInitialized(
base::Bind(&OnPreferencesInit, web_contents_getter,
base::RetainedRef(extension), pref_id, callback));
preferences->EnsureInitialized(base::Bind(
&OnPreferencesInit, web_contents_getter, base::RetainedRef(extension),
pref_id, base::Passed(&callback)));
return;
}
}

content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, base::File::FILE_ERROR_NOT_FOUND));
base::BindOnce(std::move(callback), base::File::FILE_ERROR_NOT_FOUND));
}

} // namespace
Expand Down Expand Up @@ -196,7 +196,7 @@ bool MediaFileSystemBackend::AttemptAutoMountForURLRequest(
const net::URLRequest* url_request,
const storage::FileSystemURL& filesystem_url,
const std::string& storage_domain,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
if (storage_domain.empty() ||
filesystem_url.type() != storage::kFileSystemTypeExternal ||
storage_domain != filesystem_url.origin().host()) {
Expand Down Expand Up @@ -224,7 +224,7 @@ bool MediaFileSystemBackend::AttemptAutoMountForURLRequest(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&AttemptAutoMountOnUIThread,
request_info->GetWebContentsGetterForRequest(),
storage_domain, mount_point, callback));
storage_domain, mount_point, std::move(callback)));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MediaFileSystemBackend : public storage::FileSystemBackend {
const net::URLRequest* url_request,
const storage::FileSystemURL& filesystem_url,
const std::string& storage_domain,
const base::Callback<void(base::File::Error result)>& callback);
base::OnceCallback<void(base::File::Error result)> callback);

// FileSystemBackend implementation.
bool CanHandleType(storage::FileSystemType type) const override;
Expand Down
20 changes: 11 additions & 9 deletions chrome/browser/media_galleries/media_file_system_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,16 @@ class ExtensionGalleriesHost
// then calls |callback| with the result.
void RegisterMediaFileSystem(
const MediaGalleryPrefInfo& gallery,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
// Extract all the device ids so we can make sure they are attached.
MediaStorageUtil::DeviceIdSet* device_ids =
new MediaStorageUtil::DeviceIdSet;
device_ids->insert(gallery.device_id);
MediaStorageUtil::FilterAttachedDevices(device_ids, base::Bind(
&ExtensionGalleriesHost::RegisterAttachedMediaFileSystem, this,
base::Owned(device_ids), gallery, callback));
MediaStorageUtil::FilterAttachedDevices(
device_ids,
base::Bind(&ExtensionGalleriesHost::RegisterAttachedMediaFileSystem,
this, base::Owned(device_ids), gallery,
base::Passed(&callback)));
}

// Revoke the file system for |id| if this extension has created one for |id|.
Expand Down Expand Up @@ -430,7 +432,7 @@ class ExtensionGalleriesHost
void RegisterAttachedMediaFileSystem(
const MediaStorageUtil::DeviceIdSet* attached_device,
const MediaGalleryPrefInfo& gallery,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
base::File::Error result = base::File::FILE_ERROR_NOT_FOUND;

// If rph_refs is empty then we're actually in the middle of shutdown, and
Expand Down Expand Up @@ -464,7 +466,7 @@ class ExtensionGalleriesHost
CleanUp();
}
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, result));
base::BindOnce(std::move(callback), result));
}

std::string GetTransientIdForRemovableDeviceId(const std::string& device_id) {
Expand Down Expand Up @@ -545,7 +547,7 @@ void MediaFileSystemRegistry::RegisterMediaFileSystemForExtension(
content::WebContents* contents,
const extensions::Extension* extension,
MediaGalleryPrefId pref_id,
const base::Callback<void(base::File::Error result)>& callback) {
base::OnceCallback<void(base::File::Error result)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_NE(kInvalidMediaGalleryPrefId, pref_id);

Expand All @@ -560,7 +562,7 @@ void MediaFileSystemRegistry::RegisterMediaFileSystemForExtension(
!base::ContainsKey(permitted_galleries, pref_id)) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, base::File::FILE_ERROR_NOT_FOUND));
base::BindOnce(std::move(callback), base::File::FILE_ERROR_NOT_FOUND));
return;
}

Expand All @@ -571,7 +573,7 @@ void MediaFileSystemRegistry::RegisterMediaFileSystemForExtension(
// contents of the context is referenced before the filesystems are retrieved.
extension_host->ReferenceFromWebContents(contents);

extension_host->RegisterMediaFileSystem(gallery->second, callback);
extension_host->RegisterMediaFileSystem(gallery->second, std::move(callback));
}

MediaGalleriesPreferences* MediaFileSystemRegistry::GetPreferences(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MediaFileSystemRegistry
content::WebContents* contents,
const extensions::Extension* extension,
MediaGalleryPrefId pref_id,
const base::Callback<void(base::File::Error result)>& callback);
base::OnceCallback<void(base::File::Error result)> callback);

// Returns the media galleries preferences for the specified |profile|.
// Caller is responsible for ensuring that the preferences are initialized
Expand Down
Loading

0 comments on commit 7f1c54b

Please sign in to comment.