Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/possible_url_model.h" | 5 #include "chrome/browser/possible_url_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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if (i != fav_icon_map_.end()) { | 156 if (i != fav_icon_map_.end()) { |
| 157 // We already requested the favicon, return it. | 157 // We already requested the favicon, return it. |
| 158 if (!i->second.isNull()) | 158 if (!i->second.isNull()) |
| 159 return i->second; | 159 return i->second; |
| 160 } else if (profile_) { | 160 } else if (profile_) { |
| 161 FaviconService* favicon_service = | 161 FaviconService* favicon_service = |
| 162 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 162 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 163 if (favicon_service) { | 163 if (favicon_service) { |
| 164 CancelableRequestProvider::Handle h = | 164 CancelableRequestProvider::Handle h = |
| 165 favicon_service->GetFaviconForURL( | 165 favicon_service->GetFaviconForURL( |
| 166 result.url, &consumer_, | 166 result.url, |
| 167 history::FAV_ICON, | |
| 168 &consumer_, | |
| 167 NewCallback(this, &PossibleURLModel::OnFavIconAvailable)); | 169 NewCallback(this, &PossibleURLModel::OnFavIconAvailable)); |
| 168 consumer_.SetClientData(favicon_service, h, result.index); | 170 consumer_.SetClientData(favicon_service, h, result.index); |
| 169 // Add an entry to the map so that we don't attempt to request the | 171 // Add an entry to the map so that we don't attempt to request the |
| 170 // favicon again. | 172 // favicon again. |
| 171 fav_icon_map_[result.index] = SkBitmap(); | 173 fav_icon_map_[result.index] = SkBitmap(); |
| 172 } | 174 } |
| 173 } | 175 } |
| 174 return *default_fav_icon; | 176 return *default_fav_icon; |
| 175 } | 177 } |
| 176 | 178 |
| 177 int PossibleURLModel::CompareValues(int row1, int row2, int column_id) { | 179 int PossibleURLModel::CompareValues(int row1, int row2, int column_id) { |
| 178 if (column_id == IDS_ASI_URL_COLUMN) { | 180 if (column_id == IDS_ASI_URL_COLUMN) { |
| 179 return results_[row1].display_url.Compare( | 181 return results_[row1].display_url.Compare( |
| 180 results_[row2].display_url, GetCollator()); | 182 results_[row2].display_url, GetCollator()); |
| 181 } | 183 } |
| 182 return ui::TableModel::CompareValues(row1, row2, column_id); | 184 return ui::TableModel::CompareValues(row1, row2, column_id); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void PossibleURLModel::OnFavIconAvailable( | 187 void PossibleURLModel::OnFavIconAvailable( |
| 186 FaviconService::Handle h, | 188 FaviconService::Handle h, |
| 187 bool fav_icon_available, | 189 bool fav_icon_available, |
| 188 scoped_refptr<RefCountedMemory> data, | 190 scoped_refptr<RefCountedMemory> data, |
| 189 bool expired, | 191 bool expired, |
| 190 GURL icon_url) { | 192 GURL icon_url, |
| 193 history::IconType) { | |
|
sky
2011/03/09 21:41:08
include name
michaelbai
2011/03/09 23:11:45
Done.
| |
| 191 if (profile_) { | 194 if (profile_) { |
| 192 FaviconService* favicon_service = | 195 FaviconService* favicon_service = |
| 193 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 196 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 194 size_t index = consumer_.GetClientData(favicon_service, h); | 197 size_t index = consumer_.GetClientData(favicon_service, h); |
| 195 if (fav_icon_available) { | 198 if (fav_icon_available) { |
| 196 // The decoder will leave our bitmap empty on error. | 199 // The decoder will leave our bitmap empty on error. |
| 197 gfx::PNGCodec::Decode(data->front(), data->size(), | 200 gfx::PNGCodec::Decode(data->front(), data->size(), |
| 198 &(fav_icon_map_[index])); | 201 &(fav_icon_map_[index])); |
| 199 | 202 |
| 200 // Notify the observer. | 203 // Notify the observer. |
| 201 if (!fav_icon_map_[index].isNull() && observer_) | 204 if (!fav_icon_map_[index].isNull() && observer_) |
| 202 observer_->OnItemsChanged(static_cast<int>(index), 1); | 205 observer_->OnItemsChanged(static_cast<int>(index), 1); |
| 203 } | 206 } |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 207 void PossibleURLModel::SetObserver(ui::TableModelObserver* observer) { | 210 void PossibleURLModel::SetObserver(ui::TableModelObserver* observer) { |
| 208 observer_ = observer; | 211 observer_ = observer; |
| 209 } | 212 } |
| OLD | NEW |