Commit ca5a56f9 authored by orenb's avatar orenb Committed by Commit bot

MediaGalleriesCustomBindings: Ensure blobs aren't GC'd when getMetadata runs.

BUG=415792

Review URL: https://codereview.chromium.org/615633003

Cr-Commit-Position: refs/heads/master@{#297444}
parent 3f07f5f3
...@@ -20,6 +20,7 @@ per-file web_view*.js=fsamuel@chromium.org ...@@ -20,6 +20,7 @@ per-file web_view*.js=fsamuel@chromium.org
per-file web_view*.js=lazyboy@chromium.org per-file web_view*.js=lazyboy@chromium.org
per-file app_view*.js=fsamuel@chromium.org per-file app_view*.js=fsamuel@chromium.org
per-file app_view*.js=lazyboy@chromium.org per-file app_view*.js=lazyboy@chromium.org
per-file media_galleries*.js=orenb@chromium.org
per-file enterprise_platform_keys*=pneubeck@chromium.org per-file enterprise_platform_keys*=pneubeck@chromium.org
per-file notifications_*.js=dewittj@chromium.org per-file notifications_*.js=dewittj@chromium.org
per-file image_util.js=dewittj@chromium.org per-file image_util.js=dewittj@chromium.org
......
...@@ -8,6 +8,7 @@ var binding = require('binding').Binding.create('mediaGalleries'); ...@@ -8,6 +8,7 @@ var binding = require('binding').Binding.create('mediaGalleries');
var blobNatives = requireNative('blob_natives'); var blobNatives = requireNative('blob_natives');
var mediaGalleriesNatives = requireNative('mediaGalleries'); var mediaGalleriesNatives = requireNative('mediaGalleries');
var blobsAwaitingMetadata = {};
var mediaGalleriesMetadata = {}; var mediaGalleriesMetadata = {};
function createFileSystemObjectsAndUpdateMetadata(response) { function createFileSystemObjectsAndUpdateMetadata(response) {
...@@ -101,6 +102,10 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { ...@@ -101,6 +102,10 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
apiFunctions.setUpdateArgumentsPostValidate('getMetadata', apiFunctions.setUpdateArgumentsPostValidate('getMetadata',
function(mediaFile, options, callback) { function(mediaFile, options, callback) {
var blobUuid = blobNatives.GetBlobUuid(mediaFile) var blobUuid = blobNatives.GetBlobUuid(mediaFile)
// Store the blob in a global object to keep its refcount nonzero -- this
// prevents the object from being garbage collected before any metadata
// parsing gets to occur (see crbug.com/415792).
blobsAwaitingMetadata[blobUuid] = mediaFile;
return [blobUuid, options, callback]; return [blobUuid, options, callback];
}); });
...@@ -118,6 +123,11 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { ...@@ -118,6 +123,11 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
if (request.callback) if (request.callback)
request.callback(response.metadata); request.callback(response.metadata);
request.callback = null; request.callback = null;
// The UUID was in position 0 in the setUpdateArgumentsPostValidate
// function.
var uuid = request.args[0];
delete blobsAwaitingMetadata[uuid];
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment