OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // The favicon url isn't always set. Guess at one here. | 84 // The favicon url isn't always set. Guess at one here. |
85 if (template_url_.url() && template_url_.url()->IsValid()) { | 85 if (template_url_.url() && template_url_.url()->IsValid()) { |
86 GURL url = GURL(template_url_.url()->url()); | 86 GURL url = GURL(template_url_.url()->url()); |
87 if (url.is_valid()) | 87 if (url.is_valid()) |
88 favicon_url = TemplateURL::GenerateFaviconURL(url); | 88 favicon_url = TemplateURL::GenerateFaviconURL(url); |
89 } | 89 } |
90 if (!favicon_url.is_valid()) | 90 if (!favicon_url.is_valid()) |
91 return; | 91 return; |
92 } | 92 } |
93 load_state_ = LOADING; | 93 load_state_ = LOADING; |
94 favicon_service->GetFavicon(favicon_url, | 94 favicon_service->GetFavicon(favicon_url, history::FAVICON, |
95 &request_consumer_, | 95 &request_consumer_, |
96 NewCallback(this, &ModelEntry::OnFaviconDataAvailable)); | 96 NewCallback(this, &ModelEntry::OnFaviconDataAvailable)); |
97 } | 97 } |
98 | 98 |
99 void OnFaviconDataAvailable( | 99 void OnFaviconDataAvailable( |
100 FaviconService::Handle handle, | 100 FaviconService::Handle handle, |
101 bool know_favicon, | 101 history::FaviconData favicon) { |
102 scoped_refptr<RefCountedMemory> data, | |
103 bool expired, | |
104 GURL icon_url) { | |
105 load_state_ = LOADED; | 102 load_state_ = LOADED; |
106 if (know_favicon && data.get() && | 103 if (favicon.is_valid() && gfx::PNGCodec::Decode(favicon.image_data->front(), |
107 gfx::PNGCodec::Decode(data->front(), data->size(), &favicon_)) { | 104 favicon.image_data->size(), |
| 105 &favicon_)) { |
108 model_->FaviconAvailable(this); | 106 model_->FaviconAvailable(this); |
109 } | 107 } |
110 } | 108 } |
111 | 109 |
112 const TemplateURL& template_url_; | 110 const TemplateURL& template_url_; |
113 SkBitmap favicon_; | 111 SkBitmap favicon_; |
114 LoadState load_state_; | 112 LoadState load_state_; |
115 TemplateURLTableModel* model_; | 113 TemplateURLTableModel* model_; |
116 CancelableRequestConsumer request_consumer_; | 114 CancelableRequestConsumer request_consumer_; |
117 | 115 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { | 370 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { |
373 std::vector<ModelEntry*>::iterator i = | 371 std::vector<ModelEntry*>::iterator i = |
374 find(entries_.begin(), entries_.end(), entry); | 372 find(entries_.begin(), entries_.end(), entry); |
375 DCHECK(i != entries_.end()); | 373 DCHECK(i != entries_.end()); |
376 NotifyChanged(static_cast<int>(i - entries_.begin())); | 374 NotifyChanged(static_cast<int>(i - entries_.begin())); |
377 } | 375 } |
378 | 376 |
379 void TemplateURLTableModel::OnTemplateURLModelChanged() { | 377 void TemplateURLTableModel::OnTemplateURLModelChanged() { |
380 Reload(); | 378 Reload(); |
381 } | 379 } |
OLD | NEW |