| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Media manager class. | 8 * Media manager class. |
| 9 * This class supports the information for the media file. | 9 * This class supports the information for the media file. |
| 10 * @param {FileEntry} entry Entry of media file. This must be a external entry. | 10 * @param {FileEntry} entry Entry of media file. This must be a external entry. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 * @return {Promise} Promise which is resolved with the token. Reject if failed. | 44 * @return {Promise} Promise which is resolved with the token. Reject if failed. |
| 45 */ | 45 */ |
| 46 MediaManager.prototype.getToken = function(refresh) { | 46 MediaManager.prototype.getToken = function(refresh) { |
| 47 if (this.cachedToken_ && !refresh) | 47 if (this.cachedToken_ && !refresh) |
| 48 return Promise.resolve(this.cachedToken_); | 48 return Promise.resolve(this.cachedToken_); |
| 49 | 49 |
| 50 return new Promise(function(fulfill, reject) { | 50 return new Promise(function(fulfill, reject) { |
| 51 // TODO(yoshiki): Creates the method to get a token and use it. | 51 // TODO(yoshiki): Creates the method to get a token and use it. |
| 52 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); | 52 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
| 53 }.bind(this)).then(function(url) { | 53 }.bind(this)).then(function(url) { |
| 54 if (chrome.runtime.lastError) { |
| 55 return Promise.reject( |
| 56 'Token fetch failed: ' + chrome.runtime.lastError.message); |
| 57 } |
| 54 if (!url) | 58 if (!url) |
| 55 return Promise.reject('Token fetch failed.'); | 59 return Promise.reject('Token fetch failed.'); |
| 56 var token = url.substring(url.indexOf('access_token=') + 13); | 60 var token = url.substring(url.indexOf('access_token=') + 13); |
| 57 if (token) { | 61 if (token) { |
| 58 this.cachedToken_ = token; | 62 this.cachedToken_ = token; |
| 59 return token; | 63 return token; |
| 60 } else { | 64 } else { |
| 61 return Promise.reject('Token fetch failed.'); | 65 return Promise.reject('Token fetch failed.'); |
| 62 } | 66 } |
| 63 }.bind(this)); | 67 }.bind(this)); |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 /** | 70 /** |
| 67 * Retrives the url for cast. | 71 * Retrives the url for cast. |
| 68 * | 72 * |
| 69 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 73 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
| 70 */ | 74 */ |
| 71 MediaManager.prototype.getUrl = function() { | 75 MediaManager.prototype.getUrl = function() { |
| 72 if (this.cachedUrl_) | 76 if (this.cachedUrl_) |
| 73 return Promise.resolve(this.cachedUrl_); | 77 return Promise.resolve(this.cachedUrl_); |
| 74 | 78 |
| 75 return new Promise(function(fulfill, reject) { | 79 return new Promise(function(fulfill, reject) { |
| 76 // TODO(yoshiki): Creates the method to get a url and use it. | 80 // TODO(yoshiki): Creates the method to get a url and use it. |
| 77 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); | 81 chrome.fileBrowserPrivate.getDownloadUrl(this.entry_.toURL(), fulfill); |
| 78 }.bind(this)).then(function(url) { | 82 }.bind(this)).then(function(url) { |
| 83 if (chrome.runtime.lastError) { |
| 84 return Promise.reject( |
| 85 'URL fetch failed: ' + chrome.runtime.lastError.message); |
| 86 } |
| 79 if (!url) | 87 if (!url) |
| 80 return Promise.reject('URL fetch failed.'); | 88 return Promise.reject('URL fetch failed.'); |
| 81 var access_token_index = url.indexOf('access_token='); | 89 var access_token_index = url.indexOf('access_token='); |
| 82 if (access_token_index) { | 90 if (access_token_index) { |
| 83 url = url.substring(0, access_token_index - 1); | 91 url = url.substring(0, access_token_index - 1); |
| 84 } | 92 } |
| 85 this.cachedUrl_ = url; | 93 this.cachedUrl_ = url; |
| 86 return url; | 94 return url; |
| 87 }.bind(this)); | 95 }.bind(this)); |
| 88 }; | 96 }; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 }.bind(this)).then(function(props) { | 133 }.bind(this)).then(function(props) { |
| 126 if (!props || !props[0] || !props[0].thumbnailUrl) { | 134 if (!props || !props[0] || !props[0].thumbnailUrl) { |
| 127 // TODO(yoshiki): Adds a logic to guess the mime. | 135 // TODO(yoshiki): Adds a logic to guess the mime. |
| 128 return Promise.reject('Thuumbnail fetch failed.'); | 136 return Promise.reject('Thuumbnail fetch failed.'); |
| 129 } else { | 137 } else { |
| 130 this.cachedDriveProp_ = props[0]; | 138 this.cachedDriveProp_ = props[0]; |
| 131 return props[0].thumbnailUrl; | 139 return props[0].thumbnailUrl; |
| 132 } | 140 } |
| 133 }.bind(this)); | 141 }.bind(this)); |
| 134 }; | 142 }; |
| OLD | NEW |