OLD | NEW |
1 // Copyright (c) 2010 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 "app/mac/nsimage_cache.h" | 5 #include "ui/gfx/mac/nsimage_cache.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
11 | 11 |
12 // When C++ exceptions are disabled, the C++ library defines |try| and | 12 // When C++ exceptions are disabled, the C++ library defines |try| and |
13 // |catch| so as to allow exception-expecting C++ code to build properly when | 13 // |catch| so as to allow exception-expecting C++ code to build properly when |
14 // language support for exceptions is not present. These macros interfere | 14 // language support for exceptions is not present. These macros interfere |
15 // with the use of |@try| and |@catch| in Objective-C files such as this one. | 15 // with the use of |@try| and |@catch| in Objective-C files such as this one. |
16 // Undefine these macros here, after everything has been #included, since | 16 // Undefine these macros here, after everything has been #included, since |
17 // there will be no C++ uses and only Objective-C uses from this point on. | 17 // there will be no C++ uses and only Objective-C uses from this point on. |
18 #undef try | 18 #undef try |
19 #undef catch | 19 #undef catch |
20 | 20 |
21 namespace app { | 21 namespace gfx { |
22 namespace mac { | |
23 | 22 |
24 static NSMutableDictionary* image_cache = nil; | 23 static NSMutableDictionary* image_cache = nil; |
25 | 24 |
26 NSImage* GetCachedImageWithName(NSString* name) { | 25 NSImage* GetCachedImageWithName(NSString* name) { |
27 DCHECK(name); | 26 DCHECK(name); |
28 | 27 |
29 // NOTE: to make this thread safe, we'd have to sync on the cache and | 28 // NOTE: to make this thread safe, we'd have to sync on the cache and |
30 // also force all the bundle calls on the main thread. | 29 // also force all the bundle calls on the main thread. |
31 | 30 |
32 if (!image_cache) { | 31 if (!image_cache) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // TODO: if we ever limit the cache size, this should retain & autorelease | 63 // TODO: if we ever limit the cache size, this should retain & autorelease |
65 // the image. | 64 // the image. |
66 return result; | 65 return result; |
67 } | 66 } |
68 | 67 |
69 void ClearCachedImages(void) { | 68 void ClearCachedImages(void) { |
70 // NOTE: to make this thread safe, we'd have to sync on the cache. | 69 // NOTE: to make this thread safe, we'd have to sync on the cache. |
71 [image_cache removeAllObjects]; | 70 [image_cache removeAllObjects]; |
72 } | 71 } |
73 | 72 |
74 } // namespace mac | 73 } // namespace gfx |
75 } // namespace app | |
OLD | NEW |