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

Side by Side Diff: chrome/browser/search/suggestions/image_fetcher_impl.cc

Issue 2047713002: [NTP Snippets] Cache images in a LevelDB (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@protodb_get
Patch Set: add TODOs Created 4 years, 6 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 "chrome/browser/search/suggestions/image_fetcher_impl.h" 5 #include "chrome/browser/search/suggestions/image_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 10 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 base::Bind(&ImageFetcherImpl::OnImageURLFetched, 56 base::Bind(&ImageFetcherImpl::OnImageURLFetched,
57 base::Unretained(this), image_url)); 57 base::Unretained(this), image_url));
58 } else { 58 } else {
59 // Request in progress. Register as an interested callback. 59 // Request in progress. Register as an interested callback.
60 it->second.callbacks.push_back(callback); 60 it->second.callbacks.push_back(callback);
61 } 61 }
62 } 62 }
63 63
64 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url, 64 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url,
65 const std::string& image_data) { 65 const std::string& image_data) {
66 // TODO(markusheintz): Add a method OnImageDataFetched on the delegate and 66 // Inform the ImageFetcherDelegate.
67 // call that here. 67 if (delegate_) {
68 auto it = pending_net_requests_.find(image_url);
69 DCHECK(it != pending_net_requests_.end());
70 delegate_->OnImageDataFetched(it->second.id, image_data);
71 }
72
68 image_decoder_->DecodeImage( 73 image_decoder_->DecodeImage(
69 image_data, 74 image_data,
70 base::Bind(&ImageFetcherImpl::OnImageDecoded, 75 base::Bind(&ImageFetcherImpl::OnImageDecoded,
71 base::Unretained(this), image_url)); 76 base::Unretained(this), image_url));
72 } 77 }
73 78
74 void ImageFetcherImpl::OnImageDecoded(const GURL& image_url, 79 void ImageFetcherImpl::OnImageDecoded(const GURL& image_url,
75 const gfx::Image& image) { 80 const gfx::Image& image) {
76 // Get request for the given image_url from the request queue. 81 // Get request for the given image_url from the request queue.
77 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url); 82 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url);
78 DCHECK(image_iter != pending_net_requests_.end()); 83 DCHECK(image_iter != pending_net_requests_.end());
79 ImageRequest* request = &image_iter->second; 84 ImageRequest* request = &image_iter->second;
80 85
81 // Run all callbacks 86 // Run all callbacks
82 for (const auto& callback : request->callbacks) { 87 for (const auto& callback : request->callbacks) {
83 callback.Run(request->id, image); 88 callback.Run(request->id, image);
84 } 89 }
85 90
86 // Inform the ImageFetcherDelegate. 91 // Inform the ImageFetcherDelegate.
87 if (delegate_) { 92 if (delegate_) {
88 delegate_->OnImageFetched(request->id, image); 93 delegate_->OnImageFetched(request->id, image);
89 } 94 }
90 95
91 // Erase the completed ImageRequest. 96 // Erase the completed ImageRequest.
92 pending_net_requests_.erase(image_iter); 97 pending_net_requests_.erase(image_iter);
93 } 98 }
94 99
95 } // namespace suggestions 100 } // namespace suggestions
OLDNEW
« no previous file with comments | « chrome/browser/ntp_snippets/ntp_snippets_service_factory.cc ('k') | components/image_fetcher/image_fetcher_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698