Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: chrome/browser/ui/cocoa/history_menu_bridge.mm

Issue 10873022: Revert 152904 - Moving FaviconService to a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU 13 #include "chrome/app/chrome_command_ids.h" // IDC_HISTORY_MENU
14 #import "chrome/browser/app_controller_mac.h" 14 #import "chrome/browser/app_controller_mac.h"
15 #include "chrome/browser/favicon/favicon_service_factory.h"
16 #include "chrome/browser/history/history_service_factory.h" 15 #include "chrome/browser/history/history_service_factory.h"
17 #include "chrome/browser/history/page_usage_data.h" 16 #include "chrome/browser/history/page_usage_data.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sessions/session_types.h" 18 #include "chrome/browser/sessions/session_types.h"
20 #include "chrome/browser/sessions/tab_restore_service_factory.h" 19 #include "chrome/browser/sessions/tab_restore_service_factory.h"
21 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" 20 #import "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
24 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 item->session_id = entry.id; 445 item->session_id = entry.id;
447 446
448 // Tab navigations don't come with icons, so we always have to request them. 447 // Tab navigations don't come with icons, so we always have to request them.
449 GetFaviconForHistoryItem(item); 448 GetFaviconForHistoryItem(item);
450 449
451 return item; 450 return item;
452 } 451 }
453 452
454 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) { 453 void HistoryMenuBridge::GetFaviconForHistoryItem(HistoryItem* item) {
455 FaviconService* service = 454 FaviconService* service =
456 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 455 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
457 FaviconService::Handle handle = service->GetFaviconForURL( 456 FaviconService::Handle handle = service->GetFaviconForURL(
458 profile_, item->url, history::FAVICON, &favicon_consumer_, 457 item->url, history::FAVICON, &favicon_consumer_,
459 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this))); 458 base::Bind(&HistoryMenuBridge::GotFaviconData, base::Unretained(this)));
460 favicon_consumer_.SetClientData(service, handle, item); 459 favicon_consumer_.SetClientData(service, handle, item);
461 item->icon_handle = handle; 460 item->icon_handle = handle;
462 item->icon_requested = true; 461 item->icon_requested = true;
463 } 462 }
464 463
465 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle, 464 void HistoryMenuBridge::GotFaviconData(FaviconService::Handle handle,
466 history::FaviconData favicon) { 465 history::FaviconData favicon) {
467 // Since we're going to do Cocoa-y things, make sure this is the main thread. 466 // Since we're going to do Cocoa-y things, make sure this is the main thread.
468 DCHECK([NSThread isMainThread]); 467 DCHECK([NSThread isMainThread]);
469 468
470 HistoryItem* item = 469 HistoryItem* item =
471 favicon_consumer_.GetClientData( 470 favicon_consumer_.GetClientData(
472 FaviconServiceFactory::GetForProfile( 471 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), handle);
473 profile_, Profile::EXPLICIT_ACCESS), handle);
474 DCHECK(item); 472 DCHECK(item);
475 item->icon_requested = false; 473 item->icon_requested = false;
476 item->icon_handle = 0; 474 item->icon_handle = 0;
477 475
478 // Convert the raw data to Skia and then to a NSImage. 476 // Convert the raw data to Skia and then to a NSImage.
479 // TODO(rsesek): Is there an easier way to do this? 477 // TODO(rsesek): Is there an easier way to do this?
480 SkBitmap icon; 478 SkBitmap icon;
481 if (favicon.is_valid() && 479 if (favicon.is_valid() &&
482 gfx::PNGCodec::Decode(favicon.image_data->front(), 480 gfx::PNGCodec::Decode(favicon.image_data->front(),
483 favicon.image_data->size(), &icon)) { 481 favicon.image_data->size(), &icon)) {
484 NSImage* image = gfx::SkBitmapToNSImage(icon); 482 NSImage* image = gfx::SkBitmapToNSImage(icon);
485 if (image) { 483 if (image) {
486 // The conversion was successful. 484 // The conversion was successful.
487 item->icon.reset([image retain]); 485 item->icon.reset([image retain]);
488 [item->menu_item setImage:item->icon.get()]; 486 [item->menu_item setImage:item->icon.get()];
489 } 487 }
490 } 488 }
491 } 489 }
492 490
493 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { 491 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) {
494 DCHECK(item); 492 DCHECK(item);
495 if (item->icon_requested) { 493 if (item->icon_requested) {
496 FaviconService* service = FaviconServiceFactory::GetForProfile( 494 FaviconService* service =
497 profile_, Profile::EXPLICIT_ACCESS); 495 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
498 service->CancelRequest(item->icon_handle); 496 service->CancelRequest(item->icon_handle);
499 item->icon_requested = false; 497 item->icon_requested = false;
500 item->icon_handle = 0; 498 item->icon_handle = 0;
501 } 499 }
502 } 500 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.cc ('k') | chrome/browser/ui/intents/web_intent_picker_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698