diff options
-rw-r--r-- | chrome/browser/browser.vcproj | 10 | ||||
-rw-r--r-- | chrome/browser/icon_loader.cc | 34 | ||||
-rw-r--r-- | chrome/browser/icon_loader.h | 35 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 15 | ||||
-rw-r--r-- | chrome/browser/icon_loader_mac.mm | 15 | ||||
-rw-r--r-- | chrome/browser/icon_loader_win.cc | 39 | ||||
-rw-r--r-- | chrome/browser/icon_loader_win.h | 40 | ||||
-rw-r--r-- | chrome/browser/icon_manager.cc | 32 | ||||
-rw-r--r-- | chrome/browser/icon_manager.h | 22 | ||||
-rw-r--r-- | chrome/browser/icon_manager_linux.cc | 12 | ||||
-rw-r--r-- | chrome/browser/icon_manager_mac.mm | 12 | ||||
-rw-r--r-- | chrome/browser/icon_manager_win.cc | 15 | ||||
-rw-r--r-- | chrome/chrome.gyp | 8 |
13 files changed, 173 insertions, 116 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index def66f1..0dfa68d 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -378,15 +378,15 @@ > </File> <File - RelativePath=".\icon_loader.h" + RelativePath=".\icon_loader.cc" > </File> <File - RelativePath=".\icon_loader_win.cc" + RelativePath=".\icon_loader.h" > </File> <File - RelativePath=".\icon_loader_win.h" + RelativePath=".\icon_loader_win.cc" > </File> <File @@ -398,6 +398,10 @@ > </File> <File + RelativePath=".\icon_manager_win.cc" + > + </File> + <File RelativePath=".\ime_input.cc" > </File> diff --git a/chrome/browser/icon_loader.cc b/chrome/browser/icon_loader.cc new file mode 100644 index 0000000..6896427 --- /dev/null +++ b/chrome/browser/icon_loader.cc @@ -0,0 +1,34 @@ +// 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/icon_loader.h" + +#include "base/message_loop.h" +#include "base/thread.h" +#include "chrome/browser/browser_process.h" +#include "skia/include/SkBitmap.h" + +IconLoader::IconLoader(const IconGroupID& group, IconSize size, + Delegate* delegate) + : group_(group), + icon_size_(size), + bitmap_(NULL), + delegate_(delegate) { +} + +IconLoader::~IconLoader() { + delete bitmap_; +} + +void IconLoader::Start() { + target_message_loop_ = MessageLoop::current(); + + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(this, &IconLoader::ReadIcon)); +} + +void IconLoader::NotifyDelegate() { + delegate_->OnBitmapLoaded(this, bitmap_); + bitmap_ = NULL; +} diff --git a/chrome/browser/icon_loader.h b/chrome/browser/icon_loader.h index a02c6ba..b7e76ba 100644 --- a/chrome/browser/icon_loader.h +++ b/chrome/browser/icon_loader.h @@ -11,6 +11,16 @@ #include "base/file_path.h" #include "base/ref_counted.h" +#if defined(OS_WIN) +// On Windows, we group files by their extension, with several exceptions: +// .dll, .exe, .ico. See IconManager.h for explanation. +typedef std::wstring IconGroupID; +#elif defined(OS_POSIX) +// On POSIX, we group files by MIME type. +typedef std::string IconGroupID; +#endif + +class MessageLoop; class SkBitmap; //////////////////////////////////////////////////////////////////////////////// @@ -35,18 +45,29 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> { virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result) = 0; }; - IconLoader() { } + IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate); - virtual ~IconLoader() { } + virtual ~IconLoader(); // Start reading the icon on the file thread. - virtual void Start() = 0; - - // Factory method for returning a platform specific IconLoad. - static IconLoader* Create(const FilePath& path, IconSize size, - Delegate* delegate); + void Start(); private: + void ReadIcon(); + + void NotifyDelegate(); + + // The message loop object of the thread in which we notify the delegate. + MessageLoop* target_message_loop_; + + IconGroupID group_; + + IconSize icon_size_; + + SkBitmap* bitmap_; + + Delegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(IconLoader); }; diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc new file mode 100644 index 0000000..83a8305 --- /dev/null +++ b/chrome/browser/icon_loader_linux.cc @@ -0,0 +1,15 @@ +// 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/icon_loader.h" + +#include "base/message_loop.h" +#include "base/thread.h" + +void IconLoader::ReadIcon() { + NOTIMPLEMENTED(); + + target_message_loop_->PostTask(FROM_HERE, + NewRunnableMethod(this, &IconLoader::NotifyDelegate)); +} diff --git a/chrome/browser/icon_loader_mac.mm b/chrome/browser/icon_loader_mac.mm new file mode 100644 index 0000000..83a8305 --- /dev/null +++ b/chrome/browser/icon_loader_mac.mm @@ -0,0 +1,15 @@ +// 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/icon_loader.h" + +#include "base/message_loop.h" +#include "base/thread.h" + +void IconLoader::ReadIcon() { + NOTIMPLEMENTED(); + + target_message_loop_->PostTask(FROM_HERE, + NewRunnableMethod(this, &IconLoader::NotifyDelegate)); +} diff --git a/chrome/browser/icon_loader_win.cc b/chrome/browser/icon_loader_win.cc index 998faf1..1d47c37 100644 --- a/chrome/browser/icon_loader_win.cc +++ b/chrome/browser/icon_loader_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/icon_loader_win.h" +#include "chrome/browser/icon_loader.h" #include <windows.h> #include <shellapi.h> @@ -11,34 +11,8 @@ #include "base/gfx/size.h" #include "base/message_loop.h" #include "base/thread.h" -#include "chrome/browser/browser_process.h" -#include "skia/include/SkBitmap.h" -IconLoader* IconLoader::Create(const FilePath& path, IconSize size, - Delegate* delegate) { - return new IconLoaderWin(path, size, delegate); -} - -IconLoaderWin::IconLoaderWin(const FilePath& path, IconSize size, - Delegate* delegate) - : path_(path), - icon_size_(size), - bitmap_(NULL), - delegate_(delegate) { -} - -IconLoaderWin::~IconLoaderWin() { - delete bitmap_; -} - -void IconLoaderWin::Start() { - target_message_loop_ = MessageLoop::current(); - - g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, &IconLoaderWin::ReadIcon)); -} - -void IconLoaderWin::ReadIcon() { +void IconLoader::ReadIcon() { int size = 0; switch (icon_size_) { case IconLoader::SMALL: @@ -54,7 +28,7 @@ void IconLoaderWin::ReadIcon() { NOTREACHED(); } SHFILEINFO file_info = { 0 }; - if (!SHGetFileInfo(path_.value().c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, + if (!SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, sizeof(SHFILEINFO), SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) return; @@ -71,10 +45,5 @@ void IconLoaderWin::ReadIcon() { bitmap_ = IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size); target_message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &IconLoaderWin::NotifyDelegate)); -} - -void IconLoaderWin::NotifyDelegate() { - delegate_->OnBitmapLoaded(this, bitmap_); - bitmap_ = NULL; + NewRunnableMethod(this, &IconLoader::NotifyDelegate)); } diff --git a/chrome/browser/icon_loader_win.h b/chrome/browser/icon_loader_win.h deleted file mode 100644 index ca6c96a..0000000 --- a/chrome/browser/icon_loader_win.h +++ /dev/null @@ -1,40 +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_ICON_LOADER_WIN_H_ -#define CHROME_BROWSER_ICON_LOADER_WIN_H_ - -#include "chrome/browser/icon_loader.h" - -class MessageLoop; - -class IconLoaderWin : public IconLoader { - public: - IconLoaderWin(const FilePath& path, IconSize size, Delegate* delegate); - - virtual ~IconLoaderWin(); - - // IconLoader implementation. - virtual void Start(); - - private: - void ReadIcon(); - - void NotifyDelegate(); - - // The message loop object of the thread in which we notify the delegate. - MessageLoop* target_message_loop_; - - FilePath path_; - - IconSize icon_size_; - - SkBitmap* bitmap_; - - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(IconLoaderWin); -}; - -#endif // CHROME_BROWSER_ICON_LOADER_WIN_H_ diff --git a/chrome/browser/icon_manager.cc b/chrome/browser/icon_manager.cc index 827e0b1..f2a0cef 100644 --- a/chrome/browser/icon_manager.cc +++ b/chrome/browser/icon_manager.cc @@ -19,14 +19,8 @@ IconManager::~IconManager() { SkBitmap* IconManager::LookupIcon(const FilePath& file_name, IconLoader::IconSize size) { - FilePath path = file_name; - FilePath::StringType extension = file_util::GetFileExtensionFromPath(path); -#if defined(OS_WIN) - if (extension != L"exe" && extension != L"dll" && extension != L"ico") - path = FilePath(L'.' + extension); -#endif - - IconMap::iterator it = icon_cache_.find(CacheKey(path, size)); + IconGroupID group = GetGroupIDFromFilepath(file_name); + IconMap::iterator it = icon_cache_.find(CacheKey(group, size)); if (it != icon_cache_.end()) return it->second; @@ -38,20 +32,14 @@ IconManager::Handle IconManager::LoadIcon( IconLoader::IconSize size, CancelableRequestConsumerBase* consumer, IconRequestCallback* callback) { - FilePath path = file_name; - FilePath::StringType extension = file_util::GetFileExtensionFromPath(path); -#if defined(OS_WIN) - if (extension != L"exe" && extension != L"dll" && extension != L"ico") - path = FilePath(L'.' + extension); -#endif - + IconGroupID group = GetGroupIDFromFilepath(file_name); IconRequest* request = new IconRequest(callback); AddRequest(request, consumer); - IconLoader* loader = IconLoader::Create(path, size, this); + IconLoader* loader = new IconLoader(group, size, this); loader->AddRef(); loader->Start(); - ClientRequest client_request = { request, path, size }; + ClientRequest client_request = { request, group, size }; requests_[loader] = client_request; return request->handle(); } @@ -77,7 +65,7 @@ bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) { // Cache the bitmap. Watch out: |result| or the cached bitmap may be NULL to // indicate a current or past failure. - CacheKey key(client_request.file_name, client_request.size); + CacheKey key(client_request.group, client_request.size); IconMap::iterator it = icon_cache_.find(key); if (it != icon_cache_.end() && result && it->second) { it->second->swap(*result); @@ -96,14 +84,14 @@ bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) { return true; // Indicates we took ownership of result. } -IconManager::CacheKey::CacheKey(const FilePath& file_name, +IconManager::CacheKey::CacheKey(const IconGroupID& group, IconLoader::IconSize size) - : file_name(file_name), + : group(group), size(size) { } bool IconManager::CacheKey::operator<(const CacheKey &other) const { - if (file_name != other.file_name) - return file_name < other.file_name; + if (group != other.group) + return group < other.group; return size < other.size; } diff --git a/chrome/browser/icon_manager.h b/chrome/browser/icon_manager.h index fbd0cd1..44d17da 100644 --- a/chrome/browser/icon_manager.h +++ b/chrome/browser/icon_manager.h @@ -25,6 +25,9 @@ // file extension and the results will be cached per extension. That way, all // .mp3 files will share one icon, but all .exe files will have their own icon. // +// POSIX files don't have associated icons. We query the OS by the file's +// mime type. +// // The IconManager can be queried in two ways: // 1. A quick, synchronous check of its caches which does not touch the disk: // IconManager::LookupIcon() @@ -47,14 +50,15 @@ #include <string> #include "base/hash_tables.h" -#include "chrome/browser/icon_loader.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/icon_loader.h" +class FilePath; class SkBitmap; class IconManager : public IconLoader::Delegate, public CancelableRequestProvider { -public: + public: IconManager(); ~IconManager(); @@ -83,14 +87,18 @@ public: // IconLoader::Delegate interface. virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result); -private: + // Get the identifying string for the given file. The implementation + // is in icon_manager_[platform].cc. + static IconGroupID GetGroupIDFromFilepath(const FilePath& path); + + private: struct CacheKey { - CacheKey(const FilePath& file_name, IconLoader::IconSize size); + CacheKey(const IconGroupID& group, IconLoader::IconSize size); // Used as a key in the map below, so we need this comparator. bool operator<(const CacheKey &other) const; - FilePath file_name; + IconGroupID group; IconLoader::IconSize size; }; @@ -100,12 +108,12 @@ private: typedef CancelableRequest<IconRequestCallback> IconRequest; typedef struct { scoped_refptr<IconRequest> request; - FilePath file_name; + IconGroupID group; IconLoader::IconSize size; } ClientRequest; // Asynchronous requests that have not yet been completed. - typedef base::hash_map<IconLoader*, ClientRequest> ClientRequests; + typedef std::map<IconLoader*, ClientRequest> ClientRequests; ClientRequests requests_; DISALLOW_COPY_AND_ASSIGN(IconManager); diff --git a/chrome/browser/icon_manager_linux.cc b/chrome/browser/icon_manager_linux.cc new file mode 100644 index 0000000..3e5d8be --- /dev/null +++ b/chrome/browser/icon_manager_linux.cc @@ -0,0 +1,12 @@ +// 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/icon_manager.h" + +#include "base/file_path.h" + +IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) { + NOTIMPLEMENTED(); + return std::string(); +} diff --git a/chrome/browser/icon_manager_mac.mm b/chrome/browser/icon_manager_mac.mm new file mode 100644 index 0000000..3e5d8be --- /dev/null +++ b/chrome/browser/icon_manager_mac.mm @@ -0,0 +1,12 @@ +// 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/icon_manager.h" + +#include "base/file_path.h" + +IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) { + NOTIMPLEMENTED(); + return std::string(); +} diff --git a/chrome/browser/icon_manager_win.cc b/chrome/browser/icon_manager_win.cc new file mode 100644 index 0000000..b1eb860 --- /dev/null +++ b/chrome/browser/icon_manager_win.cc @@ -0,0 +1,15 @@ +// 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/icon_manager.h" + +#include "base/file_path.h" + +IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) { + std::wstring extension = filepath.Extension(); + if (extension != L".exe" && extension != L".dll" && extension != L".ico") + return extension; + else + return filepath.value(); +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 29ac0b9..390d6f8c 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -961,10 +961,14 @@ 'browser/history/visitsegment_database.h', 'browser/hung_renderer_dialog.h', 'browser/icon_loader.h', + 'browser/icon_loader_linux.cc', + 'browser/icon_loader_mac.mm', 'browser/icon_loader_win.cc', - 'browser/icon_loader_win.h', 'browser/icon_manager.cc', 'browser/icon_manager.h', + 'browser/icon_manager_linux.cc', + 'browser/icon_manager_mac.mm', + 'browser/icon_manager_win.cc', 'browser/ime_input.cc', 'browser/ime_input.h', 'browser/importer/firefox2_importer.cc', @@ -1497,6 +1501,7 @@ 'browser/bookmarks/bookmark_context_menu.cc', 'browser/bookmarks/bookmark_drop_info.cc', 'browser/debugger/debugger_shell_stubs.cc', + 'browser/icon_manager.cc', ], 'sources': [ # Build the necessary GTM sources @@ -1581,7 +1586,6 @@ 'browser/history/history_indexer.idl', 'browser/history_tab_ui.cc', 'browser/history_view.cc', - 'browser/icon_manager.cc', 'browser/ime_input.cc', 'browser/importer/ie_importer.cc', 'browser/jankometer.cc', |