Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: ui/gfx/color_profile_win.cc

Issue 293393008: gfx/ui/color_profile: add color profile cache on win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698