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

Unified Diff: chrome/browser/cocoa/nsimage_cache.mm

Issue 243100: Move nsimage_cache into base so that it can be accessed from outside of chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « chrome/browser/cocoa/nsimage_cache.h ('k') | chrome/browser/cocoa/nsimage_cache_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/nsimage_cache.mm
===================================================================
--- chrome/browser/cocoa/nsimage_cache.mm (revision 28009)
+++ chrome/browser/cocoa/nsimage_cache.mm (working copy)
@@ -1,65 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/cocoa/nsimage_cache.h"
-
-#include "base/logging.h"
-#include "base/mac_util.h"
-
-// When C++ exceptions are disabled, the C++ library defines |try| and
-// |catch| so as to allow exception-expecting C++ code to build properly when
-// language support for exceptions is not present. These macros interfere
-// with the use of |@try| and |@catch| in Objective-C files such as this one.
-// Undefine these macros here, after everything has been #included, since
-// there will be no C++ uses and only Objective-C uses from this point on.
-#undef try
-#undef catch
-
-namespace nsimage_cache {
-
-static NSMutableDictionary *image_cache = nil;
-
-NSImage *ImageNamed(NSString *name) {
- DCHECK(name);
-
- // NOTE: to make this thread safe, we'd have to sync on the cache and
- // also force all the bundle calls on the main thread.
-
- if (!image_cache) {
- image_cache = [[NSMutableDictionary alloc] init];
- DCHECK(image_cache);
- }
-
- NSImage *result = [image_cache objectForKey:name];
- if (!result) {
- DLOG_IF(INFO, [[name pathExtension] length] == 0)
- << "Suggest including the extension in the image name";
-
- NSString *path = [mac_util::MainAppBundle() pathForImageResource:name];
- if (path) {
- @try {
- result = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
- if (result)
- [image_cache setObject:result forKey:name];
- }
- @catch (id err) {
- DLOG(ERROR) << "Failed to load the image for name '"
- << [name UTF8String] << "' from path '" << [path UTF8String]
- << "', error: " << [err description];
- result = nil;
- }
- }
- }
-
- // TODO: if we ever limit the cache size, this should retain & autorelease
- // the image.
- return result;
-}
-
-void Clear(void) {
- // NOTE: to make this thread safe, we'd have to sync on the cache.
- [image_cache removeAllObjects];
-}
-
-} // namespace nsimage_cache
« no previous file with comments | « chrome/browser/cocoa/nsimage_cache.h ('k') | chrome/browser/cocoa/nsimage_cache_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698