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

Side by Side Diff: ui/file_manager/image_loader/image_loader.js

Issue 985533004: Implement chrome.fileSystem.requestFileSystem(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compile issues. Created 5 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 /** 5 /**
6 * Loads and resizes an image. 6 * Loads and resizes an image.
7 * @constructor 7 * @constructor
8 */ 8 */
9 function ImageLoader() { 9 function ImageLoader() {
10 /** 10 /**
11 * Persistent cache object. 11 * Persistent cache object.
12 * @type {Cache} 12 * @type {Cache}
13 * @private 13 * @private
14 */ 14 */
15 this.cache_ = new Cache(); 15 this.cache_ = new Cache();
16 16
17 /** 17 /**
18 * Manages pending requests and runs them in order of priorities. 18 * Manages pending requests and runs them in order of priorities.
19 * @type {Scheduler} 19 * @type {Scheduler}
20 * @private 20 * @private
21 */ 21 */
22 this.scheduler_ = new Scheduler(); 22 this.scheduler_ = new Scheduler();
23 23
24 // Grant permissions to all volumes, initialize the cache and then start the 24 // Grant permissions to all volumes, initialize the cache and then start the
25 // scheduler. 25 // scheduler.
26 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) { 26 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) {
27 // Listen for mount events, and grant permissions to volumes being mounted.
28 chrome.fileManagerPrivate.onMountCompleted.addListener(
29 function(event) {
30 if (event.eventType == 'mount' && event.status == 'success') {
hirono 2015/03/19 03:33:54 nit: === are preferred.
mtomasz 2015/03/19 10:28:41 Done.
31 chrome.fileSystem.requestFileSystem(
32 {volumeId: event.volumeMetadata.volumeId}, function() {});
33 }
34 });
27 var initPromises = volumeMetadataList.map(function(volumeMetadata) { 35 var initPromises = volumeMetadataList.map(function(volumeMetadata) {
28 var requestPromise = new Promise(function(callback) { 36 var requestPromise = new Promise(function(callback) {
29 chrome.fileManagerPrivate.requestFileSystem( 37 chrome.fileSystem.requestFileSystem(
30 volumeMetadata.volumeId, 38 {volumeId: volumeMetadata.volumeId},
31 callback); 39 callback);
32 }); 40 });
33 return requestPromise; 41 return requestPromise;
34 }); 42 });
35 initPromises.push(new Promise(function(resolve, reject) { 43 initPromises.push(new Promise(function(resolve, reject) {
36 this.cache_.initialize(resolve); 44 this.cache_.initialize(resolve);
37 }.bind(this))); 45 }.bind(this)));
38 46
39 // After all initialization promises are done, start the scheduler. 47 // After all initialization promises are done, start the scheduler.
40 Promise.all(initPromises).then(this.scheduler_.start.bind(this.scheduler_)); 48 Promise.all(initPromises).then(this.scheduler_.start.bind(this.scheduler_));
41
42 // Listen for mount events, and grant permissions to volumes being mounted.
43 chrome.fileManagerPrivate.onMountCompleted.addListener(
44 function(event) {
45 if (event.eventType == 'mount' && event.status == 'success') {
46 chrome.fileManagerPrivate.requestFileSystem(
47 event.volumeMetadata.volumeId, function() {});
48 }
49 });
50 }.bind(this)); 49 }.bind(this));
51 50
52 // Listen for incoming requests. 51 // Listen for incoming requests.
53 chrome.runtime.onMessageExternal.addListener( 52 chrome.runtime.onMessageExternal.addListener(
54 function(request, sender, sendResponse) { 53 function(request, sender, sendResponse) {
55 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) { 54 if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) !== -1) {
56 // Sending a response may fail if the receiver already went offline. 55 // Sending a response may fail if the receiver already went offline.
57 // This is not an error, but a normal and quite common situation. 56 // This is not an error, but a normal and quite common situation.
58 var failSafeSendResponse = function(response) { 57 var failSafeSendResponse = function(response) {
59 try { 58 try {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 targetContext.translate(target.width / 2, target.height / 2); 225 targetContext.translate(target.width / 2, target.height / 2);
227 targetContext.rotate(orientation * Math.PI / 2); 226 targetContext.rotate(orientation * Math.PI / 2);
228 targetContext.drawImage( 227 targetContext.drawImage(
229 source, 228 source,
230 0, 0, 229 0, 0,
231 source.width, source.height, 230 source.width, source.height,
232 -drawImageWidth / 2, -drawImageHeight / 2, 231 -drawImageWidth / 2, -drawImageHeight / 2,
233 drawImageWidth, drawImageHeight); 232 drawImageWidth, drawImageHeight);
234 targetContext.restore(); 233 targetContext.restore();
235 }; 234 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698