OLD | NEW |
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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * The overlay displaying the image. | 8 * The overlay displaying the image. |
9 * | 9 * |
10 * @param {HTMLElement} container The container element. | 10 * @param {HTMLElement} container The container element. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 345 |
346 video.addEventListener('loadedmetadata', onVideoLoadSuccess); | 346 video.addEventListener('loadedmetadata', onVideoLoadSuccess); |
347 video.addEventListener('error', onVideoLoadError); | 347 video.addEventListener('error', onVideoLoadError); |
348 | 348 |
349 // Do not try no stream when offline. | 349 // Do not try no stream when offline. |
350 video.src = (navigator.onLine && metadata.streaming && | 350 video.src = (navigator.onLine && metadata.streaming && |
351 metadata.streaming.url) || url; | 351 metadata.streaming.url) || url; |
352 video.load(); | 352 video.load(); |
353 return; | 353 return; |
354 } | 354 } |
| 355 |
| 356 // Cache has to be evicted in advance, so the returned cached image is not |
| 357 // evicted later by the prefetched image. |
| 358 this.contentCache_.evictLRU(); |
| 359 |
355 var cached = this.contentCache_.getItem(this.contentID_); | 360 var cached = this.contentCache_.getItem(this.contentID_); |
356 if (cached) { | 361 if (cached) { |
357 displayMainImage(ImageView.LOAD_TYPE_CACHED_FULL, | 362 displayMainImage(ImageView.LOAD_TYPE_CACHED_FULL, |
358 false /* no preview */, cached); | 363 false /* no preview */, cached); |
359 } else { | 364 } else { |
360 var cachedScreen = this.screenCache_.getItem(this.contentID_); | 365 var cachedScreen = this.screenCache_.getItem(this.contentID_); |
361 if (cachedScreen) { | 366 if (cachedScreen) { |
362 // We have a cached screen-scale canvas, use it instead of a thumbnail. | 367 // We have a cached screen-scale canvas, use it instead of a thumbnail. |
363 displayThumbnail(ImageView.LOAD_TYPE_CACHED_SCREEN, cachedScreen); | 368 displayThumbnail(ImageView.LOAD_TYPE_CACHED_SCREEN, cachedScreen); |
364 // As far as the user can tell the image is loaded. We still need to load | 369 // As far as the user can tell the image is loaded. We still need to load |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 * @param {string} id The item ID. | 802 * @param {string} id The item ID. |
798 * @param {Object} item The item object. | 803 * @param {Object} item The item object. |
799 * @param {boolean=} opt_keepLRU True if the LRU order should not be modified. | 804 * @param {boolean=} opt_keepLRU True if the LRU order should not be modified. |
800 */ | 805 */ |
801 ImageView.Cache.prototype.putItem = function(id, item, opt_keepLRU) { | 806 ImageView.Cache.prototype.putItem = function(id, item, opt_keepLRU) { |
802 var pos = this.order_.indexOf(id); | 807 var pos = this.order_.indexOf(id); |
803 | 808 |
804 if ((pos >= 0) != (id in this.map_)) | 809 if ((pos >= 0) != (id in this.map_)) |
805 throw new Error('Inconsistent cache state'); | 810 throw new Error('Inconsistent cache state'); |
806 | 811 |
807 if ((pos >= 0) && (item != this.map_[id])) | |
808 this.deleteItem_(this.map_[id]); | |
809 | |
810 if (id in this.map_) { | 812 if (id in this.map_) { |
811 if (!opt_keepLRU) { | 813 if (!opt_keepLRU) { |
812 // Move to the end (most recently used). | 814 // Move to the end (most recently used). |
813 this.order_.splice(pos, 1); | 815 this.order_.splice(pos, 1); |
814 this.order_.push(id); | 816 this.order_.push(id); |
815 } | 817 } |
816 } else { | 818 } else { |
817 this.evictLRU(); | 819 this.evictLRU(); |
818 this.order_.push(id); | 820 this.order_.push(id); |
819 } | 821 } |
820 | 822 |
| 823 if ((pos >= 0) && (item != this.map_[id])) |
| 824 this.deleteItem_(this.map_[id]); |
821 this.map_[id] = item; | 825 this.map_[id] = item; |
822 | 826 |
823 if (this.order_.length > this.capacity_) | 827 if (this.order_.length > this.capacity_) |
824 throw new Error('Exceeded cache capacity'); | 828 throw new Error('Exceeded cache capacity'); |
825 }; | 829 }; |
826 | 830 |
827 /** | 831 /** |
828 * Evict the least recently used items. | 832 * Evict the least recently used items. |
829 */ | 833 */ |
830 ImageView.Cache.prototype.evictLRU = function() { | 834 ImageView.Cache.prototype.evictLRU = function() { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 | 1056 |
1053 /** | 1057 /** |
1054 * @param {HTMLCanvasElement|HTMLVideoElement} element Element. | 1058 * @param {HTMLCanvasElement|HTMLVideoElement} element Element. |
1055 * @return {string} Transform string. | 1059 * @return {string} Transform string. |
1056 */ | 1060 */ |
1057 ImageView.Effect.Rotate.prototype.transform = function(element) { | 1061 ImageView.Effect.Rotate.prototype.transform = function(element) { |
1058 var ratio = ImageView.Effect.getPixelRatio_(element); | 1062 var ratio = ImageView.Effect.getPixelRatio_(element); |
1059 return 'rotate(' + (this.rotate90_ * 90) + 'deg) ' + | 1063 return 'rotate(' + (this.rotate90_ * 90) + 'deg) ' + |
1060 'scale(' + (this.scale_ / ratio) + ')'; | 1064 'scale(' + (this.scale_ / ratio) + ')'; |
1061 }; | 1065 }; |
OLD | NEW |