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

Side by Side Diff: ash/app_list/icon_cache.cc

Issue 10388032: Move app list from ash to ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix win_aura bot and comments in #5 Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/app_list/icon_cache.h ('k') | ash/app_list/page_switcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/app_list/icon_cache.h"
6
7 #include "base/logging.h"
8 #include "base/md5.h"
9 #include "ui/gfx/size.h"
10
11 namespace {
12
13 // Gets cache key based on |image| contents and desired |size|.
14 std::string GetKey(const SkBitmap& image, const gfx::Size& size) {
15 SkAutoLockPixels image_lock(image);
16 base::MD5Digest digest;
17 MD5Sum(image.getPixels(), image.getSize(), &digest);
18
19 return MD5DigestToBase16(digest) + "." + size.ToString();
20 }
21
22 } // namespace
23
24 namespace ash {
25
26 // static
27 IconCache* IconCache::instance_ = NULL;
28
29 // static
30 void IconCache::CreateInstance() {
31 DCHECK(!instance_);
32 instance_ = new IconCache;
33 }
34
35 // static
36 void IconCache::DeleteInstance() {
37 DCHECK(instance_);
38 delete instance_;
39 instance_ = NULL;
40 }
41
42 // static
43 IconCache* IconCache::GetInstance() {
44 DCHECK(instance_);
45 return instance_;
46 }
47
48 void IconCache::MarkAllEntryUnused() {
49 for (Cache::iterator i = cache_.begin(); i != cache_.end(); ++i)
50 i->second.used = false;
51 }
52
53 void IconCache::PurgeAllUnused() {
54 for (Cache::iterator i = cache_.begin(); i != cache_.end();) {
55 Cache::iterator current(i);
56 ++i;
57 if (!current->second.used)
58 cache_.erase(current);
59 }
60 }
61
62 bool IconCache::Get(const SkBitmap& src,
63 const gfx::Size& size,
64 SkBitmap* processed) {
65 Cache::iterator it = cache_.find(GetKey(src, size));
66 if (it == cache_.end())
67 return false;
68
69 it->second.used = true;
70
71 if (processed)
72 *processed = it->second.image;
73 return true;
74 }
75
76 void IconCache::Put(const SkBitmap& src,
77 const gfx::Size& size,
78 const SkBitmap& processed) {
79 const std::string key = GetKey(src, size);
80 cache_[key].image = processed;
81 cache_[key].used = true;
82 }
83
84 IconCache::IconCache() {
85 }
86
87 IconCache::~IconCache() {
88 }
89
90 } // namespace ash
OLDNEW
« no previous file with comments | « ash/app_list/icon_cache.h ('k') | ash/app_list/page_switcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698