diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 19:07:34 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 19:07:34 +0000 |
commit | 3075a7fdc642d705bec27b857d284b5b12c6dff0 (patch) | |
tree | decd2068a70a330e44dae9b7a5f4e26f73ea33cc /chrome/browser | |
parent | a3416f9ba02ce9ca1e52b033fafabeffab50dceb (diff) | |
download | chromium_src-3075a7fdc642d705bec27b857d284b5b12c6dff0.zip chromium_src-3075a7fdc642d705bec27b857d284b5b12c6dff0.tar.gz chromium_src-3075a7fdc642d705bec27b857d284b5b12c6dff0.tar.bz2 |
Move nsimage_cache into base so that it can be accessed from outside of chrome.
This is in support of the next round of rebundling.
TEST=does it still build, do the unit tests still pass, does it still work?
BUG=14610
Review URL: http://codereview.chromium.org/243100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28016 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_view_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/blocked_popup_container_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_menu_bridge.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/nsimage_cache.h | 26 | ||||
-rw-r--r-- | chrome/browser/cocoa/nsimage_cache.mm | 65 | ||||
-rw-r--r-- | chrome/browser/cocoa/nsimage_cache_unittest.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_controller.mm | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_view.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/web_drag_source.mm | 2 |
12 files changed, 12 insertions, 101 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm index 6e468af..79c0b33 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm @@ -5,6 +5,7 @@ #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" #include "app/gfx/text_elider.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #include "base/gfx/rect.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" @@ -12,7 +13,6 @@ #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/bubble_positioner.h" #include "chrome/browser/cocoa/event_utils.h" -#include "chrome/browser/cocoa/nsimage_cache.h" namespace { diff --git a/chrome/browser/cocoa/blocked_popup_container_controller.mm b/chrome/browser/cocoa/blocked_popup_container_controller.mm index f84bb3a..9151750 100644 --- a/chrome/browser/cocoa/blocked_popup_container_controller.mm +++ b/chrome/browser/cocoa/blocked_popup_container_controller.mm @@ -5,9 +5,9 @@ #import "chrome/browser/cocoa/blocked_popup_container_controller.h" #include "app/l10n_util_mac.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #import "chrome/browser/cocoa/bubble_view.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index da36bc1..87b2925 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -4,6 +4,7 @@ #include "app/l10n_util_mac.h" #include "base/mac_util.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_editor.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -19,7 +20,6 @@ #import "chrome/browser/cocoa/event_utils.h" #import "chrome/browser/cocoa/menu_button.h" #import "chrome/browser/cocoa/view_resizer.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" diff --git a/chrome/browser/cocoa/bookmark_menu_bridge.mm b/chrome/browser/cocoa/bookmark_menu_bridge.mm index 70a0983..dd06da6 100644 --- a/chrome/browser/cocoa/bookmark_menu_bridge.mm +++ b/chrome/browser/cocoa/bookmark_menu_bridge.mm @@ -5,6 +5,7 @@ #import <AppKit/AppKit.h> #include "app/l10n_util.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU #import "chrome/browser/app_controller_mac.h" @@ -13,7 +14,6 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/cocoa/bookmark_menu_bridge.h" #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" -#import "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/profile.h" #include "chrome/browser/profile_manager.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/cocoa/nsimage_cache.h b/chrome/browser/cocoa/nsimage_cache.h deleted file mode 100644 index 7085eef..0000000 --- a/chrome/browser/cocoa/nsimage_cache.h +++ /dev/null @@ -1,26 +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. - -#ifndef CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_ -#define CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_ - -#import <Cocoa/Cocoa.h> - -namespace nsimage_cache { - -// Returns an autoreleased image from the main app bundle -// (mac_util::MainAppBundle()) with the given name, and keeps it in memory so -// future fetches are fast. -// NOTE: -// - This should only be called on the main thread. -// - The caller should retain the image if they want to keep it around, as -// the cache could have limit on size/lifetime, etc. -NSImage *ImageNamed(NSString* name); - -// Clears the cache. -void Clear(void); - -} // namespace nsimage_cache - -#endif // CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_ diff --git a/chrome/browser/cocoa/nsimage_cache.mm b/chrome/browser/cocoa/nsimage_cache.mm deleted file mode 100644 index feb0376..0000000 --- a/chrome/browser/cocoa/nsimage_cache.mm +++ /dev/null @@ -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 diff --git a/chrome/browser/cocoa/nsimage_cache_unittest.mm b/chrome/browser/cocoa/nsimage_cache_unittest.mm index 4c348d8..9ecf747 100644 --- a/chrome/browser/cocoa/nsimage_cache_unittest.mm +++ b/chrome/browser/cocoa/nsimage_cache_unittest.mm @@ -6,12 +6,15 @@ #include "base/file_path.h" #include "base/mac_util.h" +#include "base/nsimage_cache_mac.h" #include "base/path_service.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/common/mac_app_names.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +// This tests nsimage_cache, which lives in base/. The unit test is in +// chrome/ because it depends on having a built-up Chrome present. + namespace { class NSImageCacheTest : public PlatformTest { diff --git a/chrome/browser/cocoa/tab_controller.mm b/chrome/browser/cocoa/tab_controller.mm index 231164a..64207f9 100644 --- a/chrome/browser/cocoa/tab_controller.mm +++ b/chrome/browser/cocoa/tab_controller.mm @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "base/mac_util.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #import "chrome/browser/cocoa/tab_controller.h" #import "chrome/browser/cocoa/tab_controller_target.h" #import "chrome/browser/cocoa/tab_view.h" diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index f431c93..411c04a 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -7,10 +7,10 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/mac_util.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/metrics/user_metrics.h" diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm index 4d9bf82..596bfe9 100644 --- a/chrome/browser/cocoa/tab_view.mm +++ b/chrome/browser/cocoa/tab_view.mm @@ -5,7 +5,7 @@ #import "chrome/browser/cocoa/tab_view.h" #include "base/logging.h" -#include "chrome/browser/cocoa/nsimage_cache.h" +#include "base/nsimage_cache_mac.h" #import "chrome/browser/cocoa/tab_controller.h" #import "chrome/browser/cocoa/tab_window_controller.h" diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 579c5da..c36d9e1 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -6,6 +6,7 @@ #include "app/l10n_util_mac.h" #include "base/mac_util.h" +#include "base/nsimage_cache_mac.h" #include "base/sys_string_conversions.h" #include "base/gfx/rect.h" #include "chrome/app/chrome_dll_resource.h" @@ -18,7 +19,6 @@ #import "chrome/browser/cocoa/gradient_button_cell.h" #import "chrome/browser/cocoa/location_bar_view_mac.h" #import "chrome/browser/cocoa/menu_button.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/toolbar_model.h" diff --git a/chrome/browser/cocoa/web_drag_source.mm b/chrome/browser/cocoa/web_drag_source.mm index f4461d4..1d82218 100644 --- a/chrome/browser/cocoa/web_drag_source.mm +++ b/chrome/browser/cocoa/web_drag_source.mm @@ -5,12 +5,12 @@ #import "chrome/browser/cocoa/web_drag_source.h" #include "base/file_util.h" +#include "base/nsimage_cache_mac.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "base/task.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/cocoa/nsimage_cache.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |