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

Side by Side Diff: chrome/browser/ui/search_engines/template_url_table_model.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/search_engines/template_url_table_model.h" 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/favicon/favicon_service.h" 12 #include "chrome/browser/favicon/favicon_service.h"
13 #include "chrome/browser/favicon/favicon_service_factory.h" 13 #include "chrome/browser/favicon/favicon_service_factory.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "grit/ui_resources.h" 18 #include "grit/ui_resources.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/models/table_model_observer.h" 21 #include "ui/base/models/table_model_observer.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/favicon_size.h"
24 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 25
26 // Group IDs used by TemplateURLTableModel. 26 // Group IDs used by TemplateURLTableModel.
27 static const int kMainGroupID = 0; 27 static const int kMainGroupID = 0;
28 static const int kOtherGroupID = 1; 28 static const int kOtherGroupID = 1;
29 29
30 // ModelEntry ---------------------------------------------------- 30 // ModelEntry ----------------------------------------------------
31 31
32 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. 32 // ModelEntry wraps a TemplateURL as returned from the TemplateURL.
33 // ModelEntry also tracks state information about the URL. 33 // ModelEntry also tracks state information about the URL.
(...skipping 22 matching lines...) Expand all
56 LoadFavicon(); 56 LoadFavicon();
57 if (!favicon_.isNull()) 57 if (!favicon_.isNull())
58 return favicon_; 58 return favicon_;
59 return *default_icon; 59 return *default_icon;
60 } 60 }
61 61
62 // Resets internal status so that the next time the icon is asked for its 62 // Resets internal status so that the next time the icon is asked for its
63 // fetched again. This should be invoked if the url is modified. 63 // fetched again. This should be invoked if the url is modified.
64 void ResetIcon() { 64 void ResetIcon() {
65 load_state_ = NOT_LOADED; 65 load_state_ = NOT_LOADED;
66 favicon_ = SkBitmap(); 66 favicon_ = gfx::ImageSkia();
67 } 67 }
68 68
69 private: 69 private:
70 // State of the favicon. 70 // State of the favicon.
71 enum LoadState { 71 enum LoadState {
72 NOT_LOADED, 72 NOT_LOADED,
73 LOADING, 73 LOADING,
74 LOADED 74 LOADED
75 }; 75 };
76 76
77 void LoadFavicon() { 77 void LoadFavicon() {
78 load_state_ = LOADED; 78 load_state_ = LOADED;
79 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 79 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
80 model_->template_url_service()->profile(), Profile::EXPLICIT_ACCESS); 80 model_->template_url_service()->profile(), Profile::EXPLICIT_ACCESS);
81 if (!favicon_service) 81 if (!favicon_service)
82 return; 82 return;
83 GURL favicon_url = template_url()->favicon_url(); 83 GURL favicon_url = template_url()->favicon_url();
84 if (!favicon_url.is_valid()) { 84 if (!favicon_url.is_valid()) {
85 // The favicon url isn't always set. Guess at one here. 85 // The favicon url isn't always set. Guess at one here.
86 if (template_url_->url_ref().IsValid()) { 86 if (template_url_->url_ref().IsValid()) {
87 GURL url(template_url_->url()); 87 GURL url(template_url_->url());
88 if (url.is_valid()) 88 if (url.is_valid())
89 favicon_url = TemplateURL::GenerateFaviconURL(url); 89 favicon_url = TemplateURL::GenerateFaviconURL(url);
90 } 90 }
91 if (!favicon_url.is_valid()) 91 if (!favicon_url.is_valid())
92 return; 92 return;
93 } 93 }
94 load_state_ = LOADING; 94 load_state_ = LOADING;
95 favicon_service->GetFavicon(favicon_url, history::FAVICON, 95 favicon_service->GetFaviconImage(favicon_url, history::FAVICON,
96 &request_consumer_, 96 gfx::kFaviconSize, &request_consumer_,
97 base::Bind(&ModelEntry::OnFaviconDataAvailable, 97 base::Bind(&ModelEntry::OnFaviconDataAvailable,
98 base::Unretained(this))); 98 base::Unretained(this)));
99 } 99 }
100 100
101 void OnFaviconDataAvailable( 101 void OnFaviconDataAvailable(
102 FaviconService::Handle handle, 102 FaviconService::Handle handle,
103 history::FaviconData favicon) { 103 const history::FaviconImageResult& image_result) {
104 load_state_ = LOADED; 104 load_state_ = LOADED;
105 if (favicon.is_valid() && gfx::PNGCodec::Decode(favicon.image_data->front(), 105 if (!image_result.image.IsEmpty()) {
106 favicon.image_data->size(), 106 favicon_ = image_result.image.AsImageSkia();
107 &favicon_)) {
108 model_->FaviconAvailable(this); 107 model_->FaviconAvailable(this);
109 } 108 }
110 } 109 }
111 110
112 TemplateURL* template_url_; 111 TemplateURL* template_url_;
113 SkBitmap favicon_; 112 gfx::ImageSkia favicon_;
114 LoadState load_state_; 113 LoadState load_state_;
115 TemplateURLTableModel* model_; 114 TemplateURLTableModel* model_;
116 CancelableRequestConsumer request_consumer_; 115 CancelableRequestConsumer request_consumer_;
117 116
118 DISALLOW_COPY_AND_ASSIGN(ModelEntry); 117 DISALLOW_COPY_AND_ASSIGN(ModelEntry);
119 }; 118 };
120 119
121 // TemplateURLTableModel ----------------------------------------- 120 // TemplateURLTableModel -----------------------------------------
122 121
123 TemplateURLTableModel::TemplateURLTableModel( 122 TemplateURLTableModel::TemplateURLTableModel(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { 365 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) {
367 std::vector<ModelEntry*>::iterator i = 366 std::vector<ModelEntry*>::iterator i =
368 std::find(entries_.begin(), entries_.end(), entry); 367 std::find(entries_.begin(), entries_.end(), entry);
369 DCHECK(i != entries_.end()); 368 DCHECK(i != entries_.end());
370 NotifyChanged(static_cast<int>(i - entries_.begin())); 369 NotifyChanged(static_cast<int>(i - entries_.begin()));
371 } 370 }
372 371
373 void TemplateURLTableModel::OnTemplateURLServiceChanged() { 372 void TemplateURLTableModel::OnTemplateURLServiceChanged() {
374 Reload(); 373 Reload();
375 } 374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698