Chromium Code Reviews| 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..3185bb499dc4e76ea60f0563a7f91c499795a076 100644 |
| --- a/ui/gfx/color_profile_win.cc |
| +++ b/ui/gfx/color_profile_win.cc |
| @@ -4,12 +4,64 @@ |
| #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 { |
| +typedef std::map<std::wstring, std::vector<char> > ColorProfileMap; |
| + |
| +base::LazyInstance<ColorProfileMap>::Leaky g_color_profile_map = |
|
sky
2014/05/28 15:31:21
Seems like you only want ColorProfileCache as the
|
| + LAZY_INSTANCE_INITIALIZER; |
| +base::LazyInstance<base::Lock>::Leaky g_color_profile_map_lock; |
|
sky
2014/05/28 15:31:21
These are not globals, remove the g_.
|
| + |
| +struct ColorProfileCache { |
|
sky
2014/05/28 15:31:21
Make this a class (see https://engdoc.corp.google.
|
| + ColorProfileCache() {} |
| + |
| + bool find(std::wstring device, std::vector<char>* profile) { |
| + base::AutoLock lock(g_color_profile_map_lock.Get()); |
| + |
| + ColorProfileMap* cache = g_color_profile_map.Pointer(); |
| + ColorProfileMap::const_iterator it = cache->find(device); |
| + if (it == cache->end()) |
| + return false; |
| + |
| + const char* data = it->second.data(); |
|
sky
2014/05/28 15:31:21
*profile = it->second; ?
|
| + profile->assign(data, data + it->second.size()); |
| + return true; |
| + } |
| + |
| + void insert(std::wstring device, const std::vector<char>& profile) { |
|
sky
2014/05/28 15:31:21
const std::wstring&
|
| + base::AutoLock lock(g_color_profile_map_lock.Get()); |
| + |
| + ColorProfileMap* cache = g_color_profile_map.Pointer(); |
| + (*cache)[device] = profile; |
| + } |
| + |
| + bool erase(std::wstring device) { |
|
sky
2014/05/28 15:31:21
const std::wstring&
|
| + base::AutoLock lock(g_color_profile_map_lock.Get()); |
| + |
| + ColorProfileMap* cache = g_color_profile_map.Pointer(); |
| + ColorProfileMap::iterator it = cache->find(device); |
| + if (it == cache->end()) |
| + return false; |
| + |
| + cache->erase(device); |
| + return true; |
| + } |
| + |
| + void clear() { |
| + base::AutoLock lock(g_color_profile_map_lock.Get()); |
| + |
| + ColorProfileMap* cache = g_color_profile_map.Pointer(); |
| + cache->clear(); |
| + } |
| +}; |
| + |
| bool GetDisplayColorProfile(const gfx::Rect& bounds, |
| std::vector<char>* profile) { |
| if (bounds.IsEmpty()) |