| 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 #include "ppapi/proxy/ppb_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // Adds the given image data to the cache. There should be no plugin | 237 // Adds the given image data to the cache. There should be no plugin |
| 238 // references to it. This may delete an older item from the cache. | 238 // references to it. This may delete an older item from the cache. |
| 239 void Add(ImageData* image_data); | 239 void Add(ImageData* image_data); |
| 240 | 240 |
| 241 // Notification from the renderer that the given image data is usable. | 241 // Notification from the renderer that the given image data is usable. |
| 242 void ImageDataUsable(ImageData* image_data); | 242 void ImageDataUsable(ImageData* image_data); |
| 243 | 243 |
| 244 void DidDeleteInstance(PP_Instance instance); | 244 void DidDeleteInstance(PP_Instance instance); |
| 245 | 245 |
| 246 private: | 246 private: |
| 247 friend struct LeakySingletonTraits<ImageDataCache>; | 247 friend struct base::LeakySingletonTraits<ImageDataCache>; |
| 248 | 248 |
| 249 // Timer callback to expire entries for the given instance. | 249 // Timer callback to expire entries for the given instance. |
| 250 void OnTimer(PP_Instance instance); | 250 void OnTimer(PP_Instance instance); |
| 251 | 251 |
| 252 typedef std::map<PP_Instance, ImageDataInstanceCache> CacheMap; | 252 typedef std::map<PP_Instance, ImageDataInstanceCache> CacheMap; |
| 253 CacheMap cache_; | 253 CacheMap cache_; |
| 254 | 254 |
| 255 // This class does timer calls and we don't want to run these outside of the | 255 // This class does timer calls and we don't want to run these outside of the |
| 256 // scope of the object. Technically, since this class is a leaked static, | 256 // scope of the object. Technically, since this class is a leaked static, |
| 257 // this will never happen and this factory is unnecessary. However, it's | 257 // this will never happen and this factory is unnecessary. However, it's |
| 258 // probably better not to make assumptions about the lifetime of this class. | 258 // probably better not to make assumptions about the lifetime of this class. |
| 259 base::WeakPtrFactory<ImageDataCache> weak_factory_; | 259 base::WeakPtrFactory<ImageDataCache> weak_factory_; |
| 260 | 260 |
| 261 DISALLOW_COPY_AND_ASSIGN(ImageDataCache); | 261 DISALLOW_COPY_AND_ASSIGN(ImageDataCache); |
| 262 }; | 262 }; |
| 263 | 263 |
| 264 // static | 264 // static |
| 265 ImageDataCache* ImageDataCache::GetInstance() { | 265 ImageDataCache* ImageDataCache::GetInstance() { |
| 266 return Singleton<ImageDataCache, | 266 return base::Singleton<ImageDataCache, |
| 267 LeakySingletonTraits<ImageDataCache> >::get(); | 267 base::LeakySingletonTraits<ImageDataCache>>::get(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 scoped_refptr<ImageData> ImageDataCache::Get( | 270 scoped_refptr<ImageData> ImageDataCache::Get( |
| 271 PP_Instance instance, | 271 PP_Instance instance, |
| 272 PPB_ImageData_Shared::ImageDataType type, | 272 PPB_ImageData_Shared::ImageDataType type, |
| 273 int width, int height, | 273 int width, int height, |
| 274 PP_ImageDataFormat format) { | 274 PP_ImageDataFormat format) { |
| 275 CacheMap::iterator found = cache_.find(instance); | 275 CacheMap::iterator found = cache_.find(instance); |
| 276 if (found == cache_.end()) | 276 if (found == cache_.end()) |
| 277 return scoped_refptr<ImageData>(); | 277 return scoped_refptr<ImageData>(); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // still cached in our process, the proxy still holds a reference so we can | 680 // still cached in our process, the proxy still holds a reference so we can |
| 681 // remove the one the renderer just sent is. If the proxy no longer holds a | 681 // remove the one the renderer just sent is. If the proxy no longer holds a |
| 682 // reference, we released everything and we should also release the one the | 682 // reference, we released everything and we should also release the one the |
| 683 // renderer just sent us. | 683 // renderer just sent us. |
| 684 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 684 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
| 685 API_ID_PPB_CORE, old_image_data)); | 685 API_ID_PPB_CORE, old_image_data)); |
| 686 } | 686 } |
| 687 | 687 |
| 688 } // namespace proxy | 688 } // namespace proxy |
| 689 } // namespace ppapi | 689 } // namespace ppapi |
| OLD | NEW |