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

Side by Side Diff: chrome/browser/notifications/sync_notifier/image_holder.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: another windows fix Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // This class holds the URL to an image and the bitmap for the fetched image,
6 // and has code to fetch the bitmap from the URL.
7
8 #include "chrome/browser/notifications/sync_notifier/image_holder.h"
9
10 // #include "ui/gfx/image/image_skia_rep.h"
dewittj 2014/03/25 22:31:14 nit: fix this include.
Pete Williamson 2014/03/26 18:12:55 Done.
11
12 namespace notifier {
13
14 ImageHolder::ImageHolder(const GURL& low_dpi_url,
15 const GURL& high_dpi_url,
16 Profile* profile,
17 ImageHolderDelegate* delegate)
18 : low_dpi_url_(low_dpi_url),
19 high_dpi_url_(high_dpi_url),
20 low_dpi_fetched_(false),
21 high_dpi_fetched_(false),
22 delegate_(delegate),
23 profile_(profile) {
24
25 // If a URL is invalid, clear it so we don't try to fetch it.
26 if (!low_dpi_url_.is_valid()) {
27 low_dpi_url_ = GURL();
28 }
29 if (!high_dpi_url_.is_valid()) {
30 high_dpi_url_ = GURL();
31 }
32
33 // Create a featcher for each URL that is set.
34 if (!low_dpi_url_.is_empty()) {
35 CreateBitmapFetcher(low_dpi_url_);
36 }
37 if (!high_dpi_url_.is_empty()) {
38 CreateBitmapFetcher(high_dpi_url_);
39 }
40 }
41
42 ImageHolder::~ImageHolder() {}
43
44 // This will let us know if we have tried to fetch once and the try completed.
45 // Currently there is no logic for retries.
46 bool ImageHolder::IsFetchingDone() const {
47 return ( (low_dpi_url_.is_empty() || low_dpi_fetched_) &&
dewittj 2014/03/25 22:31:14 nit: no whitespace between ( ( and ) )
Pete Williamson 2014/03/26 18:12:55 Done.
48 (high_dpi_url_.is_empty() || high_dpi_fetched_) );
49 }
50
51 // If this bitmap has a valid GURL, create a fetcher for it.
52 void ImageHolder::CreateBitmapFetcher(const GURL& url) {
53 // Check for dups, ignore any request for a dup.
54 ScopedVector<chrome::BitmapFetcher>::iterator iter;
55 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
56 if ((*iter)->url() == url)
57 return;
58 }
59
60 if (url.is_valid()) {
61 fetchers_.push_back(new chrome::BitmapFetcher(url, this));
62 DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url;
63 }
64 }
65
66 void ImageHolder::StartFetch() {
67 // Now that we have queued them all, start the fetching.
68 ScopedVector<chrome::BitmapFetcher>::iterator iter;
69 for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
70 (*iter)->Start(profile_);
71 }
72 }
73
74 // Method inherited from BitmapFetcher delegate.
75 void ImageHolder::OnFetchComplete(const GURL url,
76 const SkBitmap* bitmap) {
dewittj 2014/03/25 22:31:14 nit:no newline
Pete Williamson 2014/03/26 18:12:55 Done.
dewittj 2014/03/26 18:38:39 This is not done. No newline between url, and con
Pete Williamson 2014/03/26 21:03:50 Done.
77 // TODO(petewil): Should I retry if a fetch fails?
dewittj 2014/03/25 22:31:14 Please open a bug for this, maybe even mark launch
Pete Williamson 2014/03/26 18:12:55 crbug.com/256466
78
79 // Match the bitmap to the URL to put it into the image with the correct scale
80 // factor.
81 if (url == low_dpi_url_) {
82 low_dpi_fetched_ = true;
83 if (bitmap != NULL)
84 image_.AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0));
85 } else if (url == high_dpi_url_) {
86 high_dpi_fetched_ = true;
87 if (bitmap != NULL)
88 image_.AddRepresentation(gfx::ImageSkiaRep(*bitmap, 2.0));
89 } else {
90 DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url;
91 }
92
93 // Notify callback of bitmap arrival.
94 delegate_->OnFetchComplete();
95 }
96
97 } // namespace notifier.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698