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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 1995493002: Change the ntp_snippet_service to use a gfx image instead of SkBitmap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/ntp_snippets/ntp_snippets_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ntp_snippets/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return std::find_if(haystack.begin(), haystack.end(), 142 return std::find_if(haystack.begin(), haystack.end(),
143 [&id](const std::unique_ptr<NTPSnippet>& snippet) { 143 [&id](const std::unique_ptr<NTPSnippet>& snippet) {
144 return snippet->id() == id; 144 return snippet->id() == id;
145 }) != haystack.end(); 145 }) != haystack.end();
146 } 146 }
147 147
148 void WrapImageFetchedCallback( 148 void WrapImageFetchedCallback(
149 const NTPSnippetsService::ImageFetchedCallback& callback, 149 const NTPSnippetsService::ImageFetchedCallback& callback,
150 const GURL& snippet_id_url, 150 const GURL& snippet_id_url,
151 const gfx::Image& image) { 151 const gfx::Image& image) {
152 const SkBitmap* bitmap = nullptr; 152 callback.Run(snippet_id_url.spec(), image);
153 if (!image.IsEmpty())
154 bitmap = image.ToSkBitmap();
155 callback.Run(snippet_id_url.spec(), bitmap);
156 } 153 }
157 154
158 } // namespace 155 } // namespace
159 156
160 NTPSnippetsService::NTPSnippetsService( 157 NTPSnippetsService::NTPSnippetsService(
161 PrefService* pref_service, 158 PrefService* pref_service,
162 SuggestionsService* suggestions_service, 159 SuggestionsService* suggestions_service,
163 scoped_refptr<base::SequencedTaskRunner> file_task_runner, 160 scoped_refptr<base::SequencedTaskRunner> file_task_runner,
164 const std::string& application_language_code, 161 const std::string& application_language_code,
165 NTPSnippetsScheduler* scheduler, 162 NTPSnippetsScheduler* scheduler,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 238
242 void NTPSnippetsService::FetchSnippetImage( 239 void NTPSnippetsService::FetchSnippetImage(
243 const std::string& snippet_id, 240 const std::string& snippet_id,
244 const ImageFetchedCallback& callback) { 241 const ImageFetchedCallback& callback) {
245 auto it = 242 auto it =
246 std::find_if(snippets_.begin(), snippets_.end(), 243 std::find_if(snippets_.begin(), snippets_.end(),
247 [&snippet_id](const std::unique_ptr<NTPSnippet>& snippet) { 244 [&snippet_id](const std::unique_ptr<NTPSnippet>& snippet) {
248 return snippet->id() == snippet_id; 245 return snippet->id() == snippet_id;
249 }); 246 });
250 if (it == snippets_.end()) { 247 if (it == snippets_.end()) {
251 callback.Run(snippet_id, nullptr); 248 gfx::Image empty_image;
249 callback.Run(snippet_id, empty_image);
252 return; 250 return;
253 } 251 }
254 252
255 const NTPSnippet& snippet = *it->get(); 253 const NTPSnippet& snippet = *it->get();
256 // TODO(treib): Make ImageFetcher take a string instead of a GURL as an 254 // TODO(treib): Make ImageFetcher take a string instead of a GURL as an
257 // identifier. 255 // identifier.
258 image_fetcher_->StartOrQueueNetworkRequest( 256 image_fetcher_->StartOrQueueNetworkRequest(
259 GURL(snippet.id()), snippet.salient_image_url(), 257 GURL(snippet.id()), snippet.salient_image_url(),
260 base::Bind(WrapImageFetchedCallback, callback)); 258 base::Bind(WrapImageFetchedCallback, callback));
261 // TODO(treib): Cache/persist the snippet image. 259 // TODO(treib): Cache/persist the snippet image.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (snippet->expiry_date() < next_expiry) 500 if (snippet->expiry_date() < next_expiry)
503 next_expiry = snippet->expiry_date(); 501 next_expiry = snippet->expiry_date();
504 } 502 }
505 DCHECK_GT(next_expiry, expiry); 503 DCHECK_GT(next_expiry, expiry);
506 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, 504 expiry_timer_.Start(FROM_HERE, next_expiry - expiry,
507 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished, 505 base::Bind(&NTPSnippetsService::LoadingSnippetsFinished,
508 base::Unretained(this))); 506 base::Unretained(this)));
509 } 507 }
510 508
511 } // namespace ntp_snippets 509 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698