| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/icon_manager.h" | 5 #include "chrome/browser/icon_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void RunCallbackIfNotCanceled( | 16 void RunCallbackIfNotCanceled( |
| 17 const CancelableTaskTracker::IsCanceledCallback& is_canceled, | 17 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled, |
| 18 const IconManager::IconRequestCallback& callback, | 18 const IconManager::IconRequestCallback& callback, |
| 19 gfx::Image* image) { | 19 gfx::Image* image) { |
| 20 if (is_canceled.Run()) | 20 if (is_canceled.Run()) |
| 21 return; | 21 return; |
| 22 callback.Run(image); | 22 callback.Run(image); |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 struct IconManager::ClientRequest { | 27 struct IconManager::ClientRequest { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 48 | 48 |
| 49 gfx::Image* IconManager::LookupIconFromGroup(const IconGroupID& group, | 49 gfx::Image* IconManager::LookupIconFromGroup(const IconGroupID& group, |
| 50 IconLoader::IconSize size) { | 50 IconLoader::IconSize size) { |
| 51 IconMap::iterator it = icon_cache_.find(CacheKey(group, size)); | 51 IconMap::iterator it = icon_cache_.find(CacheKey(group, size)); |
| 52 if (it != icon_cache_.end()) | 52 if (it != icon_cache_.end()) |
| 53 return it->second; | 53 return it->second; |
| 54 | 54 |
| 55 return NULL; | 55 return NULL; |
| 56 } | 56 } |
| 57 | 57 |
| 58 CancelableTaskTracker::TaskId IconManager::LoadIcon( | 58 base::CancelableTaskTracker::TaskId IconManager::LoadIcon( |
| 59 const base::FilePath& file_name, | 59 const base::FilePath& file_name, |
| 60 IconLoader::IconSize size, | 60 IconLoader::IconSize size, |
| 61 const IconRequestCallback& callback, | 61 const IconRequestCallback& callback, |
| 62 CancelableTaskTracker* tracker) { | 62 base::CancelableTaskTracker* tracker) { |
| 63 IconLoader* loader = new IconLoader(file_name, size, this); | 63 IconLoader* loader = new IconLoader(file_name, size, this); |
| 64 loader->AddRef(); | 64 loader->AddRef(); |
| 65 loader->Start(); | 65 loader->Start(); |
| 66 | 66 |
| 67 CancelableTaskTracker::IsCanceledCallback is_canceled; | 67 base::CancelableTaskTracker::IsCanceledCallback is_canceled; |
| 68 CancelableTaskTracker::TaskId id = tracker->NewTrackedTaskId(&is_canceled); | 68 base::CancelableTaskTracker::TaskId id = |
| 69 tracker->NewTrackedTaskId(&is_canceled); |
| 69 IconRequestCallback callback_runner = base::Bind( | 70 IconRequestCallback callback_runner = base::Bind( |
| 70 &RunCallbackIfNotCanceled, is_canceled, callback); | 71 &RunCallbackIfNotCanceled, is_canceled, callback); |
| 71 | 72 |
| 72 ClientRequest client_request = { callback_runner, file_name, size }; | 73 ClientRequest client_request = { callback_runner, file_name, size }; |
| 73 requests_[loader] = client_request; | 74 requests_[loader] = client_request; |
| 74 return id; | 75 return id; |
| 75 } | 76 } |
| 76 | 77 |
| 77 // IconLoader::Delegate implementation ----------------------------------------- | 78 // IconLoader::Delegate implementation ----------------------------------------- |
| 78 | 79 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 IconLoader::IconSize size) | 139 IconLoader::IconSize size) |
| 139 : group(group), | 140 : group(group), |
| 140 size(size) { | 141 size(size) { |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool IconManager::CacheKey::operator<(const CacheKey &other) const { | 144 bool IconManager::CacheKey::operator<(const CacheKey &other) const { |
| 144 if (group != other.group) | 145 if (group != other.group) |
| 145 return group < other.group; | 146 return group < other.group; |
| 146 return size < other.size; | 147 return size < other.size; |
| 147 } | 148 } |
| OLD | NEW |