| 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 #include "chrome/browser/android/thumbnail/thumbnail_cache.h" | 5 #include "chrome/browser/android/thumbnail/thumbnail_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 thumbnail->CreateUIResource(); | 820 thumbnail->CreateUIResource(); |
| 821 | 821 |
| 822 cache_.Put(tab_id, std::move(thumbnail)); | 822 cache_.Put(tab_id, std::move(thumbnail)); |
| 823 NotifyObserversOfThumbnailRead(tab_id); | 823 NotifyObserversOfThumbnailRead(tab_id); |
| 824 } | 824 } |
| 825 | 825 |
| 826 ReadNextThumbnail(); | 826 ReadNextThumbnail(); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void ThumbnailCache::NotifyObserversOfThumbnailRead(TabId tab_id) { | 829 void ThumbnailCache::NotifyObserversOfThumbnailRead(TabId tab_id) { |
| 830 FOR_EACH_OBSERVER( | 830 for (ThumbnailCacheObserver& observer : observers_) |
| 831 ThumbnailCacheObserver, observers_, OnFinishedThumbnailRead(tab_id)); | 831 observer.OnFinishedThumbnailRead(tab_id); |
| 832 } | 832 } |
| 833 | 833 |
| 834 void ThumbnailCache::RemoveOnMatchedTimeStamp(TabId tab_id, | 834 void ThumbnailCache::RemoveOnMatchedTimeStamp(TabId tab_id, |
| 835 const base::Time& time_stamp) { | 835 const base::Time& time_stamp) { |
| 836 // We remove the cached version if it matches the tab_id and the time_stamp. | 836 // We remove the cached version if it matches the tab_id and the time_stamp. |
| 837 Thumbnail* thumbnail = cache_.Get(tab_id); | 837 Thumbnail* thumbnail = cache_.Get(tab_id); |
| 838 Thumbnail* approx_thumbnail = approximation_cache_.Get(tab_id); | 838 Thumbnail* approx_thumbnail = approximation_cache_.Get(tab_id); |
| 839 if ((thumbnail && thumbnail->time_stamp() == time_stamp) || | 839 if ((thumbnail && thumbnail->time_stamp() == time_stamp) || |
| 840 (approx_thumbnail && approx_thumbnail->time_stamp() == time_stamp)) { | 840 (approx_thumbnail && approx_thumbnail->time_stamp() == time_stamp)) { |
| 841 Remove(tab_id); | 841 Remove(tab_id); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 return std::make_pair(dst_bitmap, new_scale * scale); | 933 return std::make_pair(dst_bitmap, new_scale * scale); |
| 934 } | 934 } |
| 935 | 935 |
| 936 void ThumbnailCache::OnMemoryPressure( | 936 void ThumbnailCache::OnMemoryPressure( |
| 937 base::MemoryPressureListener::MemoryPressureLevel level) { | 937 base::MemoryPressureListener::MemoryPressureLevel level) { |
| 938 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 938 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 939 cache_.Clear(); | 939 cache_.Clear(); |
| 940 approximation_cache_.Clear(); | 940 approximation_cache_.Clear(); |
| 941 } | 941 } |
| 942 } | 942 } |
| OLD | NEW |