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

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

Issue 634273002: Revert of [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
« no previous file with comments | « components/suggestions/image_encoder.h ('k') | components/suggestions/image_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
32 class ImageFetcher; 31 class ImageFetcher;
33 class SuggestionsProfile; 32 class SuggestionsProfile;
34 33
35 // A class used to fetch server images asynchronously and manage the caching 34 // A class used to fetch server images asynchronously and manage the caching
36 // layer (both in memory and on disk). 35 // layer (both in memory and on disk).
37 class ImageManager : public ImageFetcherDelegate { 36 class ImageManager : public ImageFetcherDelegate {
38 public: 37 public:
39 typedef std::vector<ImageData> ImageDataVector; 38 typedef std::vector<ImageData> ImageDataVector;
40 39
41 // This class takes ownership of |image_fetcher|, |image_encoder| and
42 // |database|.
43 ImageManager(scoped_ptr<ImageFetcher> image_fetcher, 40 ImageManager(scoped_ptr<ImageFetcher> image_fetcher,
44 scoped_ptr<ImageEncoder> image_encoder,
45 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database, 41 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database,
46 const base::FilePath& database_dir); 42 const base::FilePath& database_dir);
47 virtual ~ImageManager(); 43 virtual ~ImageManager();
48 44
49 virtual void Initialize(const SuggestionsProfile& suggestions); 45 virtual void Initialize(const SuggestionsProfile& suggestions);
50 46
51 // Should be called from the UI thread. 47 // Should be called from the UI thread.
52 virtual void GetImageForURL( 48 virtual void GetImageForURL(
53 const GURL& url, 49 const GURL& url,
54 base::Callback<void(const GURL&, const SkBitmap*)> callback); 50 base::Callback<void(const GURL&, const SkBitmap*)> callback);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void OnDatabaseInit(bool success); 112 void OnDatabaseInit(bool success);
117 // Will transfer the loaded |entries| in memory (|image_map_|). 113 // Will transfer the loaded |entries| in memory (|image_map_|).
118 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries); 114 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries);
119 void OnDatabaseSave(bool success); 115 void OnDatabaseSave(bool success);
120 116
121 // Take entries from the database and put them in the local cache. 117 // Take entries from the database and put them in the local cache.
122 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries); 118 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries);
123 119
124 void ServePendingCacheRequests(); 120 void ServePendingCacheRequests();
125 121
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
126 // Map from URL to image URL. Should be kept up to date when a new 127 // Map from URL to image URL. Should be kept up to date when a new
127 // SuggestionsProfile is available. 128 // SuggestionsProfile is available.
128 std::map<GURL, GURL> image_url_map_; 129 std::map<GURL, GURL> image_url_map_;
129 130
130 // Map from website URL to request information, used for pending cache 131 // Map from website URL to request information, used for pending cache
131 // requests while the database hasn't loaded. 132 // requests while the database hasn't loaded.
132 ImageCacheRequestMap pending_cache_requests_; 133 ImageCacheRequestMap pending_cache_requests_;
133 134
134 // Holding the bitmaps in memory, keyed by website URL string. 135 // Holding the bitmaps in memory, keyed by website URL string.
135 ImageMap image_map_; 136 ImageMap image_map_;
136 137
137 scoped_ptr<ImageFetcher> image_fetcher_; 138 scoped_ptr<ImageFetcher> image_fetcher_;
138 139
139 scoped_ptr<ImageEncoder> image_encoder_;
140
141 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_; 140 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_;
142 141
143 bool database_ready_; 142 bool database_ready_;
144 143
145 base::WeakPtrFactory<ImageManager> weak_ptr_factory_; 144 base::WeakPtrFactory<ImageManager> weak_ptr_factory_;
146 145
147 base::ThreadChecker thread_checker_; 146 base::ThreadChecker thread_checker_;
148 147
149 DISALLOW_COPY_AND_ASSIGN(ImageManager); 148 DISALLOW_COPY_AND_ASSIGN(ImageManager);
150 }; 149 };
151 150
152 } // namespace suggestions 151 } // namespace suggestions
153 152
154 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ 153 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/suggestions/image_encoder.h ('k') | components/suggestions/image_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698