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

Side by Side Diff: components/enhanced_bookmarks/bookmark_image_service.cc

Issue 899653003: [Enhanced Bookmark]Upstream image fetching code in android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 #include "components/enhanced_bookmarks/bookmark_image_service.h" 5 #include "components/enhanced_bookmarks/bookmark_image_service.h"
6 6
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 void BookmarkImageService::Shutdown() { 95 void BookmarkImageService::Shutdown() {
96 DCHECK(CalledOnValidThread()); 96 DCHECK(CalledOnValidThread());
97 enhanced_bookmark_model_->bookmark_model()->RemoveObserver(this); 97 enhanced_bookmark_model_->bookmark_model()->RemoveObserver(this);
98 enhanced_bookmark_model_ = NULL; 98 enhanced_bookmark_model_ = NULL;
99 } 99 }
100 100
101 void BookmarkImageService::SalientImageForUrl(const GURL& page_url, 101 void BookmarkImageService::SalientImageForUrl(const GURL& page_url,
102 ImageCallback callback) { 102 ImageCallback callback) {
103 DCHECK(CalledOnValidThread()); 103 DCHECK(CalledOnValidThread());
104 SalientImageForUrl(page_url, true, callback); 104 SalientImageFromWeb(page_url, callback);
105 } 105 }
106 106
107 void BookmarkImageService::RetrieveImageFromStore(const GURL& page_url, 107 void BookmarkImageService::RetrieveImageFromStore(const GURL& page_url,
108 ImageCallback callback) { 108 ImageCallback callback) {
109 DCHECK(CalledOnValidThread()); 109 DCHECK(CalledOnValidThread());
110 pool_->PostSequencedWorkerTaskWithShutdownBehavior( 110 pool_->PostSequencedWorkerTaskWithShutdownBehavior(
111 pool_->GetNamedSequenceToken(kSequenceToken), 111 pool_->GetNamedSequenceToken(kSequenceToken),
112 FROM_HERE, 112 FROM_HERE,
113 base::Bind(&RetrieveImageFromStoreRelay, 113 base::Bind(&RetrieveImageFromStoreRelay,
114 base::Unretained(store_.get()), 114 base::Unretained(store_.get()),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Either the record was in the store or there is no image in the store, but 153 // Either the record was in the store or there is no image in the store, but
154 // an URL for a record is present, indicating that a previous attempt to 154 // an URL for a record is present, indicating that a previous attempt to
155 // download the image failed. Just return the record. 155 // download the image failed. Just return the record.
156 original_callback.Run(record); 156 original_callback.Run(record);
157 } else { 157 } else {
158 // There is no record in the store, and no previous attempts to retrieve 158 // There is no record in the store, and no previous attempts to retrieve
159 // one. Start a request to retrieve a salient image if there is an image 159 // one. Start a request to retrieve a salient image if there is an image
160 // url set on a bookmark, and then enqueue the request for the record to 160 // url set on a bookmark, and then enqueue the request for the record to
161 // be triggered when the retrieval is finished. 161 // be triggered when the retrieval is finished.
162 RetrieveSalientImageForPageUrl(page_url); 162 RetrieveSalientImageForPageUrl(page_url);
163 SalientImageForUrl(page_url, false, original_callback); 163 SalientImageFromLocal(page_url, original_callback);
164 } 164 }
165 } 165 }
166 166
167 void BookmarkImageService::SalientImageForUrl(const GURL& page_url, 167 void BookmarkImageService::SalientImageFromLocal(const GURL& page_url,
168 bool fetch_from_bookmark, 168 ImageCallback callback) {
169 ImageCallback callback) {
170 DCHECK(CalledOnValidThread()); 169 DCHECK(CalledOnValidThread());
171
172 // If the request is done while the image is currently being retrieved, just 170 // If the request is done while the image is currently being retrieved, just
173 // store the appropriate callbacks to call once the image is retrieved. 171 // store the appropriate callbacks to call once the image is retrieved.
174 if (IsPageUrlInProgress(page_url)) { 172 if (IsPageUrlInProgress(page_url)) {
175 callbacks_[page_url].push_back(callback); 173 callbacks_[page_url].push_back(callback);
176 return; 174 return;
177 } 175 }
176 RetrieveImageFromStore(page_url, callback);
177 }
178 178
179 if (!fetch_from_bookmark) { 179 void BookmarkImageService::SalientImageFromWeb(const GURL& page_url,
180 RetrieveImageFromStore(page_url, callback); 180 ImageCallback callback) {
181 } else { 181 // If the request is done while the image is currently being retrieved, just
lpromero 2015/02/04 13:54:51 Add DCHECK called on valid thread.
Ian Wen 2015/02/05 18:33:17 Reverted the signature change.
182 RetrieveImageFromStore(page_url, 182 // store the appropriate callbacks to call once the image is retrieved.
183 base::Bind(&BookmarkImageService::FetchCallback, 183 if (IsPageUrlInProgress(page_url)) {
184 base::Unretained(this), 184 callbacks_[page_url].push_back(callback);
185 page_url, 185 return;
noyau (Ping after 24h) 2015/02/04 12:45:27 The refactoring leads to the duplication of this c
Ian Wen 2015/02/05 18:33:17 Reverted.
186 callback));
187 } 186 }
187 RetrieveImageFromStore(
188 page_url, base::Bind(&BookmarkImageService::FetchCallback,
189 base::Unretained(this), page_url, callback));
188 } 190 }
189 191
190 void BookmarkImageService::ProcessNewImage(const GURL& page_url, 192 void BookmarkImageService::ProcessNewImage(const GURL& page_url,
191 bool update_bookmarks, 193 bool update_bookmarks,
Kibeom Kim (inactive) 2015/02/05 01:19:24 Question to noyau@ or lpromero@: can we remove upd
noyau (Ping after 24h) 2015/02/05 08:49:59 This is not unnecessary. This decides if the image
Ian Wen 2015/02/05 18:33:17 update_bookmarks is useful to prefetch the image w
Kibeom Kim (inactive) 2015/02/05 18:51:34 I see I missed that part. On 2015/02/05 18:33:17
192 const gfx::Image& image, 194 const gfx::Image& image,
193 const GURL& image_url) { 195 const GURL& image_url) {
194 DCHECK(CalledOnValidThread()); 196 DCHECK(CalledOnValidThread());
195 PostTaskToStoreImage(image, image_url, page_url); 197 PostTaskToStoreImage(image, image_url, page_url);
196 if (update_bookmarks && image_url.is_valid()) { 198 if (update_bookmarks && image_url.is_valid()) {
197 const BookmarkNode* bookmark = 199 const BookmarkNode* bookmark =
198 enhanced_bookmark_model_->bookmark_model() 200 enhanced_bookmark_model_->bookmark_model()
199 ->GetMostRecentlyAddedUserNodeForURL(page_url); 201 ->GetMostRecentlyAddedUserNodeForURL(page_url);
200 if (bookmark) { 202 if (bookmark) {
201 const gfx::Size& size = image.Size(); 203 const gfx::Size& size = image.Size();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 const BookmarkNode* node) { 360 const BookmarkNode* node) {
359 } 361 }
360 362
361 void BookmarkImageService::BookmarkAllUserNodesRemoved( 363 void BookmarkImageService::BookmarkAllUserNodesRemoved(
362 BookmarkModel* model, 364 BookmarkModel* model,
363 const std::set<GURL>& removed_urls) { 365 const std::set<GURL>& removed_urls) {
364 ClearAll(); 366 ClearAll();
365 } 367 }
366 368
367 } // namespace enhanced_bookmarks 369 } // namespace enhanced_bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698