| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 // The number of visisted results to get. | 49 // The number of visisted results to get. |
| 50 const int kVisitedCount = 15; | 50 const int kVisitedCount = 15; |
| 51 | 51 |
| 52 // The number of recently closed items to get. | 52 // The number of recently closed items to get. |
| 53 const unsigned int kRecentlyClosedCount = 10; | 53 const unsigned int kRecentlyClosedCount = 10; |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 HistoryMenuBridge::HistoryItem::HistoryItem() | 57 HistoryMenuBridge::HistoryItem::HistoryItem() |
| 58 : icon_requested(false), | 58 : icon_requested(false), |
| 59 icon_task_id(CancelableTaskTracker::kBadTaskId), | 59 icon_task_id(base::CancelableTaskTracker::kBadTaskId), |
| 60 menu_item(nil), | 60 menu_item(nil), |
| 61 session_id(0) { | 61 session_id(0) {} |
| 62 } | |
| 63 | 62 |
| 64 HistoryMenuBridge::HistoryItem::HistoryItem(const HistoryItem& copy) | 63 HistoryMenuBridge::HistoryItem::HistoryItem(const HistoryItem& copy) |
| 65 : title(copy.title), | 64 : title(copy.title), |
| 66 url(copy.url), | 65 url(copy.url), |
| 67 icon_requested(false), | 66 icon_requested(false), |
| 68 icon_task_id(CancelableTaskTracker::kBadTaskId), | 67 icon_task_id(base::CancelableTaskTracker::kBadTaskId), |
| 69 menu_item(nil), | 68 menu_item(nil), |
| 70 session_id(copy.session_id) { | 69 session_id(copy.session_id) {} |
| 71 } | |
| 72 | 70 |
| 73 HistoryMenuBridge::HistoryItem::~HistoryItem() { | 71 HistoryMenuBridge::HistoryItem::~HistoryItem() { |
| 74 } | 72 } |
| 75 | 73 |
| 76 HistoryMenuBridge::HistoryMenuBridge(Profile* profile) | 74 HistoryMenuBridge::HistoryMenuBridge(Profile* profile) |
| 77 : controller_([[HistoryMenuCocoaController alloc] initWithBridge:this]), | 75 : controller_([[HistoryMenuCocoaController alloc] initWithBridge:this]), |
| 78 profile_(profile), | 76 profile_(profile), |
| 79 history_service_(NULL), | 77 history_service_(NULL), |
| 80 tab_restore_service_(NULL), | 78 tab_restore_service_(NULL), |
| 81 create_in_progress_(false), | 79 create_in_progress_(false), |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 449 |
| 452 // 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. |
| 453 GetFaviconForHistoryItem(item); | 451 GetFaviconForHistoryItem(item); |
| 454 | 452 |
| 455 return item; | 453 return item; |
| 456 } | 454 } |
| 457 | 455 |
| 458 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { | 456 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { |
| 459 FaviconService* service = | 457 FaviconService* service = |
| 460 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 458 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 461 CancelableTaskTracker::TaskId task_id = service->GetFaviconImageForURL( | 459 base::CancelableTaskTracker::TaskId task_id = service->GetFaviconImageForURL( |
| 462 FaviconService::FaviconForURLParams(item->url, | 460 FaviconService::FaviconForURLParams( |
| 463 chrome::FAVICON, | 461 item->url, chrome::FAVICON, gfx::kFaviconSize), |
| 464 gfx::kFaviconSize), | 462 base::Bind( |
| 465 base::Bind(&HistoryMenuBridge::GotFaviconData, | 463 &HistoryMenuBridge::GotFaviconData, base::Unretained(this), item), |
| 466 base::Unretained(this), | |
| 467 item), | |
| 468 &cancelable_task_tracker_); | 464 &cancelable_task_tracker_); |
| 469 item->icon_task_id = task_id; | 465 item->icon_task_id = task_id; |
| 470 item->icon_requested = true; | 466 item->icon_requested = true; |
| 471 } | 467 } |
| 472 | 468 |
| 473 void HistoryMenuBridge::GotFaviconData( | 469 void HistoryMenuBridge::GotFaviconData( |
| 474 HistoryItem* item, | 470 HistoryItem* item, |
| 475 const chrome::FaviconImageResult& image_result) { | 471 const chrome::FaviconImageResult& image_result) { |
| 476 // Since we're going to do Cocoa-y things, make sure this is the main thread. | 472 // Since we're going to do Cocoa-y things, make sure this is the main thread. |
| 477 DCHECK([NSThread isMainThread]); | 473 DCHECK([NSThread isMainThread]); |
| 478 | 474 |
| 479 DCHECK(item); | 475 DCHECK(item); |
| 480 item->icon_requested = false; | 476 item->icon_requested = false; |
| 481 item->icon_task_id = CancelableTaskTracker::kBadTaskId; | 477 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; |
| 482 | 478 |
| 483 NSImage* image = image_result.image.AsNSImage(); | 479 NSImage* image = image_result.image.AsNSImage(); |
| 484 if (image) { | 480 if (image) { |
| 485 item->icon.reset([image retain]); | 481 item->icon.reset([image retain]); |
| 486 [item->menu_item setImage:item->icon.get()]; | 482 [item->menu_item setImage:item->icon.get()]; |
| 487 } | 483 } |
| 488 } | 484 } |
| 489 | 485 |
| 490 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 486 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
| 491 DCHECK(item); | 487 DCHECK(item); |
| 492 if (item->icon_requested) { | 488 if (item->icon_requested) { |
| 493 cancelable_task_tracker_.TryCancel(item->icon_task_id); | 489 cancelable_task_tracker_.TryCancel(item->icon_task_id); |
| 494 item->icon_requested = false; | 490 item->icon_requested = false; |
| 495 item->icon_task_id = CancelableTaskTracker::kBadTaskId; | 491 item->icon_task_id = base::CancelableTaskTracker::kBadTaskId; |
| 496 } | 492 } |
| 497 } | 493 } |
| OLD | NEW |