Index: ui/gfx/color_profile_win.cc |
diff --git a/ui/gfx/color_profile_win.cc b/ui/gfx/color_profile_win.cc |
index 43ea465795834f735a133d8cb9b8b79c80ea60e9..67f1b7016ce65f76bbfd67760027a9c5defb04e8 100644 |
--- a/ui/gfx/color_profile_win.cc |
+++ b/ui/gfx/color_profile_win.cc |
@@ -4,12 +4,57 @@ |
#include "ui/gfx/color_profile.h" |
+#include <map> |
#include <windows.h> |
#include "base/file_util.h" |
+#include "base/lazy_instance.h" |
+#include "base/synchronization/lock.h" |
namespace gfx { |
+class ColorProfileCache { |
+ public: |
+ // A thread-safe cache of color profiles keyed by windows device name. |
+ ColorProfileCache() {} |
+ |
+ bool Find(const std::wstring& device, std::vector<char>* profile) { |
+ base::AutoLock lock(lock_); |
+ DeviceColorProfile::const_iterator it = cache_.find(device); |
+ if (it == cache_.end()) |
+ return false; |
+ *profile = it->second; |
+ return true; |
+ } |
+ |
+ void Insert(const std::wstring& device, const std::vector<char>& profile) { |
+ base::AutoLock lock(lock_); |
+ cache_[device] = profile; |
+ } |
+ |
+ bool Erase(const std::wstring& device) { |
+ base::AutoLock lock(lock_); |
+ DeviceColorProfile::iterator it = cache_.find(device); |
+ if (it == cache_.end()) |
+ return false; |
+ cache_.erase(device); |
+ return true; |
+ } |
+ |
+ void Clear() { |
+ base::AutoLock lock(lock_); |
+ cache_.clear(); |
+ } |
+ |
+ private: |
+ typedef std::map<std::wstring, std::vector<char> > DeviceColorProfile; |
+ |
+ DeviceColorProfile cache_; |
+ base::Lock lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ColorProfileCache); |
+}; |
+ |
bool GetDisplayColorProfile(const gfx::Rect& bounds, |
std::vector<char>* profile) { |
if (bounds.IsEmpty()) |