| OLD | NEW |
| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" | 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return; | 246 return; |
| 247 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 247 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 248 entry->GetURL(), history::FAVICON, &load_consumer_, | 248 entry->GetURL(), history::FAVICON, &load_consumer_, |
| 249 base::Bind(&BackForwardMenuModel::OnFavIconDataAvailable, | 249 base::Bind(&BackForwardMenuModel::OnFavIconDataAvailable, |
| 250 base::Unretained(this))); | 250 base::Unretained(this))); |
| 251 load_consumer_.SetClientData(favicon_service, handle, entry->GetUniqueID()); | 251 load_consumer_.SetClientData(favicon_service, handle, entry->GetUniqueID()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void BackForwardMenuModel::OnFavIconDataAvailable( | 254 void BackForwardMenuModel::OnFavIconDataAvailable( |
| 255 FaviconService::Handle handle, | 255 FaviconService::Handle handle, |
| 256 history::FaviconData favicon) { | 256 history::FaviconData favicon_data, |
| 257 if (favicon.is_valid()) { | 257 std::vector<GURL> icon_urls_in_db) { |
| 258 if (favicon_data.has_valid_bitmaps()) { |
| 258 int unique_id = load_consumer_.GetClientDataForCurrentRequest(); | 259 int unique_id = load_consumer_.GetClientDataForCurrentRequest(); |
| 259 // Find the current model_index for the unique_id. | 260 // Find the current model_index for the unique_id. |
| 260 NavigationEntry* entry = NULL; | 261 NavigationEntry* entry = NULL; |
| 261 int model_index = -1; | 262 int model_index = -1; |
| 262 for (int i = 0; i < GetItemCount() - 1; i++) { | 263 for (int i = 0; i < GetItemCount() - 1; i++) { |
| 263 if (IsSeparator(i)) | 264 if (IsSeparator(i)) |
| 264 continue; | 265 continue; |
| 265 if (GetNavigationEntry(i)->GetUniqueID() == unique_id) { | 266 if (GetNavigationEntry(i)->GetUniqueID() == unique_id) { |
| 266 model_index = i; | 267 model_index = i; |
| 267 entry = GetNavigationEntry(i); | 268 entry = GetNavigationEntry(i); |
| 268 break; | 269 break; |
| 269 } | 270 } |
| 270 } | 271 } |
| 271 | 272 |
| 272 if (!entry) | 273 if (!entry) |
| 273 // The NavigationEntry wasn't found, this can happen if the user | 274 // The NavigationEntry wasn't found, this can happen if the user |
| 274 // navigates to another page and a NavigatationEntry falls out of the | 275 // navigates to another page and a NavigatationEntry falls out of the |
| 275 // range of kMaxHistoryItems. | 276 // range of kMaxHistoryItems. |
| 276 return; | 277 return; |
| 277 | 278 |
| 278 // Now that we have a valid NavigationEntry, decode the favicon and assign | 279 // Now that we have a valid NavigationEntry, decode the favicon and assign |
| 279 // it to the NavigationEntry. | 280 // it to the NavigationEntry. |
| 280 gfx::Image icon(favicon.image_data->front(), favicon.image_data->size()); | 281 scoped_refptr<base::RefCountedMemory> bitmap_data( |
| 282 favicon_data.first_bitmap()); |
| 283 gfx::Image icon(bitmap_data->front(), bitmap_data->size()); |
| 281 if (!icon.IsEmpty()) { | 284 if (!icon.IsEmpty()) { |
| 282 entry->GetFavicon().valid = true; | 285 entry->GetFavicon().valid = true; |
| 283 entry->GetFavicon().url = favicon.icon_url; | 286 entry->GetFavicon().url = favicon_data.icon_url; |
| 284 // TODO: Once the history service returns more representations, | 287 // TODO: Once the history service returns more representations, |
| 285 // use them all instead of having just the lodpi favicon. | 288 // use them all instead of having just the lodpi favicon. |
| 286 entry->GetFavicon().image = icon; | 289 entry->GetFavicon().image = icon; |
| 287 if (menu_model_delegate()) { | 290 if (menu_model_delegate()) { |
| 288 menu_model_delegate()->OnIconChanged(model_index); | 291 menu_model_delegate()->OnIconChanged(model_index); |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 } | 294 } |
| 292 } | 295 } |
| 293 | 296 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 metric_string += "ForwardMenu_"; | 469 metric_string += "ForwardMenu_"; |
| 467 else | 470 else |
| 468 metric_string += "BackMenu_"; | 471 metric_string += "BackMenu_"; |
| 469 metric_string += action; | 472 metric_string += action; |
| 470 if (index != -1) { | 473 if (index != -1) { |
| 471 // +1 is for historical reasons (indices used to start at 1). | 474 // +1 is for historical reasons (indices used to start at 1). |
| 472 metric_string += base::IntToString(index + 1); | 475 metric_string += base::IntToString(index + 1); |
| 473 } | 476 } |
| 474 return metric_string; | 477 return metric_string; |
| 475 } | 478 } |
| OLD | NEW |