OLD | NEW |
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void OnDatabaseInit(bool success); | 112 void OnDatabaseInit(bool success); |
113 // Will transfer the loaded |entries| in memory (|image_map_|). | 113 // Will transfer the loaded |entries| in memory (|image_map_|). |
114 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries); | 114 void OnDatabaseLoad(bool success, scoped_ptr<ImageDataVector> entries); |
115 void OnDatabaseSave(bool success); | 115 void OnDatabaseSave(bool success); |
116 | 116 |
117 // 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. |
118 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries); | 118 void LoadEntriesInCache(scoped_ptr<ImageDataVector> entries); |
119 | 119 |
120 void ServePendingCacheRequests(); | 120 void ServePendingCacheRequests(); |
121 | 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 | |
127 // Map from URL to image URL. Should be kept up to date when a new | 122 // Map from URL to image URL. Should be kept up to date when a new |
128 // SuggestionsProfile is available. | 123 // SuggestionsProfile is available. |
129 std::map<GURL, GURL> image_url_map_; | 124 std::map<GURL, GURL> image_url_map_; |
130 | 125 |
131 // Map from website URL to request information, used for pending cache | 126 // Map from website URL to request information, used for pending cache |
132 // requests while the database hasn't loaded. | 127 // requests while the database hasn't loaded. |
133 ImageCacheRequestMap pending_cache_requests_; | 128 ImageCacheRequestMap pending_cache_requests_; |
134 | 129 |
135 // Holding the bitmaps in memory, keyed by website URL string. | 130 // Holding the bitmaps in memory, keyed by website URL string. |
136 ImageMap image_map_; | 131 ImageMap image_map_; |
137 | 132 |
138 scoped_ptr<ImageFetcher> image_fetcher_; | 133 scoped_ptr<ImageFetcher> image_fetcher_; |
139 | 134 |
140 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_; | 135 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> > database_; |
141 | 136 |
142 bool database_ready_; | 137 bool database_ready_; |
143 | 138 |
144 base::WeakPtrFactory<ImageManager> weak_ptr_factory_; | 139 base::WeakPtrFactory<ImageManager> weak_ptr_factory_; |
145 | 140 |
146 base::ThreadChecker thread_checker_; | 141 base::ThreadChecker thread_checker_; |
147 | 142 |
148 DISALLOW_COPY_AND_ASSIGN(ImageManager); | 143 DISALLOW_COPY_AND_ASSIGN(ImageManager); |
149 }; | 144 }; |
150 | 145 |
151 } // namespace suggestions | 146 } // namespace suggestions |
152 | 147 |
153 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ | 148 #endif // COMPONENTS_SUGGESTIONS_IMAGE_MANAGER_H_ |
OLD | NEW |