Commit 93b41658 authored by mathp@chromium.org's avatar mathp@chromium.org

[Suggestions] Rename ThumbnailManager to ImageManagerImpl

For future use with favicons, remove reference to "thumbnail". There is no functionality change in this CL, just a rename.

BUG=388747
TEST=ImageManager*

Review URL: https://codereview.chromium.org/445753004

Cr-Commit-Position: refs/heads/master@{#288260}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288260 0039d316-1c4b-4281-b951-d872f2087c98
parent d96ab4a3
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_MANAGER_IMPL_H_
#define CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ #define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_MANAGER_IMPL_H_
#include <map> #include <map>
#include <utility> #include <utility>
...@@ -27,21 +27,21 @@ class URLRequestContextGetter; ...@@ -27,21 +27,21 @@ class URLRequestContextGetter;
namespace suggestions { namespace suggestions {
class ImageData;
class SuggestionsProfile; class SuggestionsProfile;
class ThumbnailData;
// A class used to fetch server thumbnails asynchronously and manage the caching // A class used to fetch server images asynchronously and manage the caching
// layer (both in memory and on disk). // layer (both in memory and on disk).
class ThumbnailManager : public ImageManager, class ImageManagerImpl : public ImageManager,
public chrome::BitmapFetcherDelegate { public chrome::BitmapFetcherDelegate {
public: public:
typedef std::vector<ThumbnailData> ThumbnailVector; typedef std::vector<ImageData> ImageDataVector;
ThumbnailManager( ImageManagerImpl(
net::URLRequestContextGetter* url_request_context, net::URLRequestContextGetter* url_request_context,
scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> > database, scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database,
const base::FilePath& database_dir); const base::FilePath& database_dir);
virtual ~ThumbnailManager(); virtual ~ImageManagerImpl();
// Overrides from ImageManager. // Overrides from ImageManager.
virtual void Initialize(const SuggestionsProfile& suggestions) OVERRIDE; virtual void Initialize(const SuggestionsProfile& suggestions) OVERRIDE;
...@@ -51,55 +51,55 @@ class ThumbnailManager : public ImageManager, ...@@ -51,55 +51,55 @@ class ThumbnailManager : public ImageManager,
base::Callback<void(const GURL&, const SkBitmap*)> callback) OVERRIDE; base::Callback<void(const GURL&, const SkBitmap*)> callback) OVERRIDE;
private: private:
friend class MockThumbnailManager; friend class MockImageManagerImpl;
friend class ThumbnailManagerBrowserTest; friend class ImageManagerImplBrowserTest;
FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeTest); FRIEND_TEST_ALL_PREFIXES(ImageManagerImplTest, InitializeTest);
FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FRIEND_TEST_ALL_PREFIXES(ImageManagerImplBrowserTest,
GetImageForURLNetworkCacheHit); GetImageForURLNetworkCacheHit);
FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FRIEND_TEST_ALL_PREFIXES(ImageManagerImplBrowserTest,
GetImageForURLNetworkCacheNotInitialized); GetImageForURLNetworkCacheNotInitialized);
// Used for testing. // Used for testing.
ThumbnailManager(); ImageManagerImpl();
typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> >
CallbackVector; CallbackVector;
typedef base::hash_map<std::string, SkBitmap> ThumbnailMap; typedef base::hash_map<std::string, SkBitmap> ImageMap;
// State related to a thumbnail fetch (associated website url, thumbnail_url, // State related to an image fetch (associated website url, image_url,
// fetcher, pending callbacks). // fetcher, pending callbacks).
struct ThumbnailRequest { struct ImageRequest {
ThumbnailRequest(); ImageRequest();
explicit ThumbnailRequest(chrome::BitmapFetcher* f); explicit ImageRequest(chrome::BitmapFetcher* f);
~ThumbnailRequest(); ~ImageRequest();
void swap(ThumbnailRequest* other) { void swap(ImageRequest* other) {
std::swap(url, other->url); std::swap(url, other->url);
std::swap(thumbnail_url, other->thumbnail_url); std::swap(image_url, other->image_url);
std::swap(callbacks, other->callbacks); std::swap(callbacks, other->callbacks);
std::swap(fetcher, other->fetcher); std::swap(fetcher, other->fetcher);
} }
GURL url; GURL url;
GURL thumbnail_url; GURL image_url;
chrome::BitmapFetcher* fetcher; chrome::BitmapFetcher* fetcher;
// Queue for pending callbacks, which may accumulate while the request is in // Queue for pending callbacks, which may accumulate while the request is in
// flight. // flight.
CallbackVector callbacks; CallbackVector callbacks;
}; };
typedef std::map<const GURL, ThumbnailRequest> ThumbnailRequestMap; typedef std::map<const GURL, ImageRequest> ImageRequestMap;
// Looks up thumbnail for |url|. If found, writes the result to // Looks up image URL for |url|. If found, writes the result to |image_url|
// |thumbnail_url| and returns true. Otherwise just returns false. // and returns true. Otherwise just returns false.
bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url); bool GetImageURL(const GURL& url, GURL* image_url);
void QueueCacheRequest( void QueueCacheRequest(
const GURL& url, const GURL& thumbnail_url, const GURL& url, const GURL& image_url,
base::Callback<void(const GURL&, const SkBitmap*)> callback); base::Callback<void(const GURL&, const SkBitmap*)> callback);
void ServeFromCacheOrNetwork( void ServeFromCacheOrNetwork(
const GURL& url, const GURL& thumbnail_url, const GURL& url, const GURL& image_url,
base::Callback<void(const GURL&, const SkBitmap*)> callback); base::Callback<void(const GURL&, const SkBitmap*)> callback);
// Will return false if no bitmap was found corresponding to |url|, else // Will return false if no bitmap was found corresponding to |url|, else
...@@ -112,59 +112,59 @@ class ThumbnailManager : public ImageManager, ...@@ -112,59 +112,59 @@ class ThumbnailManager : public ImageManager,
SkBitmap* GetBitmapFromCache(const GURL& url); SkBitmap* GetBitmapFromCache(const GURL& url);
void StartOrQueueNetworkRequest( void StartOrQueueNetworkRequest(
const GURL& url, const GURL& thumbnail_url, const GURL& url, const GURL& image_url,
base::Callback<void(const GURL&, const SkBitmap*)> callback); base::Callback<void(const GURL&, const SkBitmap*)> callback);
// Inherited from BitmapFetcherDelegate. Runs on the UI thread. // Inherited from BitmapFetcherDelegate. Runs on the UI thread.
virtual void OnFetchComplete(const GURL thumbnail_url, virtual void OnFetchComplete(const GURL image_url,
const SkBitmap* bitmap) OVERRIDE; const SkBitmap* bitmap) OVERRIDE;
// Save the thumbnail bitmap in the cache and in the database. // Save the image bitmap in the cache and in the database.
void SaveThumbnail(const GURL& url, const SkBitmap& bitmap); void SaveImage(const GURL& url, const SkBitmap& bitmap);
// Database callback methods. // Database callback methods.
// Will initiate loading the entries. // Will initiate loading the entries.
void OnDatabaseInit(bool success); void OnDatabaseInit(bool success);
// Will transfer the loaded |entries| in memory (|thumbnail_map_|). // Will transfer the loaded |entries| in memory (|image_map_|).
void OnDatabaseLoad(bool success, scoped_ptr<ThumbnailVector> entries); void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries);
void OnDatabaseSave(bool success); void OnDatabaseSave(bool success);
// Take entries from the database and put them in the local cache. // Take entries from the database and put them in the local cache.
void LoadEntriesInCache(scoped_ptr<ThumbnailVector> entries); void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries);
void ServePendingCacheRequests(); void ServePendingCacheRequests();
// From SkBitmap to the vector of JPEG-encoded bytes, |dst|. Visible only for // From SkBitmap to the vector of JPEG-encoded bytes, |dst|. Visible only for
// testing. // testing.
static bool EncodeThumbnail(const SkBitmap& bitmap, static bool EncodeImage(const SkBitmap& bitmap,
std::vector<unsigned char>* dest); std::vector<unsigned char>* dest);
// Map from URL to thumbnail URL. Should be kept up to date when a new // Map from URL to image URL. Should be kept up to date when a new
// SuggestionsProfile is available. // SuggestionsProfile is available.
std::map<GURL, GURL> thumbnail_url_map_; std::map<GURL, GURL> image_url_map_;
// Map from each thumbnail URL to the request information (associated website // Map from each image URL to the request information (associated website
// url, fetcher, pending callbacks). // url, fetcher, pending callbacks).
ThumbnailRequestMap pending_net_requests_; ImageRequestMap pending_net_requests_;
// Map from website URL to request information, used for pending cache // Map from website URL to request information, used for pending cache
// requests while the database hasn't loaded. // requests while the database hasn't loaded.
ThumbnailRequestMap pending_cache_requests_; ImageRequestMap pending_cache_requests_;
// Holding the bitmaps in memory, keyed by website URL string. // Holding the bitmaps in memory, keyed by website URL string.
ThumbnailMap thumbnail_map_; ImageMap image_map_;
net::URLRequestContextGetter* url_request_context_; net::URLRequestContextGetter* url_request_context_;
scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> > database_; scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_;
bool database_ready_; bool database_ready_;
base::WeakPtrFactory<ThumbnailManager> weak_ptr_factory_; base::WeakPtrFactory<ImageManagerImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); DISALLOW_COPY_AND_ASSIGN(ImageManagerImpl);
}; };
} // namespace suggestions } // namespace suggestions
#endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_MANAGER_IMPL_H_
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <string> #include <string>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/search/suggestions/thumbnail_manager.h" #include "chrome/browser/search/suggestions/image_manager_impl.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/leveldb_proto/proto_database.h" #include "components/leveldb_proto/proto_database.h"
#include "components/leveldb_proto/testing/fake_db.h" #include "components/leveldb_proto/testing/fake_db.h"
...@@ -17,22 +17,22 @@ ...@@ -17,22 +17,22 @@
namespace { namespace {
using leveldb_proto::test::FakeDB; using leveldb_proto::test::FakeDB;
using suggestions::ThumbnailData; using suggestions::ImageData;
using suggestions::ThumbnailManager; using suggestions::ImageManagerImpl;
typedef base::hash_map<std::string, ThumbnailData> EntryMap; typedef base::hash_map<std::string, ImageData> EntryMap;
const char kTestUrl[] = "http://go.com/"; const char kTestUrl[] = "http://go.com/";
const char kTestThumbnailUrl[] = "http://thumb.com/anchor_download_test.png"; const char kTestImageUrl[] = "http://thumb.com/anchor_download_test.png";
class ThumbnailManagerTest : public testing::Test { class ImageManagerImplTest : public testing::Test {
protected: protected:
ThumbnailManager* CreateThumbnailManager(Profile* profile) { ImageManagerImpl* CreateImageManager(Profile* profile) {
FakeDB<ThumbnailData>* fake_db = new FakeDB<ThumbnailData>(&db_model_); FakeDB<ImageData>* fake_db = new FakeDB<ImageData>(&db_model_);
return new ThumbnailManager( return new ImageManagerImpl(
profile->GetRequestContext(), profile->GetRequestContext(),
scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> >(fake_db), scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> >(fake_db),
FakeDB<ThumbnailData>::DirectoryForTestDB()); FakeDB<ImageData>::DirectoryForTestDB());
} }
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
...@@ -43,23 +43,22 @@ class ThumbnailManagerTest : public testing::Test { ...@@ -43,23 +43,22 @@ class ThumbnailManagerTest : public testing::Test {
namespace suggestions { namespace suggestions {
TEST_F(ThumbnailManagerTest, InitializeTest) { TEST_F(ImageManagerImplTest, InitializeTest) {
SuggestionsProfile suggestions_profile; SuggestionsProfile suggestions_profile;
ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); ChromeSuggestion* suggestion = suggestions_profile.add_suggestions();
suggestion->set_url(kTestUrl); suggestion->set_url(kTestUrl);
suggestion->set_thumbnail(kTestThumbnailUrl); suggestion->set_thumbnail(kTestImageUrl);
TestingProfile profile; TestingProfile profile;
scoped_ptr<ThumbnailManager> thumbnail_manager( scoped_ptr<ImageManagerImpl> image_manager(
CreateThumbnailManager(&profile)); CreateImageManager(&profile));
thumbnail_manager->Initialize(suggestions_profile); image_manager->Initialize(suggestions_profile);
GURL output; GURL output;
EXPECT_TRUE(thumbnail_manager->GetThumbnailURL(GURL(kTestUrl), &output)); EXPECT_TRUE(image_manager->GetImageURL(GURL(kTestUrl), &output));
EXPECT_EQ(GURL(kTestThumbnailUrl), output); EXPECT_EQ(GURL(kTestImageUrl), output);
EXPECT_FALSE( EXPECT_FALSE(image_manager->GetImageURL(GURL("http://b.com"), &output));
thumbnail_manager->GetThumbnailURL(GURL("http://b.com"), &output));
} }
} // namespace suggestions } // namespace suggestions
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/suggestions/thumbnail_manager.h" #include "chrome/browser/search/suggestions/image_manager_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/leveldb_proto/proto_database.h" #include "components/leveldb_proto/proto_database.h"
#include "components/leveldb_proto/proto_database_impl.h" #include "components/leveldb_proto/proto_database_impl.h"
...@@ -65,16 +65,16 @@ KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor( ...@@ -65,16 +65,16 @@ KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
scoped_ptr<BlacklistStore> blacklist_store( scoped_ptr<BlacklistStore> blacklist_store(
new BlacklistStore(the_profile->GetPrefs())); new BlacklistStore(the_profile->GetPrefs()));
scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ThumbnailData> > db( scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData> > db(
new leveldb_proto::ProtoDatabaseImpl<ThumbnailData>( new leveldb_proto::ProtoDatabaseImpl<ImageData>(
background_task_runner)); background_task_runner));
base::FilePath database_dir( base::FilePath database_dir(
the_profile->GetPath().Append(FILE_PATH_LITERAL("Thumbnails"))); the_profile->GetPath().Append(FILE_PATH_LITERAL("Thumbnails")));
scoped_ptr<ThumbnailManager> thumbnail_manager(new ThumbnailManager( scoped_ptr<ImageManagerImpl> thumbnail_manager(new ImageManagerImpl(
the_profile->GetRequestContext(), the_profile->GetRequestContext(),
db.PassAs<leveldb_proto::ProtoDatabase<ThumbnailData> >(), database_dir)); db.PassAs<leveldb_proto::ProtoDatabase<ImageData> >(), database_dir));
return new SuggestionsService( return new SuggestionsService(
the_profile->GetRequestContext(), suggestions_store.Pass(), the_profile->GetRequestContext(), suggestions_store.Pass(),
thumbnail_manager.PassAs<ImageManager>(), blacklist_store.Pass()); thumbnail_manager.PassAs<ImageManager>(), blacklist_store.Pass());
......
...@@ -58,7 +58,7 @@ class SuggestionsSource : public content::URLDataSource { ...@@ -58,7 +58,7 @@ class SuggestionsSource : public content::URLDataSource {
const content::URLDataSource::GotDataCallback& callback, const content::URLDataSource::GotDataCallback& callback,
const SuggestionsProfile& suggestions_profile); const SuggestionsProfile& suggestions_profile);
// Callback for responses from each ThumbnailManager request. // Callback for responses from each Thumbnail request.
void OnThumbnailAvailable(RequestContext* context, base::Closure barrier, void OnThumbnailAvailable(RequestContext* context, base::Closure barrier,
const GURL& url, const SkBitmap* bitmap); const GURL& url, const SkBitmap* bitmap);
......
...@@ -1130,12 +1130,12 @@ ...@@ -1130,12 +1130,12 @@
'browser/search/most_visited_iframe_source.h', 'browser/search/most_visited_iframe_source.h',
'browser/search/search.cc', 'browser/search/search.cc',
'browser/search/search.h', 'browser/search/search.h',
'browser/search/suggestions/image_manager_impl.cc',
'browser/search/suggestions/image_manager_impl.h',
'browser/search/suggestions/suggestions_service_factory.cc', 'browser/search/suggestions/suggestions_service_factory.cc',
'browser/search/suggestions/suggestions_service_factory.h', 'browser/search/suggestions/suggestions_service_factory.h',
'browser/search/suggestions/suggestions_source.cc', 'browser/search/suggestions/suggestions_source.cc',
'browser/search/suggestions/suggestions_source.h', 'browser/search/suggestions/suggestions_source.h',
'browser/search/suggestions/thumbnail_manager.cc',
'browser/search/suggestions/thumbnail_manager.h',
'browser/search_engines/chrome_template_url_service_client.cc', 'browser/search_engines/chrome_template_url_service_client.cc',
'browser/search_engines/chrome_template_url_service_client.h', 'browser/search_engines/chrome_template_url_service_client.h',
'browser/search_engines/default_search_pref_migration.cc', 'browser/search_engines/default_search_pref_migration.cc',
......
...@@ -1347,7 +1347,7 @@ ...@@ -1347,7 +1347,7 @@
'browser/safe_browsing/safe_browsing_blocking_page_test.cc', 'browser/safe_browsing/safe_browsing_blocking_page_test.cc',
'browser/safe_browsing/safe_browsing_service_browsertest.cc', 'browser/safe_browsing/safe_browsing_service_browsertest.cc',
'browser/safe_browsing/safe_browsing_test.cc', 'browser/safe_browsing/safe_browsing_test.cc',
'browser/search/suggestions/thumbnail_manager_browsertest.cc', 'browser/search/suggestions/image_manager_impl_browsertest.cc',
'browser/service_process/service_process_control_browsertest.cc', 'browser/service_process/service_process_control_browsertest.cc',
'browser/services/gcm/fake_gcm_profile_service.cc', 'browser/services/gcm/fake_gcm_profile_service.cc',
'browser/services/gcm/fake_gcm_profile_service.h', 'browser/services/gcm/fake_gcm_profile_service.h',
......
...@@ -1238,7 +1238,7 @@ ...@@ -1238,7 +1238,7 @@
'browser/search/most_visited_iframe_source_unittest.cc', 'browser/search/most_visited_iframe_source_unittest.cc',
'browser/search/search_android_unittest.cc', 'browser/search/search_android_unittest.cc',
'browser/search/search_unittest.cc', 'browser/search/search_unittest.cc',
'browser/search/suggestions/thumbnail_manager_unittest.cc', 'browser/search/suggestions/image_manager_impl_unittest.cc',
'browser/search_engines/default_search_pref_migration_unittest.cc', 'browser/search_engines/default_search_pref_migration_unittest.cc',
'browser/search_engines/search_provider_install_data_unittest.cc', 'browser/search_engines/search_provider_install_data_unittest.cc',
'browser/search_engines/template_url_fetcher_unittest.cc', 'browser/search_engines/template_url_fetcher_unittest.cc',
......
...@@ -52,11 +52,11 @@ message SuggestionsBlacklist { ...@@ -52,11 +52,11 @@ message SuggestionsBlacklist {
repeated string urls = 1; repeated string urls = 1;
} }
// ThumbnailData contains the data to represent a website thumbnail. // ImageData contains the data to represent a website image (e.g. thumbnail).
// //
// Next tag: 3 // Next tag: 3
message ThumbnailData { message ImageData {
// The URL of the website represented by this Thumbnail. // The URL of the website represented by this image.
optional string url = 1; optional string url = 1;
// Bitmap bytes, encoded as JPEG. // Bitmap bytes, encoded as JPEG.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment