diff options
28 files changed, 88 insertions, 113 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index 40326c5..40651ce 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -246,10 +246,10 @@ class Writer : public Task { BookmarkFaviconFetcher::URLFaviconMap::iterator itr = favicons_map_->find(url_string); if (itr != favicons_map_->end()) { - scoped_refptr<RefCountedBytes> data = itr->second.get(); + scoped_refptr<RefCountedMemory> data = itr->second.get(); std::string favicon_data; - favicon_data.assign(reinterpret_cast<char*>(&data->data.front()), - data->data.size()); + favicon_data.assign(reinterpret_cast<const char*>(data->front()), + data->size()); std::string favicon_base64_encoded; if (base::Base64Encode(favicon_data, &favicon_base64_encoded)) { GURL favicon_url("data:image/png;base64," + favicon_base64_encoded); @@ -450,7 +450,7 @@ bool BookmarkFaviconFetcher::FetchNextFavicon() { void BookmarkFaviconFetcher::OnFavIconDataAvailable( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { GURL url; @@ -458,7 +458,7 @@ void BookmarkFaviconFetcher::OnFavIconDataAvailable( url = GURL(bookmark_urls_.front()); bookmark_urls_.pop_front(); } - if (know_favicon && data.get() && !data->data.empty() && !url.is_empty()) { + if (know_favicon && data.get() && data->size() && !url.is_empty()) { favicons_map_->insert(make_pair(url.spec(), data)); } diff --git a/chrome/browser/bookmarks/bookmark_html_writer.h b/chrome/browser/bookmarks/bookmark_html_writer.h index 0eba67f..58da351 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.h +++ b/chrome/browser/bookmarks/bookmark_html_writer.h @@ -38,7 +38,7 @@ class BookmarksExportObserver { class BookmarkFaviconFetcher: public NotificationObserver { public: // Map of URL and corresponding favicons. - typedef std::map<std::string, scoped_refptr<RefCountedBytes> > URLFaviconMap; + typedef std::map<std::string, scoped_refptr<RefCountedMemory> > URLFaviconMap; BookmarkFaviconFetcher(Profile* profile, const FilePath& path, @@ -69,7 +69,7 @@ class BookmarkFaviconFetcher: public NotificationObserver { // html output on the file thread. void OnFavIconDataAvailable(FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index 73fc5ea..96da421 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -765,7 +765,7 @@ BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( void BookmarkModel::OnFavIconDataAvailable( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { SkBitmap fav_icon; diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 391792f..6e238bc 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -429,7 +429,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { void OnFavIconDataAvailable( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); diff --git a/chrome/browser/cocoa/history_menu_bridge.h b/chrome/browser/cocoa/history_menu_bridge.h index 488909f..bfa7959b 100644 --- a/chrome/browser/cocoa/history_menu_bridge.h +++ b/chrome/browser/cocoa/history_menu_bridge.h @@ -132,7 +132,7 @@ class HistoryMenuBridge : public NotificationObserver, // GetFaviconForHistoryItem() was called on (UI thread). void GotFaviconData(FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL url); diff --git a/chrome/browser/cocoa/history_menu_bridge.mm b/chrome/browser/cocoa/history_menu_bridge.mm index d66dc37..85b9a72 100644 --- a/chrome/browser/cocoa/history_menu_bridge.mm +++ b/chrome/browser/cocoa/history_menu_bridge.mm @@ -371,7 +371,7 @@ void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL url) { // Since we're going to do Cocoa-y things, make sure this is the main thread. diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index b5ef7f02..c6fb306 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -142,9 +142,6 @@ DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents, // static RefCountedMemory* DOMUIFactory::GetFaviconResourceBytes(Profile* profile, const GURL& page_url) { - // The extensions DOM UI might need to load the favicon file so we alwyas run - // this on the FILE thread. - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); if (page_url.SchemeIs(chrome::kExtensionScheme)) return ExtensionDOMUI::GetFaviconResourceBytes(profile, page_url); diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.cc b/chrome/browser/dom_ui/dom_ui_favicon_source.cc index 4ec0ce8..582b281 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.cc +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.cc @@ -42,7 +42,7 @@ void DOMUIFavIconSource::StartDataRequest(const std::string& path, void DOMUIFavIconSource::OnFavIconDataAvailable( FaviconService::Handle request_handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { FaviconService* favicon_service = @@ -50,7 +50,7 @@ void DOMUIFavIconSource::OnFavIconDataAvailable( int request_id = cancelable_consumer_.GetClientData(favicon_service, request_handle); - if (know_favicon && data.get() && !data->data.empty()) { + if (know_favicon && data.get() && data->size()) { // Forward the data along to the networking system. SendResponse(request_id, data); } else { diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.h b/chrome/browser/dom_ui/dom_ui_favicon_source.h index b0db79b..a3ba511 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.h +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.h @@ -36,7 +36,7 @@ class DOMUIFavIconSource : public ChromeURLDataManager::DataSource { // Called when favicon data is available from the history backend. void OnFavIconDataAvailable(FaviconService::Handle request_handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL url); diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc index 424dd80e..e9866b1 100644 --- a/chrome/browser/extensions/extension_dom_ui.cc +++ b/chrome/browser/extensions/extension_dom_ui.cc @@ -27,8 +27,9 @@ const wchar_t kExtensionURLOverrides[] = L"extensions.chrome_url_overrides"; // Returns a piece of memory with the contents of the file |path|. RefCountedMemory* ReadFileData(const FilePath& path) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - + // TODO(arv): We currently read this on the UI thread since extension objects + // can only safely be accessed on the UI thread. Read the file on the FILE + // thread and cache the result on the UI thread instead. if (path.empty()) return NULL; @@ -71,7 +72,7 @@ void ExtensionDOMUI::ResetExtensionFunctionDispatcher( void ExtensionDOMUI::ResetExtensionBookmarkManagerEventRouter() { if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableTabbedBookmarkManager)) { + switches::kEnableTabbedBookmarkManager)) { extension_bookmark_manager_event_router_.reset( new ExtensionBookmarkManagerEventRouter(GetProfile(), tab_contents())); } @@ -317,6 +318,9 @@ void ExtensionDOMUI::UnregisterChromeURLOverrides( // static RefCountedMemory* ExtensionDOMUI::GetFaviconResourceBytes(Profile* profile, GURL page_url) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)) << "The extension " + "objects should only be accessed on the UI thread."; + // Even when the extensions service is enabled by default, it's still // disabled in incognito mode. ExtensionsService* service = profile->GetExtensionsService(); diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc index eaa3eb3..e17daa7 100644 --- a/chrome/browser/fav_icon_helper.cc +++ b/chrome/browser/fav_icon_helper.cc @@ -9,6 +9,7 @@ #include "app/gfx/codec/png_codec.h" #include "app/gfx/favicon_size.h" #include "base/callback.h" +#include "base/ref_counted_memory.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" @@ -89,9 +90,9 @@ void FavIconHelper::SetFavIcon( } void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, - const std::vector<unsigned char>& data) { + scoped_refptr<RefCountedMemory> data) { SkBitmap image; - gfx::PNGCodec::Decode(&data.front(), data.size(), &image); + gfx::PNGCodec::Decode(data->front(), data->size(), &image); UpdateFavIcon(entry, image); } @@ -166,7 +167,7 @@ NavigationEntry* FavIconHelper::GetEntry() { void FavIconHelper::OnFavIconDataForInitialURL( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { NavigationEntry* entry = GetEntry(); @@ -184,8 +185,8 @@ void FavIconHelper::OnFavIconDataForInitialURL( // to be expired (or the wrong url) we'll fetch later on. This way the // user doesn't see a flash of the default favicon. entry->favicon().set_url(icon_url); - if (data && !data->data.empty()) - UpdateFavIcon(entry, data->data); + if (data.get() && data->size()) + UpdateFavIcon(entry, data); entry->favicon().set_is_valid(true); } @@ -238,7 +239,7 @@ void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { void FavIconHelper::OnFavIconData( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { NavigationEntry* entry = GetEntry(); @@ -248,11 +249,11 @@ void FavIconHelper::OnFavIconData( // No need to update the favicon url. By the time we get here // UpdateFavIconURL will have set the favicon url. - if (know_favicon && data && !data->data.empty()) { + if (know_favicon && data.get() && data->size()) { // There is a favicon, set it now. If expired we'll download the current // one again, but at least the user will get some icon instead of the // default and most likely the current one is fine anyway. - UpdateFavIcon(entry, data->data); + UpdateFavIcon(entry, data); } if (!know_favicon || expired) { diff --git a/chrome/browser/fav_icon_helper.h b/chrome/browser/fav_icon_helper.h index e5e1b23..008ba7e 100644 --- a/chrome/browser/fav_icon_helper.h +++ b/chrome/browser/fav_icon_helper.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/callback.h" -#include "base/ref_counted_memory.h" #include "base/scoped_ptr.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/favicon_service.h" @@ -20,6 +19,7 @@ class NavigationEntry; class Profile; +class RefCountedMemory; class SkBitmap; class TabContents; @@ -120,7 +120,7 @@ class FavIconHelper : public RenderViewHostDelegate::FavIcon { // See description above class for details. void OnFavIconDataForInitialURL(FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); @@ -132,7 +132,7 @@ class FavIconHelper : public RenderViewHostDelegate::FavIcon { // See description above class for details. void OnFavIconData(FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); @@ -149,7 +149,7 @@ class FavIconHelper : public RenderViewHostDelegate::FavIcon { // If the TabContents has a delegate, it is notified of the new favicon // (INVALIDATE_FAVICON). void UpdateFavIcon(NavigationEntry* entry, - const std::vector<unsigned char>& data); + scoped_refptr<RefCountedMemory> data); void UpdateFavIcon(NavigationEntry* entry, const SkBitmap& image); // Scales the image such that either the width and/or height is 16 pixels diff --git a/chrome/browser/favicon_service.cc b/chrome/browser/favicon_service.cc index 621d93b..0c24c80 100644 --- a/chrome/browser/favicon_service.cc +++ b/chrome/browser/favicon_service.cc @@ -49,12 +49,14 @@ FaviconService::Handle FaviconService::GetFaviconForURL( FaviconDataCallback* callback) { GetFaviconRequest* request = new GetFaviconRequest(callback); AddRequest(request, consumer); - + FaviconService::Handle handle = request->handle(); if (page_url.SchemeIs(chrome::kChromeUIScheme) || page_url.SchemeIs(chrome::kExtensionScheme)) { - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, &FaviconService::GetFaviconForDOMUIOnFileThread, - request, page_url)); + scoped_refptr<RefCountedMemory> icon_data = + DOMUIFactory::GetFaviconResourceBytes(profile_, page_url); + bool know_icon = icon_data.get() != NULL && icon_data->size() > 0; + request->ForwardResultAsync(FaviconDataCallback::TupleType(handle, + know_icon, icon_data, false, GURL())); } else { HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); if (hs) @@ -62,40 +64,9 @@ FaviconService::Handle FaviconService::GetFaviconForURL( else ForwardEmptyResultAsync(request); } - return request->handle(); -} - -void FaviconService::GetFaviconForDOMUIOnFileThread(GetFaviconRequest* request, - const GURL& page_url) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - DCHECK(page_url.SchemeIs(chrome::kChromeUIScheme) || - page_url.SchemeIs(chrome::kExtensionScheme)); - - // TODO(erg): For now, we're cheating here. DOMUIFactory returns the new - // RefCountedMemory superclass, but consumers of favicon information are - // still all hardcoded to use RefCountedBytes. For now, just copy the - // favicon data in this case because the returned RefCountedMemory class is - // the statically allocated memory one; not the vector backed - // RefCountedBytes. - - scoped_refptr<RefCountedBytes> icon_data = NULL; - scoped_refptr<RefCountedMemory> static_memory( - DOMUIFactory::GetFaviconResourceBytes(profile_, page_url)); - bool know_icon = static_memory.get() != NULL; - - if (know_icon) { - std::vector<unsigned char> bytes; - bytes.insert(bytes.begin(), - static_memory->front(), - static_memory->front() + static_memory->size()); - icon_data = RefCountedBytes::TakeVector(&bytes); - } - - request->ForwardResult(FaviconDataCallback::TupleType(request->handle(), - know_icon, icon_data, false, GURL())); + return handle; } - void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); if (hs) diff --git a/chrome/browser/favicon_service.h b/chrome/browser/favicon_service.h index 3cc2880..a7b500c 100644 --- a/chrome/browser/favicon_service.h +++ b/chrome/browser/favicon_service.h @@ -38,11 +38,11 @@ class FaviconService : public CancelableRequestProvider, // opposed to not knowing anything). |expired| will be set to true if we // refreshed the favicon "too long" ago and should be updated if the page // is visited again. - typedef Callback5<Handle, // handle - bool, // know_favicon - scoped_refptr<RefCountedBytes>, // data - bool, // expired - GURL>::Type // url of the favicon + typedef Callback5<Handle, // handle + bool, // know_favicon + scoped_refptr<RefCountedMemory>, // data + bool, // expired + GURL>::Type // url of the favicon FaviconDataCallback; typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest; @@ -91,11 +91,6 @@ class FaviconService : public CancelableRequestProvider, ~FaviconService() {} - // This is used to get the favicon for DOMUI on the file thread since these - // might be loaded from disk. - void GetFaviconForDOMUIOnFileThread(GetFaviconRequest* request, - const GURL& page_url); - Profile* profile_; // Helper to forward an empty result if we cannot get the history service. diff --git a/chrome/browser/gtk/list_store_favicon_loader.cc b/chrome/browser/gtk/list_store_favicon_loader.cc index 4623dcf..e20211a 100644 --- a/chrome/browser/gtk/list_store_favicon_loader.cc +++ b/chrome/browser/gtk/list_store_favicon_loader.cc @@ -62,17 +62,18 @@ bool ListStoreFavIconLoader::GetRowByFavIconHandle( void ListStoreFavIconLoader::OnGotFavIcon( FaviconService::Handle handle, bool know_fav_icon, - scoped_refptr<RefCountedBytes> image_data, bool is_expired, GURL icon_url) { + scoped_refptr<RefCountedMemory> image_data, bool is_expired, + GURL icon_url) { GtkTreeIter iter; if (!GetRowByFavIconHandle(handle, &iter)) return; gtk_list_store_set(list_store_, &iter, favicon_handle_col_, 0, -1); - if (know_fav_icon && image_data.get() && !image_data->data.empty()) { + if (know_fav_icon && image_data.get() && image_data->size()) { SkBitmap icon; - if (gfx::PNGCodec::Decode(&image_data->data.front(), - image_data->data.size(), &icon)) { + if (gfx::PNGCodec::Decode(image_data->front(), + image_data->size(), &icon)) { GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); gtk_list_store_set(list_store_, &iter, favicon_col_, pixbuf, diff --git a/chrome/browser/gtk/list_store_favicon_loader.h b/chrome/browser/gtk/list_store_favicon_loader.h index 8be5b9ba..8d68e3c 100644 --- a/chrome/browser/gtk/list_store_favicon_loader.h +++ b/chrome/browser/gtk/list_store_favicon_loader.h @@ -38,7 +38,7 @@ class ListStoreFavIconLoader { // Callback from FaviconService:::GetFavIconForURL void OnGotFavIcon(FaviconService::Handle handle, bool know_fav_icon, - scoped_refptr<RefCountedBytes> image_data, bool is_expired, + scoped_refptr<RefCountedMemory> image_data, bool is_expired, GURL icon_url); // The list store we are loading favicons into. diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index 53ad780..b1b9d09 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -433,7 +433,7 @@ void HistoryService::SetFavicon(const GURL& page_url, ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::SetFavIcon, page_url, icon_url, - scoped_refptr<RefCountedBytes>(new RefCountedBytes(image_data))); + scoped_refptr<RefCountedMemory>(new RefCountedBytes(image_data))); } void HistoryService::SetFaviconOutOfDateForPage(const GURL& page_url) { diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 33c079a..420095e 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -1445,7 +1445,8 @@ void HistoryBackend::SetImportedFavicons( favicon_id = thumbnail_db_->AddFavIcon(favicon_usage[i].favicon_url); if (!favicon_id) continue; // Unable to add the favicon. - thumbnail_db_->SetFavIcon(favicon_id, favicon_usage[i].png_data, now); + thumbnail_db_->SetFavIcon(favicon_id, + new RefCountedBytes(favicon_usage[i].png_data), now); } // Save the mapping from all the URLs to the favicon. @@ -1561,7 +1562,7 @@ void HistoryBackend::GetFavIconForURL( void HistoryBackend::SetFavIcon( const GURL& page_url, const GURL& icon_url, - scoped_refptr<RefCountedBytes> data) { + scoped_refptr<RefCountedMemory> data) { DCHECK(data.get()); if (!thumbnail_db_.get() || !db_.get()) return; @@ -1571,7 +1572,7 @@ void HistoryBackend::SetFavIcon( id = thumbnail_db_->AddFavIcon(icon_url); // Set the image data. - thumbnail_db_->SetFavIcon(id, data->data, Time::Now()); + thumbnail_db_->SetFavIcon(id, data, Time::Now()); SetFavIconMapping(page_url, id); } diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 34817a7..cfd1637 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -191,7 +191,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, const GURL& page_url); void SetFavIcon(const GURL& page_url, const GURL& icon_url, - scoped_refptr<RefCountedBytes> data); + scoped_refptr<RefCountedMemory> data); void UpdateFavIconMappingAndFetch(scoped_refptr<GetFavIconRequest> request, const GURL& page_url, const GURL& icon_url); diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index e1c8d47..5be4a77 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -6,6 +6,7 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" +#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history_backend.h" @@ -183,12 +184,12 @@ TEST_F(HistoryBackendTest, DeleteAll) { std::vector<unsigned char> data; data.push_back('1'); - EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon( - favicon1, data, Time::Now())); + EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon(favicon1, + new RefCountedBytes(data), Time::Now())); data[0] = '2'; EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon( - favicon2, data, Time::Now())); + favicon2, new RefCountedBytes(data), Time::Now())); // First visit two URLs. URLRow row1(GURL("http://www.google.com/")); @@ -311,11 +312,11 @@ TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { std::vector<unsigned char> data; data.push_back('1'); EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon( - favicon1, data, Time::Now())); + favicon1, new RefCountedBytes(data), Time::Now())); data[0] = '2'; EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon( - favicon2, data, Time::Now())); + favicon2, new RefCountedBytes(data), Time::Now())); // First visit two URLs. URLRow row1(GURL("http://www.google.com/")); @@ -509,7 +510,8 @@ TEST_F(HistoryBackendTest, ImportedFaviconsTest) { FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1); std::vector<unsigned char> data; data.push_back('1'); - EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon(favicon1, data, Time::Now())); + EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon(favicon1, + RefCountedBytes::TakeVector(&data), Time::Now())); URLRow row1(GURL("http://www.google.com/")); row1.set_favicon_id(favicon1); row1.set_visit_count(1); diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc index 4e6f372..9fab35c 100644 --- a/chrome/browser/history/thumbnail_database.cc +++ b/chrome/browser/history/thumbnail_database.cc @@ -11,6 +11,7 @@ #if defined(OS_MACOSX) #include "base/mac_util.h" #endif +#include "base/ref_counted_memory.h" #include "base/time.h" #include "base/string_util.h" #include "chrome/browser/diagnostics/sqlite_diagnostics.h" @@ -305,17 +306,17 @@ bool ThumbnailDatabase::ThumbnailScoreForId(URLID id, } bool ThumbnailDatabase::SetFavIcon(URLID icon_id, - const std::vector<unsigned char>& icon_data, + scoped_refptr<RefCountedMemory> icon_data, base::Time time) { DCHECK(icon_id); - if (icon_data.size()) { + if (icon_data->size()) { sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, "UPDATE favicons SET image_data=?, last_updated=? WHERE id=?")); if (!statement) return 0; - statement.BindBlob(0, &icon_data.front(), - static_cast<int>(icon_data.size())); + statement.BindBlob(0, icon_data->front(), + static_cast<int>(icon_data->size())); statement.BindInt64(1, time.ToTimeT()); statement.BindInt64(2, icon_id); return statement.Run(); diff --git a/chrome/browser/history/thumbnail_database.h b/chrome/browser/history/thumbnail_database.h index 362edec..fb24357 100644 --- a/chrome/browser/history/thumbnail_database.h +++ b/chrome/browser/history/thumbnail_database.h @@ -10,11 +10,13 @@ #include "app/sql/connection.h" #include "app/sql/init_status.h" #include "app/sql/meta_table.h" +#include "base/ref_counted.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/url_database.h" // For DBCloseScoper. #include "chrome/browser/meta_table_helper.h" class FilePath; +class RefCountedMemory; struct ThumbnailScore; class SkBitmap; @@ -88,7 +90,7 @@ class ThumbnailDatabase { // The time indicates the access time, and is used to detect when the favicon // should be refreshed. bool SetFavIcon(FavIconID icon_id, - const std::vector<unsigned char>& icon_data, + scoped_refptr<RefCountedMemory> icon_data, base::Time time); // Sets the time the favicon was last updated. diff --git a/chrome/browser/jumplist.cc b/chrome/browser/jumplist.cc index 21c80e1..c59cd7b 100644 --- a/chrome/browser/jumplist.cc +++ b/chrome/browser/jumplist.cc @@ -750,12 +750,12 @@ void JumpList::OnSegmentUsageAvailable( void JumpList::OnFavIconDataAvailable( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { // Attach the received data to the ShellLinkItem object. // This data will be decoded by JumpListUpdateTask. - if (know_favicon && data.get() && !data->data.empty()) { + if (know_favicon && data.get() && data->size()) { if (!icon_urls_.empty() && icon_urls_.front().second) icon_urls_.front().second->SetIconData(data); } diff --git a/chrome/browser/jumplist.h b/chrome/browser/jumplist.h index 5ba7e04..9d9d49b 100644 --- a/chrome/browser/jumplist.h +++ b/chrome/browser/jumplist.h @@ -45,7 +45,7 @@ class ShellLinkItem : public base::RefCountedThreadSafe<ShellLinkItem> { const std::wstring& title() const { return title_; } const std::wstring& icon() const { return icon_; } int index() const { return index_; } - scoped_refptr<RefCountedBytes> data() const { return data_; } + scoped_refptr<RefCountedMemory> data() const { return data_; } void SetArguments(const std::wstring& arguments) { arguments_ = arguments; @@ -61,7 +61,7 @@ class ShellLinkItem : public base::RefCountedThreadSafe<ShellLinkItem> { favicon_ = favicon; } - void SetIconData(scoped_refptr<RefCountedBytes> data) { + void SetIconData(scoped_refptr<RefCountedMemory> data) { data_ = data; } @@ -73,7 +73,7 @@ class ShellLinkItem : public base::RefCountedThreadSafe<ShellLinkItem> { std::wstring arguments_; std::wstring title_; std::wstring icon_; - scoped_refptr<RefCountedBytes> data_; + scoped_refptr<RefCountedMemory> data_; int index_; bool favicon_; @@ -159,7 +159,7 @@ class JumpList : public TabRestoreService::Observer { // decompresses collected fav icons and updates a JumpList. void OnFavIconDataAvailable(HistoryService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); diff --git a/chrome/browser/possible_url_model.cc b/chrome/browser/possible_url_model.cc index bfe3c1a..12269e4 100644 --- a/chrome/browser/possible_url_model.cc +++ b/chrome/browser/possible_url_model.cc @@ -169,7 +169,7 @@ int PossibleURLModel::CompareValues(int row1, int row2, int column_id) { void PossibleURLModel::OnFavIconAvailable( FaviconService::Handle h, bool fav_icon_available, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { if (profile_) { diff --git a/chrome/browser/possible_url_model.h b/chrome/browser/possible_url_model.h index ac3013c..973a2dd 100644 --- a/chrome/browser/possible_url_model.h +++ b/chrome/browser/possible_url_model.h @@ -49,7 +49,7 @@ class PossibleURLModel : public TableModel { virtual void OnFavIconAvailable(FaviconService::Handle h, bool fav_icon_available, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url); diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 894f56f..614e44b 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -97,7 +97,7 @@ class ModelEntry { void OnFavIconDataAvailable( FaviconService::Handle handle, bool know_favicon, - scoped_refptr<RefCountedBytes> data, + scoped_refptr<RefCountedMemory> data, bool expired, GURL icon_url) { load_state_ = LOADED; diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index e9c9e01..b00ae94 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -107,7 +107,7 @@ class CustomHomePagesTableModel : public TableModel { // fav_icon_handle matches handle and notifies the observer of the change. void OnGotFavIcon(FaviconService::Handle handle, bool know_fav_icon, - scoped_refptr<RefCountedBytes> image_data, + scoped_refptr<RefCountedMemory> image_data, bool is_expired, GURL icon_url); @@ -231,18 +231,18 @@ void CustomHomePagesTableModel::LoadFavIcon(Entry* entry) { void CustomHomePagesTableModel::OnGotFavIcon( FaviconService::Handle handle, bool know_fav_icon, - scoped_refptr<RefCountedBytes> image_data, + scoped_refptr<RefCountedMemory> image_data, bool is_expired, GURL icon_url) { int entry_index; Entry* entry = GetEntryByLoadHandle(handle, &entry_index); DCHECK(entry); entry->fav_icon_handle = 0; - if (know_fav_icon && image_data.get() && !image_data->data.empty()) { + if (know_fav_icon && image_data.get() && image_data->size()) { int width, height; std::vector<unsigned char> decoded_data; - if (gfx::PNGCodec::Decode(&image_data->data.front(), - image_data->data.size(), + if (gfx::PNGCodec::Decode(image_data->front(), + image_data->size(), gfx::PNGCodec::FORMAT_BGRA, &decoded_data, &width, &height)) { entry->icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); |