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

Side by Side Diff: chrome/browser/ui/views/frame/global_menu_bar_x11.cc

Issue 845013002: Remove TopSites notification in favor of Observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
OLDNEW
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"
20 #include "chrome/browser/history/top_sites.h" 19 #include "chrome/browser/history/top_sites.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_info_cache.h" 21 #include "chrome/browser/profiles/profile_info_cache.h"
23 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/sessions/tab_restore_service.h" 23 #include "chrome/browser/sessions/tab_restore_service.h"
25 #include "chrome/browser/sessions/tab_restore_service_factory.h" 24 #include "chrome/browser/sessions/tab_restore_service_factory.h"
26 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h" 26 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_list.h" 27 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 28 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
30 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_x11.h" 29 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_x11.h"
31 #include "chrome/browser/ui/views/frame/browser_view.h" 30 #include "chrome/browser/ui/views/frame/browser_view.h"
32 #include "chrome/browser/ui/views/frame/global_menu_bar_registrar_x11.h" 31 #include "chrome/browser/ui/views/frame/global_menu_bar_registrar_x11.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
35 #include "content/public/browser/notification_source.h"
36 #include "ui/base/accelerators/menu_label_accelerator_util_linux.h" 34 #include "ui/base/accelerators/menu_label_accelerator_util_linux.h"
37 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 36 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
39 #include "ui/gfx/text_elider.h" 37 #include "ui/gfx/text_elider.h"
40 38
41 // libdbusmenu-glib types 39 // libdbusmenu-glib types
42 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; 40 typedef struct _DbusmenuMenuitem DbusmenuMenuitem;
43 typedef DbusmenuMenuitem* (*dbusmenu_menuitem_new_func)(); 41 typedef DbusmenuMenuitem* (*dbusmenu_menuitem_new_func)();
44 typedef bool (*dbusmenu_menuitem_child_add_position_func)( 42 typedef bool (*dbusmenu_menuitem_child_add_position_func)(
45 DbusmenuMenuitem* parent, 43 DbusmenuMenuitem* parent,
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 : browser_(browser_view->browser()), 325 : browser_(browser_view->browser()),
328 profile_(browser_->profile()), 326 profile_(browser_->profile()),
329 browser_view_(browser_view), 327 browser_view_(browser_view),
330 host_(host), 328 host_(host),
331 server_(nullptr), 329 server_(nullptr),
332 root_item_(nullptr), 330 root_item_(nullptr),
333 history_menu_(nullptr), 331 history_menu_(nullptr),
334 profiles_menu_(nullptr), 332 profiles_menu_(nullptr),
335 top_sites_(nullptr), 333 top_sites_(nullptr),
336 tab_restore_service_(nullptr), 334 tab_restore_service_(nullptr),
335 scoped_observer_(this),
337 weak_ptr_factory_(this) { 336 weak_ptr_factory_(this) {
338 EnsureMethodsLoaded(); 337 EnsureMethodsLoaded();
339 338
340 if (server_new) 339 if (server_new)
341 host_->AddObserver(this); 340 host_->AddObserver(this);
342 } 341 }
343 342
344 GlobalMenuBarX11::~GlobalMenuBarX11() { 343 GlobalMenuBarX11::~GlobalMenuBarX11() {
345 if (server_) { 344 if (server_) {
346 Disable(); 345 Disable();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 pref_change_registrar_.Add( 422 pref_change_registrar_.Add(
424 bookmarks::prefs::kShowBookmarkBar, 423 bookmarks::prefs::kShowBookmarkBar,
425 base::Bind(&GlobalMenuBarX11::OnBookmarkBarVisibilityChanged, 424 base::Bind(&GlobalMenuBarX11::OnBookmarkBarVisibilityChanged,
426 base::Unretained(this))); 425 base::Unretained(this)));
427 OnBookmarkBarVisibilityChanged(); 426 OnBookmarkBarVisibilityChanged();
428 427
429 top_sites_ = profile_->GetTopSites(); 428 top_sites_ = profile_->GetTopSites();
430 if (top_sites_) { 429 if (top_sites_) {
431 GetTopSitesData(); 430 GetTopSitesData();
432 431
433 // Register for notification when TopSites changes so that we can update 432 // Register as TopSitesObserver so that we can update ourselves when the
434 // ourself. 433 // TopSites changes.
435 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, 434 scoped_observer_.Add(top_sites_);
436 content::Source<history::TopSites>(top_sites_));
437 } 435 }
438 436
439 ProfileManager* profile_manager = g_browser_process->profile_manager(); 437 ProfileManager* profile_manager = g_browser_process->profile_manager();
440 DCHECK(profile_manager); 438 DCHECK(profile_manager);
441 avatar_menu_.reset(new AvatarMenu( 439 avatar_menu_.reset(new AvatarMenu(
442 &profile_manager->GetProfileInfoCache(), this, nullptr)); 440 &profile_manager->GetProfileInfoCache(), this, nullptr));
443 avatar_menu_->RebuildMenu(); 441 avatar_menu_->RebuildMenu();
444 BrowserList::AddObserver(this); 442 BrowserList::AddObserver(this);
445 443
446 RebuildProfilesMenu(); 444 RebuildProfilesMenu();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 avatar_menu_->ActiveBrowserChanged(browser); 719 avatar_menu_->ActiveBrowserChanged(browser);
722 RebuildProfilesMenu(); 720 RebuildProfilesMenu();
723 } 721 }
724 722
725 void GlobalMenuBarX11::EnabledStateChangedForCommand(int id, bool enabled) { 723 void GlobalMenuBarX11::EnabledStateChangedForCommand(int id, bool enabled) {
726 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id); 724 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id);
727 if (it != id_to_menu_item_.end()) 725 if (it != id_to_menu_item_.end())
728 menuitem_property_set_bool(it->second, kPropertyEnabled, enabled); 726 menuitem_property_set_bool(it->second, kPropertyEnabled, enabled);
729 } 727 }
730 728
731 void GlobalMenuBarX11::Observe(int type, 729 void GlobalMenuBarX11::TopSitesLoaded(history::TopSites* top_sites) {
732 const content::NotificationSource& source, 730 }
733 const content::NotificationDetails& details) { 731
734 if (type == chrome::NOTIFICATION_TOP_SITES_CHANGED) { 732 void GlobalMenuBarX11::TopSitesChanged(history::TopSites* top_sites) {
735 GetTopSitesData(); 733 GetTopSitesData();
736 } else {
737 NOTREACHED();
738 }
739 } 734 }
740 735
741 void GlobalMenuBarX11::TabRestoreServiceChanged(TabRestoreService* service) { 736 void GlobalMenuBarX11::TabRestoreServiceChanged(TabRestoreService* service) {
742 const TabRestoreService::Entries& entries = service->entries(); 737 const TabRestoreService::Entries& entries = service->entries();
743 738
744 ClearMenuSection(history_menu_, TAG_RECENTLY_CLOSED); 739 ClearMenuSection(history_menu_, TAG_RECENTLY_CLOSED);
745 740
746 // We'll get the index the "Recently Closed" header. (This can vary depending 741 // We'll get the index the "Recently Closed" header. (This can vary depending
747 // on the number of "Most Visited" items. 742 // on the number of "Most Visited" items.
748 int index = GetIndexOfMenuItemWithTag(history_menu_, 743 int index = GetIndexOfMenuItemWithTag(history_menu_,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 void GlobalMenuBarX11::OnEditProfileItemActivated(DbusmenuMenuitem* sender, 887 void GlobalMenuBarX11::OnEditProfileItemActivated(DbusmenuMenuitem* sender,
893 unsigned int timestamp) { 888 unsigned int timestamp) {
894 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId)); 889 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId));
895 avatar_menu_->EditProfile(id); 890 avatar_menu_->EditProfile(id);
896 } 891 }
897 892
898 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender, 893 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender,
899 unsigned int timestamp) { 894 unsigned int timestamp) {
900 avatar_menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU); 895 avatar_menu_->AddNewProfile(ProfileMetrics::ADD_NEW_USER_MENU);
901 } 896 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/global_menu_bar_x11.h ('k') | chrome/browser/ui/webui/ntp/most_visited_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698