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

Unified Diff: ui/file_manager/video_player/js/background.js

Issue 414623003: Video Player: Use external entries instead of isolated entries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/video_player/js/background.js
diff --git a/ui/file_manager/video_player/js/background.js b/ui/file_manager/video_player/js/background.js
index 99ea086312eb8e8d8ffb559208b8ca0eb3682985..dc9fbdac4e3e19f46705d1b2e6e36b555a94d18b 100644
--- a/ui/file_manager/video_player/js/background.js
+++ b/ui/file_manager/video_player/js/background.js
@@ -9,42 +9,71 @@
// the same name will be overridden each other.
var appWindowsForTest = {};
-chrome.app.runtime.onLaunched.addListener(function(launchData) {
+var initializeQueue = new AsyncUtil.Queue();
+
+// Initializes the strings. This needs for the volume manager.
+initializeQueue.run(function(fulfill) {
+ chrome.fileBrowserPrivate.getStrings(function(stringData) {
+ loadTimeData.data = stringData;
+ fulfill();
+ }.wrap());
+}.wrap());
+
+// Initializes the volume manager. This needs for isolated entries.
+initializeQueue.run(function(fulfill) {
+ VolumeManager.getInstance(fulfill);
+}.wrap());
+
+// Registers a handler.
+initializeQueue.run(function(fulfill) {
+ chrome.app.runtime.onLaunched.addListener(onLaunched);
hirono 2014/07/23 02:48:58 I'm not sure if it is OK to register the onLaunche
yoshiki 2014/07/23 03:49:39 I'm also not sure but I think it's better to care.
+ fulfill();
+}.wrap());
+
+/**
+ * Called when an app is launched.
+ * @param {Object} launchData Launch data.
+ */
+function onLaunched(launchData) {
if (!launchData || !launchData.items || launchData.items.length == 0)
return;
- var getFilePromises = launchData.items.map(function(item) {
- var entry = item.entry;
- return new Promise(function(fullfill, reject) {
- entry.file(
- function(file) {
- fullfill({
+ var launchQueue = new AsyncUtil.Queue();
+ var videos = [];
+
+ launchQueue.run(function(fulfill) {
+ var isolatedEntries = launchData.items.map(function(item) {
+ return item.entry;
+ });
+
+ chrome.fileBrowserPrivate.resolveIsolatedEntries(isolatedEntries,
+ function(externalEntries) {
+ videos = externalEntries.map(function(entry) {
+ return {
entry: entry,
- file: file,
- fileUrl: window.URL.createObjectURL(file)
- });
- },
- function() {
- fullfill({entry: entry, file: null, fileUrl: null});
+ title: entry.name,
+ url: entry.toURL(),
+ };
});
- });
+ fulfill();
+ }.wrap());
});
hirono 2014/07/23 02:48:58 Should wrap here?
yoshiki 2014/07/23 03:49:39 Done.
- Promise.all(getFilePromises).then(function(results) {
- results = results.filter(function(result) { return result.file !== null; });
- if (results.length > 0)
- open(results);
- }.wrap(),
- function() {
- // TODO(yoshiki): handle error in a smarter way.
- open('', 'error'); // Empty URL shows the error message.
+ launchQueue.run(function(fulfill) {
+ if (videos.length > 0) {
+ open(videos);
+ } else {
+ // TODO(yoshiki): handle error in a smarter way.
+ open('', 'error'); // Empty URL shows the error message.
+ }
+ fulfill();
}.wrap());
-}.wrap());
+}
/**
* Opens player window.
* @param {Array.<Object>} videos List of videos to play.
- **/
+ */
function open(videos) {
chrome.app.window.create('video_player.html', {
id: 'video',
« no previous file with comments | « no previous file | ui/file_manager/video_player/js/video_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698