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 "chrome/browser/ui/cocoa/history_menu_bridge.h" | 5 #include "chrome/browser/ui/cocoa/history_menu_bridge.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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 449 |
450 // Tab navigations don't come with icons, so we always have to request them. | 450 // Tab navigations don't come with icons, so we always have to request them. |
451 GetFaviconForHistoryItem(item); | 451 GetFaviconForHistoryItem(item); |
452 | 452 |
453 return item; | 453 return item; |
454 } | 454 } |
455 | 455 |
456 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { | 456 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { |
457 FaviconService* service = | 457 FaviconService* service = |
458 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 458 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
459 base::CancelableTaskTracker::TaskId task_id = service->GetFaviconImageForURL( | 459 base::CancelableTaskTracker::TaskId task_id = |
460 FaviconService::FaviconForURLParams( | 460 service->GetFaviconImageForPageURL( |
461 item->url, favicon_base::FAVICON, gfx::kFaviconSize), | 461 FaviconService::FaviconForPageURLParams( |
462 base::Bind( | 462 item->url, favicon_base::FAVICON, gfx::kFaviconSize), |
463 &HistoryMenuBridge::GotFaviconData, base::Unretained(this), item), | 463 base::Bind( |
464 &cancelable_task_tracker_); | 464 &HistoryMenuBridge::GotFaviconData, base::Unretained(this), item), |
| 465 &cancelable_task_tracker_); |
465 item->icon_task_id = task_id; | 466 item->icon_task_id = task_id; |
466 item->icon_requested = true; | 467 item->icon_requested = true; |
467 } | 468 } |
468 | 469 |
469 void HistoryMenuBridge::GotFaviconData( | 470 void HistoryMenuBridge::GotFaviconData( |
470 HistoryItem* item, | 471 HistoryItem* item, |
471 const favicon_base::FaviconImageResult& image_result) { | 472 const favicon_base::FaviconImageResult& image_result) { |
472 // Since we're going to do Cocoa-y things, make sure this is the main thread. | 473 // Since we're going to do Cocoa-y things, make sure this is the main thread. |
473 DCHECK([NSThread isMainThread]); | 474 DCHECK([NSThread isMainThread]); |
474 | 475 |
475 DCHECK(item); | 476 DCHECK(item); |
476 item->icon_requested = false; | 477 item->icon_requested = false; |
477 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; | 478 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; |
478 | 479 |
479 NSImage* image = image_result.image.AsNSImage(); | 480 NSImage* image = image_result.image.AsNSImage(); |
480 if (image) { | 481 if (image) { |
481 item->icon.reset([image retain]); | 482 item->icon.reset([image retain]); |
482 [item->menu_item setImage:item->icon.get()]; | 483 [item->menu_item setImage:item->icon.get()]; |
483 } | 484 } |
484 } | 485 } |
485 | 486 |
486 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 487 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
487 DCHECK(item); | 488 DCHECK(item); |
488 if (item->icon_requested) { | 489 if (item->icon_requested) { |
489 cancelable_task_tracker_.TryCancel(item->icon_task_id); | 490 cancelable_task_tracker_.TryCancel(item->icon_task_id); |
490 item->icon_requested = false; | 491 item->icon_requested = false; |
491 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; | 492 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; |
492 } | 493 } |
493 } | 494 } |
OLD | NEW |