OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/frame/global_menu_bar_x11.h" | 5 #include "chrome/browser/ui/views/frame/global_menu_bar_x11.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <glib-object.h> | 8 #include <glib-object.h> |
9 | 9 |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
| 21 #include "chrome/browser/history/top_sites_factory.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/sessions/tab_restore_service.h" | 25 #include "chrome/browser/sessions/tab_restore_service.h" |
25 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 26 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_commands.h" | 28 #include "chrome/browser/ui/browser_commands.h" |
28 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
29 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" | 30 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
30 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_x11.h" | 31 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_x11.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 chrome::AddCommandObserver(browser_, it->first, this); | 420 chrome::AddCommandObserver(browser_, it->first, this); |
420 } | 421 } |
421 | 422 |
422 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); | 423 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); |
423 pref_change_registrar_.Add( | 424 pref_change_registrar_.Add( |
424 bookmarks::prefs::kShowBookmarkBar, | 425 bookmarks::prefs::kShowBookmarkBar, |
425 base::Bind(&GlobalMenuBarX11::OnBookmarkBarVisibilityChanged, | 426 base::Bind(&GlobalMenuBarX11::OnBookmarkBarVisibilityChanged, |
426 base::Unretained(this))); | 427 base::Unretained(this))); |
427 OnBookmarkBarVisibilityChanged(); | 428 OnBookmarkBarVisibilityChanged(); |
428 | 429 |
429 top_sites_ = profile_->GetTopSites(); | 430 top_sites_ = TopSitesFactory::GetForProfile(profile_); |
430 if (top_sites_) { | 431 if (top_sites_.get()) { |
431 GetTopSitesData(); | 432 GetTopSitesData(); |
432 | 433 |
433 // Register for notification when TopSites changes so that we can update | 434 // Register for notification when TopSites changes so that we can update |
434 // ourself. | 435 // ourself. |
435 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, | 436 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, |
436 content::Source<history::TopSites>(top_sites_)); | 437 content::Source<history::TopSites>(top_sites_.get())); |
437 } | 438 } |
438 | 439 |
439 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 440 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
440 DCHECK(profile_manager); | 441 DCHECK(profile_manager); |
441 avatar_menu_.reset(new AvatarMenu( | 442 avatar_menu_.reset(new AvatarMenu( |
442 &profile_manager->GetProfileInfoCache(), this, nullptr)); | 443 &profile_manager->GetProfileInfoCache(), this, nullptr)); |
443 avatar_menu_->RebuildMenu(); | 444 avatar_menu_->RebuildMenu(); |
444 BrowserList::AddObserver(this); | 445 BrowserList::AddObserver(this); |
445 | 446 |
446 RebuildProfilesMenu(); | 447 RebuildProfilesMenu(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 g_signal_connect(menu_item, "item-activated", | 561 g_signal_connect(menu_item, "item-activated", |
561 G_CALLBACK(OnHistoryItemActivatedThunk), this); | 562 G_CALLBACK(OnHistoryItemActivatedThunk), this); |
562 | 563 |
563 g_object_set_data_full(G_OBJECT(menu_item), kHistoryItem, item, | 564 g_object_set_data_full(G_OBJECT(menu_item), kHistoryItem, item, |
564 DeleteHistoryItem); | 565 DeleteHistoryItem); |
565 menuitem_child_add_position(menu, menu_item, index); | 566 menuitem_child_add_position(menu, menu_item, index); |
566 g_object_unref(menu_item); | 567 g_object_unref(menu_item); |
567 } | 568 } |
568 | 569 |
569 void GlobalMenuBarX11::GetTopSitesData() { | 570 void GlobalMenuBarX11::GetTopSitesData() { |
570 DCHECK(top_sites_); | 571 DCHECK(top_sites_.get()); |
571 | 572 |
572 top_sites_->GetMostVisitedURLs( | 573 top_sites_->GetMostVisitedURLs( |
573 base::Bind(&GlobalMenuBarX11::OnTopSitesReceived, | 574 base::Bind(&GlobalMenuBarX11::OnTopSitesReceived, |
574 weak_ptr_factory_.GetWeakPtr()), false); | 575 weak_ptr_factory_.GetWeakPtr()), false); |
575 } | 576 } |
576 | 577 |
577 void GlobalMenuBarX11::OnTopSitesReceived( | 578 void GlobalMenuBarX11::OnTopSitesReceived( |
578 const history::MostVisitedURLList& visited_list) { | 579 const history::MostVisitedURLList& visited_list) { |
579 ClearMenuSection(history_menu_, TAG_MOST_VISITED); | 580 ClearMenuSection(history_menu_, TAG_MOST_VISITED); |
580 | 581 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 void GlobalMenuBarX11::OnEditProfileItemActivated(DbusmenuMenuitem* sender, | 893 void GlobalMenuBarX11::OnEditProfileItemActivated(DbusmenuMenuitem* sender, |
893 unsigned int timestamp) { | 894 unsigned int timestamp) { |
894 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId)); | 895 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId)); |
895 avatar_menu_->EditProfile(id); | 896 avatar_menu_->EditProfile(id); |
896 } | 897 } |
897 | 898 |
898 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender, | 899 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender, |
899 unsigned int timestamp) { | 900 unsigned int timestamp) { |
900 avatar_menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU); | 901 avatar_menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU); |
901 } | 902 } |
OLD | NEW |