Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: components/suggestions/image_manager.h

Issue 630073002: [Suggestions] Create ImageEncoder, to abstract away image encode/decode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ 5 #ifndef COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_
6 #define COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ 6 #define COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace net { 24 namespace net {
25 class URLRequestContextGetter; 25 class URLRequestContextGetter;
26 } 26 }
27 27
28 namespace suggestions { 28 namespace suggestions {
29 29
30 class ImageData; 30 class ImageData;
31 class ImageEncoder;
31 class ImageFetcher; 32 class ImageFetcher;
32 class SuggestionsProfile; 33 class SuggestionsProfile;
33 34
34 // A class used to fetch server images asynchronously and manage the caching 35 // A class used to fetch server images asynchronously and manage the caching
35 // layer (both in memory and on disk). 36 // layer (both in memory and on disk).
36 class ImageManager : public ImageFetcherDelegate { 37 class ImageManager : public ImageFetcherDelegate {
37 public: 38 public:
38 typedef std::vector<ImageData> ImageDataVector; 39 typedef std::vector<ImageData> ImageDataVector;
39 40
40 ImageManager(scoped_ptr<ImageFetcher> image_fetcher, 41 ImageManager(scoped_ptr<ImageFetcher> image_fetcher,
huangs 2014/10/06 17:14:18 Add comments to state that ownerships of |image_fe
Mathieu 2014/10/06 18:13:35 Done.
42 scoped_ptr<ImageEncoder> image_encoder,
41 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database, 43 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database,
42 const base::FilePath& database_dir); 44 const base::FilePath& database_dir);
43 virtual ~ImageManager(); 45 virtual ~ImageManager();
44 46
45 virtual void Initialize(const SuggestionsProfile& suggestions); 47 virtual void Initialize(const SuggestionsProfile& suggestions);
46 48
47 // Should be called from the UI thread. 49 // Should be called from the UI thread.
48 virtual void GetImageForURL( 50 virtual void GetImageForURL(
49 const GURL& url, 51 const GURL& url,
50 base::Callback<void(const GURL&, const SkBitmap*)> callback); 52 base::Callback<void(const GURL&, const SkBitmap*)> callback);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void OnDatabaseInit(bool success); 114 void OnDatabaseInit(bool success);
113 // Will transfer the loaded |entries| in memory (|image_map_|). 115 // Will transfer the loaded |entries| in memory (|image_map_|).
114 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries); 116 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries);
115 void OnDatabaseSave(bool success); 117 void OnDatabaseSave(bool success);
116 118
117 // Take entries from the database and put them in the local cache. 119 // Take entries from the database and put them in the local cache.
118 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries); 120 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries);
119 121
120 void ServePendingCacheRequests(); 122 void ServePendingCacheRequests();
121 123
122 // From SkBitmap to the vector of JPEG-encoded bytes, |dst|. Visible only for
123 // testing.
124 static bool EncodeImage(const SkBitmap& bitmap,
125 std::vector<unsigned char>* dest);
126
127 // Map from URL to image URL. Should be kept up to date when a new 124 // Map from URL to image URL. Should be kept up to date when a new
128 // SuggestionsProfile is available. 125 // SuggestionsProfile is available.
129 std::map<GURL, GURL> image_url_map_; 126 std::map<GURL, GURL> image_url_map_;
130 127
131 // Map from website URL to request information, used for pending cache 128 // Map from website URL to request information, used for pending cache
132 // requests while the database hasn't loaded. 129 // requests while the database hasn't loaded.
133 ImageCacheRequestMap pending_cache_requests_; 130 ImageCacheRequestMap pending_cache_requests_;
134 131
135 // Holding the bitmaps in memory, keyed by website URL string. 132 // Holding the bitmaps in memory, keyed by website URL string.
136 ImageMap image_map_; 133 ImageMap image_map_;
137 134
138 scoped_ptr<ImageFetcher> image_fetcher_; 135 scoped_ptr<ImageFetcher> image_fetcher_;
139 136
137 scoped_ptr<ImageEncoder> image_encoder_;
138
140 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_; 139 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_;
141 140
142 bool database_ready_; 141 bool database_ready_;
143 142
144 base::WeakPtrFactory<ImageManager> weak_ptr_factory_; 143 base::WeakPtrFactory<ImageManager> weak_ptr_factory_;
145 144
146 base::ThreadChecker thread_checker_; 145 base::ThreadChecker thread_checker_;
147 146
148 DISALLOW_COPY_AND_ASSIGN(ImageManager); 147 DISALLOW_COPY_AND_ASSIGN(ImageManager);
149 }; 148 };
150 149
151 } // namespace suggestions 150 } // namespace suggestions
152 151
153 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ 152 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698