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

Side by Side Diff: chrome/renderer/resources/extensions/media_galleries_custom_bindings.js

Issue 615633003: MediaGalleriesCustomBindings: Ensure blobs aren't GC'd when getMetadata runs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo unintended change to apitest. Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Custom binding for the Media Gallery API. 5 // Custom binding for the Media Gallery API.
6 6
7 var binding = require('binding').Binding.create('mediaGalleries'); 7 var binding = require('binding').Binding.create('mediaGalleries');
8 var blobNatives = requireNative('blob_natives'); 8 var blobNatives = requireNative('blob_natives');
9 var mediaGalleriesNatives = requireNative('mediaGalleries'); 9 var mediaGalleriesNatives = requireNative('mediaGalleries');
10 10
11 var mediaFilesMetadata = {};
tommycli 2014/09/29 21:50:00 This makes it sound like you're storing the metada
Oren Blasberg 2014/09/29 22:05:48 Done.
11 var mediaGalleriesMetadata = {}; 12 var mediaGalleriesMetadata = {};
12 13
13 function createFileSystemObjectsAndUpdateMetadata(response) { 14 function createFileSystemObjectsAndUpdateMetadata(response) {
14 var result = []; 15 var result = [];
15 mediaGalleriesMetadata = {}; // Clear any previous metadata. 16 mediaGalleriesMetadata = {}; // Clear any previous metadata.
16 if (response) { 17 if (response) {
17 for (var i = 0; i < response.length; i++) { 18 for (var i = 0; i < response.length; i++) {
18 var filesystem = mediaGalleriesNatives.GetMediaFileSystemObject( 19 var filesystem = mediaGalleriesNatives.GetMediaFileSystemObject(
19 response[i].fsid); 20 response[i].fsid);
20 $Array.push(result, filesystem); 21 $Array.push(result, filesystem);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 'galleryId': '', 95 'galleryId': '',
95 'isRemovable': false, 96 'isRemovable': false,
96 'isMediaDevice': false, 97 'isMediaDevice': false,
97 'isAvailable': false, 98 'isAvailable': false,
98 }; 99 };
99 }); 100 });
100 101
101 apiFunctions.setUpdateArgumentsPostValidate('getMetadata', 102 apiFunctions.setUpdateArgumentsPostValidate('getMetadata',
102 function(mediaFile, options, callback) { 103 function(mediaFile, options, callback) {
103 var blobUuid = blobNatives.GetBlobUuid(mediaFile) 104 var blobUuid = blobNatives.GetBlobUuid(mediaFile)
105 // Store the blob in a global object to keep its refcount nonzero -- this
tommycli 2014/09/29 21:50:00 Perfect comment :)
Oren Blasberg 2014/09/29 22:05:48 Thanks Tommy!
106 // prevents the object from being garbage collected before any metadata
107 // parsing gets to occur (see crbug.com/415792).
108 mediaFilesMetadata[blobUuid] = mediaFile;
104 return [blobUuid, options, callback]; 109 return [blobUuid, options, callback];
105 }); 110 });
106 111
107 apiFunctions.setCustomCallback('getMetadata', 112 apiFunctions.setCustomCallback('getMetadata',
108 function(name, request, response) { 113 function(name, request, response) {
109 if (response.attachedImagesBlobInfo) { 114 if (response.attachedImagesBlobInfo) {
110 for (var i = 0; i < response.attachedImagesBlobInfo.length; i++) { 115 for (var i = 0; i < response.attachedImagesBlobInfo.length; i++) {
111 var blobInfo = response.attachedImagesBlobInfo[i]; 116 var blobInfo = response.attachedImagesBlobInfo[i];
112 var blob = blobNatives.TakeBrowserProcessBlob( 117 var blob = blobNatives.TakeBrowserProcessBlob(
113 blobInfo.blobUUID, blobInfo.type, blobInfo.size); 118 blobInfo.blobUUID, blobInfo.type, blobInfo.size);
114 response.metadata.attachedImages.push(blob); 119 response.metadata.attachedImages.push(blob);
115 } 120 }
116 } 121 }
117 122
118 if (request.callback) 123 if (request.callback)
119 request.callback(response.metadata); 124 request.callback(response.metadata);
120 request.callback = null; 125 request.callback = null;
126
127 var uuid = request.args[0];
tommycli 2014/09/29 21:50:00 Maybe a short one-line comment since this is not s
Oren Blasberg 2014/09/29 22:05:48 What sort of comment would be reasonable here? Rem
tommycli 2014/09/29 22:09:25 It's the uuid because of line 109: return [blobUui
128 delete mediaFilesMetadata[uuid];
121 }); 129 });
122 }); 130 });
123 131
124 exports.binding = binding.generate(); 132 exports.binding = binding.generate();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698