Commit 78240e99 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

Renamed the DBus appmenu classes appropriately.

This is a follow-up to [1] that fixes one compilation issue and also
renames the classes and files so they would match the purpose better.

No changes to functionality are intended.

[1] https://crrev.com/c/2289772

Bug: 990756
Change-Id: Ifffe052bff2d6bfcad81ce5fe38e6e5ad37dcb8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317185
Auto-Submit: Alexander Dunaev <adunaev@igalia.com>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791382}
parent 736f5348
......@@ -3072,10 +3072,10 @@ static_library("ui") {
if (use_dbus && (use_x11 || ozone_platform_x11)) {
sources += [
"views/frame/global_menu_bar_registrar_x11.cc",
"views/frame/global_menu_bar_registrar_x11.h",
"views/frame/global_menu_bar_x11.cc",
"views/frame/global_menu_bar_x11.h",
"views/frame/dbus_appmenu.cc",
"views/frame/dbus_appmenu.h",
"views/frame/dbus_appmenu_registrar.cc",
"views/frame/dbus_appmenu_registrar.h",
]
defines += [ "USE_DBUS_MENU" ]
deps += [ "//ui/gfx/x" ]
......
......@@ -6,7 +6,7 @@ specific_include_rules = {
"browser_frame_ash\.*": [
"+ash",
],
"global_menu_bar_.*x11\.*": [
"dbus_appmenu\.*": [
"+dbus",
],
"top_controls_slide_controller_chromeos_browsertest.cc": [
......
......@@ -17,6 +17,8 @@
#include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/extensions/x11_extension.h"
#if defined(USE_DBUS_MENU)
namespace {
#if defined(USE_DBUS_MENU)
......@@ -33,6 +35,8 @@ bool CreateGlobalMenuBar() {
} // namespace
#endif // defined(USE_DBUS_MENU)
////////////////////////////////////////////////////////////////////////////////
// BrowserDesktopWindowTreeHostLinux, public:
......@@ -96,17 +100,16 @@ void BrowserDesktopWindowTreeHostLinux::Init(
#if defined(USE_DBUS_MENU)
// We have now created our backing X11 window. We now need to (possibly)
// alert the desktop environment that there's a menu bar attached to it.
if (CreateGlobalMenuBar()) {
global_menu_bar_x11_ = std::make_unique<GlobalMenuBarX11>(
browser_view_, GetAcceleratedWidget());
dbus_appmenu_ =
std::make_unique<DbusAppmenu>(browser_view_, GetAcceleratedWidget());
}
#endif
}
void BrowserDesktopWindowTreeHostLinux::CloseNow() {
#if defined(USE_DBUS_MENU)
global_menu_bar_x11_.reset();
dbus_appmenu_.reset();
#endif
DesktopWindowTreeHostLinuxImpl::CloseNow();
}
......
......@@ -9,7 +9,7 @@
#include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host.h"
#if defined(USE_DBUS_MENU)
#include "chrome/browser/ui/views/frame/global_menu_bar_x11.h" // nogncheck
#include "chrome/browser/ui/views/frame/dbus_appmenu.h" // nogncheck
#endif
#if defined(USE_X11)
......@@ -70,7 +70,7 @@ class BrowserDesktopWindowTreeHostLinux
// Each browser frame maintains its own menu bar object because the lower
// level dbus protocol associates a xid to a menu bar; we can't map multiple
// xids to the same menu bar.
std::unique_ptr<GlobalMenuBarX11> global_menu_bar_x11_;
std::unique_ptr<DbusAppmenu> dbus_appmenu_;
#endif
DISALLOW_COPY_AND_ASSIGN(BrowserDesktopWindowTreeHostLinux);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/global_menu_bar_x11.h"
#include "chrome/browser/ui/views/frame/dbus_appmenu.h"
#include <dlfcn.h>
#include <glib-object.h>
......@@ -34,7 +34,7 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_live_tab_context.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/global_menu_bar_registrar_x11.h"
#include "chrome/browser/ui/views/frame/dbus_appmenu_registrar.h"
#include "chrome/grit/generated_resources.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/history/core/browser/top_sites.h"
......@@ -50,7 +50,7 @@
#include "ui/gfx/text_elider.h"
// A line in the static menu definitions.
struct GlobalMenuBarCommand {
struct DbusAppmenuCommand {
int command;
int str_id;
};
......@@ -80,7 +80,7 @@ enum ReservedCommandId {
kFirstUnreservedCommandId
};
constexpr GlobalMenuBarCommand kFileMenu[] = {
constexpr DbusAppmenuCommand kFileMenu[] = {
{IDC_NEW_TAB, IDS_NEW_TAB},
{IDC_NEW_WINDOW, IDS_NEW_WINDOW},
{IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW},
......@@ -95,16 +95,16 @@ constexpr GlobalMenuBarCommand kFileMenu[] = {
{IDC_PRINT, IDS_PRINT},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kEditMenu[] = {{IDC_CUT, IDS_CUT},
{IDC_COPY, IDS_COPY},
{IDC_PASTE, IDS_PASTE},
{kSeparator},
{IDC_FIND, IDS_FIND},
{kSeparator},
{IDC_OPTIONS, IDS_PREFERENCES},
{kMenuEnd}};
constexpr DbusAppmenuCommand kEditMenu[] = {{IDC_CUT, IDS_CUT},
{IDC_COPY, IDS_COPY},
{IDC_PASTE, IDS_PASTE},
{kSeparator},
{IDC_FIND, IDS_FIND},
{kSeparator},
{IDC_OPTIONS, IDS_PREFERENCES},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kViewMenu[] = {
constexpr DbusAppmenuCommand kViewMenu[] = {
{IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR},
{kSeparator},
{IDC_STOP, IDS_STOP_MENU_LINUX},
......@@ -116,7 +116,7 @@ constexpr GlobalMenuBarCommand kViewMenu[] = {
{IDC_ZOOM_MINUS, IDS_TEXT_SMALLER_LINUX},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kHistoryMenu[] = {
constexpr DbusAppmenuCommand kHistoryMenu[] = {
{IDC_HOME, IDS_HISTORY_HOME_LINUX},
{IDC_BACK, IDS_HISTORY_BACK_LINUX},
{IDC_FORWARD, IDS_HISTORY_FORWARD_LINUX},
......@@ -128,7 +128,7 @@ constexpr GlobalMenuBarCommand kHistoryMenu[] = {
{IDC_SHOW_HISTORY, IDS_HISTORY_SHOWFULLHISTORY_LINK},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kToolsMenu[] = {
constexpr DbusAppmenuCommand kToolsMenu[] = {
{IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS},
{IDC_SHOW_HISTORY, IDS_HISTORY_SHOW_HISTORY},
{IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS},
......@@ -143,13 +143,13 @@ constexpr GlobalMenuBarCommand kToolsMenu[] = {
{IDC_DEV_TOOLS_DEVICES, IDS_DEV_TOOLS_DEVICES},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kProfilesMenu[] = {
constexpr DbusAppmenuCommand kProfilesMenu[] = {
{kSeparator},
{kTagProfileEdit, IDS_PROFILES_MANAGE_BUTTON_LABEL},
{kTagProfileCreate, IDS_PROFILES_CREATE_BUTTON_LABEL},
{kMenuEnd}};
constexpr GlobalMenuBarCommand kHelpMenu[] = {
constexpr DbusAppmenuCommand kHelpMenu[] = {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
{IDC_FEEDBACK, IDS_FEEDBACK},
#endif
......@@ -180,7 +180,7 @@ std::vector<std::pair<ui::MenuModel*, int>> FindMenuItemsForCommand(
} // namespace
struct GlobalMenuBarX11::HistoryItem {
struct DbusAppmenu::HistoryItem {
HistoryItem() : session_id(SessionID::InvalidValue()) {}
// The title for the menu item.
......@@ -196,7 +196,7 @@ struct GlobalMenuBarX11::HistoryItem {
SessionID session_id;
// If the HistoryItem is a window, this will be the vector of tabs. Note
// that this is a list of weak references. GlobalMenuBarX11::history_items_
// that this is a list of weak references. DbusAppmenu::history_items_
// is the owner of all items. If it is not a window, then the entry is a
// single page and the vector will be empty.
std::vector<HistoryItem*> tabs;
......@@ -205,19 +205,18 @@ struct GlobalMenuBarX11::HistoryItem {
DISALLOW_COPY_AND_ASSIGN(HistoryItem);
};
GlobalMenuBarX11::GlobalMenuBarX11(BrowserView* browser_view,
uint32_t browser_frame_xid)
DbusAppmenu::DbusAppmenu(BrowserView* browser_view, uint32_t browser_frame_id)
: browser_(browser_view->browser()),
profile_(browser_->profile()),
browser_view_(browser_view),
browser_frame_xid_(browser_frame_xid),
browser_frame_id_(browser_frame_id),
tab_restore_service_(nullptr),
last_command_id_(kFirstUnreservedCommandId - 1) {
GlobalMenuBarRegistrarX11::GetInstance()->OnMenuBarCreated(this);
DbusAppmenuRegistrar::GetInstance()->OnMenuBarCreated(this);
}
GlobalMenuBarX11::~GlobalMenuBarX11() {
auto* registrar = GlobalMenuBarRegistrarX11::GetInstance();
DbusAppmenu::~DbusAppmenu() {
auto* registrar = DbusAppmenuRegistrar::GetInstance();
registrar->OnMenuBarDestroyed(this);
if (!initialized_)
......@@ -236,7 +235,7 @@ GlobalMenuBarX11::~GlobalMenuBarX11() {
BrowserList::RemoveObserver(this);
}
void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) {
void DbusAppmenu::Initialize(DbusMenu::InitializedCallback callback) {
DCHECK(!initialized_);
initialized_ = true;
......@@ -255,7 +254,7 @@ void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) {
pref_change_registrar_.Init(browser_->profile()->GetPrefs());
pref_change_registrar_.Add(
bookmarks::prefs::kShowBookmarkBar,
base::Bind(&GlobalMenuBarX11::OnBookmarkBarVisibilityChanged,
base::Bind(&DbusAppmenu::OnBookmarkBarVisibilityChanged,
base::Unretained(this)));
top_sites_ = TopSitesFactory::GetForProfile(profile_);
......@@ -278,19 +277,19 @@ void GlobalMenuBarX11::Initialize(DbusMenu::InitializedCallback callback) {
RebuildProfilesMenu();
menu_service_ = std::make_unique<DbusMenu>(
GlobalMenuBarRegistrarX11::GetInstance()->bus()->GetExportedObject(
DbusAppmenuRegistrar::GetInstance()->bus()->GetExportedObject(
dbus::ObjectPath(GetPath())),
std::move(callback));
menu_service_->SetModel(root_menu_.get(), false);
}
std::string GlobalMenuBarX11::GetPath() const {
return base::StringPrintf("/com/canonical/menu/%X", browser_frame_xid_);
std::string DbusAppmenu::GetPath() const {
return base::StringPrintf("/com/canonical/menu/%X", browser_frame_id_);
}
ui::SimpleMenuModel* GlobalMenuBarX11::BuildStaticMenu(
ui::SimpleMenuModel* DbusAppmenu::BuildStaticMenu(
int string_id,
const GlobalMenuBarCommand* commands) {
const DbusAppmenuCommand* commands) {
toplevel_menus_.push_back(std::make_unique<ui::SimpleMenuModel>(this));
ui::SimpleMenuModel* menu = toplevel_menus_.back().get();
for (; commands->command != kMenuEnd; commands++) {
......@@ -320,8 +319,7 @@ ui::SimpleMenuModel* GlobalMenuBarX11::BuildStaticMenu(
return menu;
}
std::unique_ptr<GlobalMenuBarX11::HistoryItem>
GlobalMenuBarX11::HistoryItemForTab(
std::unique_ptr<DbusAppmenu::HistoryItem> DbusAppmenu::HistoryItemForTab(
const sessions::TabRestoreService::Tab& entry) {
const sessions::SerializedNavigationEntry& current_navigation =
entry.navigations.at(entry.current_navigation_index);
......@@ -332,9 +330,9 @@ GlobalMenuBarX11::HistoryItemForTab(
return item;
}
void GlobalMenuBarX11::AddHistoryItemToMenu(std::unique_ptr<HistoryItem> item,
ui::SimpleMenuModel* menu,
int index) {
void DbusAppmenu::AddHistoryItemToMenu(std::unique_ptr<HistoryItem> item,
ui::SimpleMenuModel* menu,
int index) {
base::string16 title = item->title;
std::string url_string = item->url.possibly_invalid_spec();
......@@ -347,14 +345,14 @@ void GlobalMenuBarX11::AddHistoryItemToMenu(std::unique_ptr<HistoryItem> item,
history_items_[command_id] = std::move(item);
}
void GlobalMenuBarX11::GetTopSitesData() {
void DbusAppmenu::GetTopSitesData() {
DCHECK(top_sites_);
top_sites_->GetMostVisitedURLs(base::BindOnce(
&GlobalMenuBarX11::OnTopSitesReceived, weak_ptr_factory_.GetWeakPtr()));
&DbusAppmenu::OnTopSitesReceived, weak_ptr_factory_.GetWeakPtr()));
}
void GlobalMenuBarX11::OnTopSitesReceived(
void DbusAppmenu::OnTopSitesReceived(
const history::MostVisitedURLList& visited_list) {
int index = ClearHistoryMenuSection(kTagMostVisited);
......@@ -374,12 +372,12 @@ void GlobalMenuBarX11::OnTopSitesReceived(
menu_service_->MenuLayoutUpdated(history_menu_);
}
void GlobalMenuBarX11::OnBookmarkBarVisibilityChanged() {
void DbusAppmenu::OnBookmarkBarVisibilityChanged() {
menu_service_->MenuItemsPropertiesUpdated(
FindMenuItemsForCommand(root_menu_.get(), IDC_SHOW_BOOKMARK_BAR));
}
void GlobalMenuBarX11::RebuildProfilesMenu() {
void DbusAppmenu::RebuildProfilesMenu() {
while (profiles_menu_->GetTypeAt(0) != ui::MenuModel::TYPE_SEPARATOR)
profiles_menu_->RemoveItemAt(0);
profile_commands_.clear();
......@@ -405,7 +403,7 @@ void GlobalMenuBarX11::RebuildProfilesMenu() {
menu_service_->MenuLayoutUpdated(profiles_menu_);
}
int GlobalMenuBarX11::ClearHistoryMenuSection(int header_command_id) {
int DbusAppmenu::ClearHistoryMenuSection(int header_command_id) {
int index = 0;
while (history_menu_->GetCommandIdAt(index++) != header_command_id) {
}
......@@ -416,7 +414,7 @@ int GlobalMenuBarX11::ClearHistoryMenuSection(int header_command_id) {
return index;
}
void GlobalMenuBarX11::RegisterCommandObserver(int command) {
void DbusAppmenu::RegisterCommandObserver(int command) {
if (command > kLastChromeCommand)
return;
......@@ -429,7 +427,7 @@ void GlobalMenuBarX11::RegisterCommandObserver(int command) {
chrome::AddCommandObserver(browser_, command, this);
}
int GlobalMenuBarX11::NextCommandId() {
int DbusAppmenu::NextCommandId() {
do {
if (last_command_id_ == std::numeric_limits<int>::max())
last_command_id_ = kFirstUnreservedCommandId;
......@@ -440,11 +438,11 @@ int GlobalMenuBarX11::NextCommandId() {
return last_command_id_;
}
void GlobalMenuBarX11::OnAvatarMenuChanged(AvatarMenu* avatar_menu) {
void DbusAppmenu::OnAvatarMenuChanged(AvatarMenu* avatar_menu) {
RebuildProfilesMenu();
}
void GlobalMenuBarX11::OnBrowserSetLastActive(Browser* browser) {
void DbusAppmenu::OnBrowserSetLastActive(Browser* browser) {
// Notify the avatar menu of the change and rebuild the menu. Note: The
// ActiveBrowserChanged() call needs to happen first to update the state.
avatar_menu_->ActiveBrowserChanged(browser);
......@@ -452,19 +450,19 @@ void GlobalMenuBarX11::OnBrowserSetLastActive(Browser* browser) {
RebuildProfilesMenu();
}
void GlobalMenuBarX11::EnabledStateChangedForCommand(int id, bool enabled) {
void DbusAppmenu::EnabledStateChangedForCommand(int id, bool enabled) {
menu_service_->MenuItemsPropertiesUpdated(
FindMenuItemsForCommand(root_menu_.get(), id));
}
void GlobalMenuBarX11::TopSitesLoaded(history::TopSites* top_sites) {}
void DbusAppmenu::TopSitesLoaded(history::TopSites* top_sites) {}
void GlobalMenuBarX11::TopSitesChanged(history::TopSites* top_sites,
ChangeReason change_reason) {
void DbusAppmenu::TopSitesChanged(history::TopSites* top_sites,
ChangeReason change_reason) {
GetTopSitesData();
}
void GlobalMenuBarX11::TabRestoreServiceChanged(
void DbusAppmenu::TabRestoreServiceChanged(
sessions::TabRestoreService* service) {
const sessions::TabRestoreService::Entries& entries = service->entries();
......@@ -521,12 +519,12 @@ void GlobalMenuBarX11::TabRestoreServiceChanged(
menu_service_->MenuLayoutUpdated(history_menu_);
}
void GlobalMenuBarX11::TabRestoreServiceDestroyed(
void DbusAppmenu::TabRestoreServiceDestroyed(
sessions::TabRestoreService* service) {
tab_restore_service_ = nullptr;
}
bool GlobalMenuBarX11::IsCommandIdChecked(int command_id) const {
bool DbusAppmenu::IsCommandIdChecked(int command_id) const {
if (command_id == IDC_SHOW_BOOKMARK_BAR) {
return browser_->profile()->GetPrefs()->GetBoolean(
bookmarks::prefs::kShowBookmarkBar);
......@@ -536,7 +534,7 @@ bool GlobalMenuBarX11::IsCommandIdChecked(int command_id) const {
return it != profile_commands_.end() && it->second == active_profile_index_;
}
bool GlobalMenuBarX11::IsCommandIdEnabled(int command_id) const {
bool DbusAppmenu::IsCommandIdEnabled(int command_id) const {
if (command_id <= kLastChromeCommand)
return chrome::IsCommandEnabled(browser_, command_id);
// There is no active profile in Guest mode, in which case the action
......@@ -546,7 +544,7 @@ bool GlobalMenuBarX11::IsCommandIdEnabled(int command_id) const {
return command_id != kTagRecentlyClosed && command_id != kTagMostVisited;
}
void GlobalMenuBarX11::ExecuteCommand(int command_id, int event_flags) {
void DbusAppmenu::ExecuteCommand(int command_id, int event_flags) {
if (command_id <= kLastChromeCommand) {
chrome::ExecuteCommand(browser_, command_id);
} else if (command_id == kTagProfileEdit) {
......@@ -575,7 +573,7 @@ void GlobalMenuBarX11::ExecuteCommand(int command_id, int event_flags) {
}
}
void GlobalMenuBarX11::OnMenuWillShow(ui::SimpleMenuModel* source) {
void DbusAppmenu::OnMenuWillShow(ui::SimpleMenuModel* source) {
if (source != history_menu_ || tab_restore_service_)
return;
......@@ -592,7 +590,7 @@ void GlobalMenuBarX11::OnMenuWillShow(ui::SimpleMenuModel* source) {
TabRestoreServiceChanged(tab_restore_service_);
}
bool GlobalMenuBarX11::GetAcceleratorForCommandId(
bool DbusAppmenu::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const {
return browser_view_->GetAccelerator(command_id, accelerator);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_H_
#include <map>
#include <string>
......@@ -33,7 +33,7 @@ class Accelerator;
class Browser;
class BrowserView;
struct GlobalMenuBarCommand;
struct DbusAppmenuCommand;
class Profile;
// Controls the Mac style menu bar on Linux desktop environments.
......@@ -42,22 +42,22 @@ class Profile;
// depending on the active window. Unity has been discontinued but the menu
// survived and is usually referred to as DBus AppMenu. There is support for it
// in KDE Plasma in form of a widget that can be inserted into a panel.
class GlobalMenuBarX11 : public AvatarMenuObserver,
public BrowserListObserver,
public CommandObserver,
public history::TopSitesObserver,
public sessions::TabRestoreServiceObserver,
public ui::SimpleMenuModel::Delegate {
class DbusAppmenu : public AvatarMenuObserver,
public BrowserListObserver,
public CommandObserver,
public history::TopSitesObserver,
public sessions::TabRestoreServiceObserver,
public ui::SimpleMenuModel::Delegate {
public:
GlobalMenuBarX11(BrowserView* browser_view, uint32_t browser_frame_xid);
~GlobalMenuBarX11() override;
DbusAppmenu(BrowserView* browser_view, uint32_t browser_frame_id);
~DbusAppmenu() override;
void Initialize(DbusMenu::InitializedCallback callback);
// Creates the object path for DbusemenuServer which is attached to |window|.
std::string GetPath() const;
uint32_t browser_frame_xid() const { return browser_frame_xid_; }
uint32_t browser_frame_id() const { return browser_frame_id_; }
private:
struct HistoryItem;
......@@ -65,7 +65,7 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
// Creates a whole menu defined with |commands| and titled with the string
// |string_id|. Then appends it to |root_menu_|.
ui::SimpleMenuModel* BuildStaticMenu(int string_id,
const GlobalMenuBarCommand* commands);
const DbusAppmenuCommand* commands);
// Creates a HistoryItem from the data in |entry|.
std::unique_ptr<HistoryItem> HistoryItemForTab(
......@@ -134,8 +134,8 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
// as plain int (and not as x11::Window) because it is never used for any
// calls to the X server, but it is always used for building string paths and
// messages, for which it is converted to int (see GetPath() and calls to our
// browser_frame_xid() in GlobalMenuBarRegistrarX11).
const uint32_t browser_frame_xid_;
// browser_frame_id() in DbusAppmenuRegistrar).
const uint32_t browser_frame_id_;
// Has Initialize() been called?
bool initialized_ = false;
......@@ -179,9 +179,9 @@ class GlobalMenuBarX11 : public AvatarMenuObserver,
int last_command_id_;
// For callbacks may be run after destruction.
base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_{this};
base::WeakPtrFactory<DbusAppmenu> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11);
DISALLOW_COPY_AND_ASSIGN(DbusAppmenu);
};
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_H_
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/global_menu_bar_registrar_x11.h"
#include "chrome/browser/ui/views/frame/dbus_appmenu_registrar.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/stl_util.h"
#include "chrome/browser/ui/views/frame/global_menu_bar_x11.h"
#include "chrome/browser/ui/views/frame/dbus_appmenu.h"
#include "components/dbus/thread_linux/dbus_thread_linux.h"
#include "dbus/bus.h"
#include "dbus/message.h"
......@@ -25,11 +25,11 @@ const char kAppMenuRegistrarInterface[] = "com.canonical.AppMenu.Registrar";
} // namespace
// static
GlobalMenuBarRegistrarX11* GlobalMenuBarRegistrarX11::GetInstance() {
return base::Singleton<GlobalMenuBarRegistrarX11>::get();
DbusAppmenuRegistrar* DbusAppmenuRegistrar::GetInstance() {
return base::Singleton<DbusAppmenuRegistrar>::get();
}
void GlobalMenuBarRegistrarX11::OnMenuBarCreated(GlobalMenuBarX11* menu) {
void DbusAppmenuRegistrar::OnMenuBarCreated(DbusAppmenu* menu) {
if (base::Contains(menus_, menu)) {
NOTREACHED();
return;
......@@ -39,13 +39,13 @@ void GlobalMenuBarRegistrarX11::OnMenuBarCreated(GlobalMenuBarX11* menu) {
InitializeMenu(menu);
}
void GlobalMenuBarRegistrarX11::OnMenuBarDestroyed(GlobalMenuBarX11* menu) {
void DbusAppmenuRegistrar::OnMenuBarDestroyed(DbusAppmenu* menu) {
DCHECK(base::Contains(menus_, menu));
if (menus_[menu] == kRegistered) {
dbus::MethodCall method_call(kAppMenuRegistrarInterface,
"UnregisterWindow");
dbus::MessageWriter writer(&method_call);
writer.AppendUint32(menu->browser_frame_xid());
writer.AppendUint32(menu->browser_frame_id());
registrar_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
......@@ -53,7 +53,7 @@ void GlobalMenuBarRegistrarX11::OnMenuBarDestroyed(GlobalMenuBarX11* menu) {
menus_.erase(menu);
}
GlobalMenuBarRegistrarX11::GlobalMenuBarRegistrarX11() {
DbusAppmenuRegistrar::DbusAppmenuRegistrar() {
dbus::Bus::Options bus_options;
bus_options.bus_type = dbus::Bus::SESSION;
bus_options.connection_type = dbus::Bus::PRIVATE;
......@@ -64,40 +64,39 @@ GlobalMenuBarRegistrarX11::GlobalMenuBarRegistrarX11() {
kAppMenuRegistrarName, dbus::ObjectPath(kAppMenuRegistrarPath));
dbus::Bus::ServiceOwnerChangeCallback callback =
base::BindRepeating(&GlobalMenuBarRegistrarX11::OnNameOwnerChanged,
base::BindRepeating(&DbusAppmenuRegistrar::OnNameOwnerChanged,
weak_ptr_factory_.GetWeakPtr());
bus_->ListenForServiceOwnerChange(kAppMenuRegistrarName, callback);
bus_->GetServiceOwner(kAppMenuRegistrarName, callback);
}
GlobalMenuBarRegistrarX11::~GlobalMenuBarRegistrarX11() {
DbusAppmenuRegistrar::~DbusAppmenuRegistrar() {
DCHECK(menus_.empty());
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&dbus::Bus::ShutdownAndBlock, bus_));
}
void GlobalMenuBarRegistrarX11::InitializeMenu(GlobalMenuBarX11* menu) {
void DbusAppmenuRegistrar::InitializeMenu(DbusAppmenu* menu) {
DCHECK(base::Contains(menus_, menu));
DCHECK_EQ(menus_[menu], kUninitialized);
menus_[menu] = kInitializing;
menu->Initialize(base::BindOnce(&GlobalMenuBarRegistrarX11::OnMenuInitialized,
menu->Initialize(base::BindOnce(&DbusAppmenuRegistrar::OnMenuInitialized,
weak_ptr_factory_.GetWeakPtr(), menu));
}
void GlobalMenuBarRegistrarX11::RegisterMenu(GlobalMenuBarX11* menu) {
void DbusAppmenuRegistrar::RegisterMenu(DbusAppmenu* menu) {
DCHECK(base::Contains(menus_, menu));
DCHECK(menus_[menu] == kInitializeSucceeded || menus_[menu] == kRegistered);
menus_[menu] = kRegistered;
dbus::MethodCall method_call(kAppMenuRegistrarInterface, "RegisterWindow");
dbus::MessageWriter writer(&method_call);
writer.AppendUint32(menu->browser_frame_xid());
writer.AppendUint32(menu->browser_frame_id());
writer.AppendObjectPath(dbus::ObjectPath(menu->GetPath()));
registrar_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, base::DoNothing());
}
void GlobalMenuBarRegistrarX11::OnMenuInitialized(GlobalMenuBarX11* menu,
bool success) {
void DbusAppmenuRegistrar::OnMenuInitialized(DbusAppmenu* menu, bool success) {
DCHECK(base::Contains(menus_, menu));
DCHECK(menus_[menu] == kInitializing);
menus_[menu] = success ? kInitializeSucceeded : kInitializeFailed;
......@@ -105,14 +104,14 @@ void GlobalMenuBarRegistrarX11::OnMenuInitialized(GlobalMenuBarX11* menu,
RegisterMenu(menu);
}
void GlobalMenuBarRegistrarX11::OnNameOwnerChanged(
void DbusAppmenuRegistrar::OnNameOwnerChanged(
const std::string& service_owner) {
service_has_owner_ = !service_owner.empty();
// If the name owner changed, we need to reregister all the live menus with
// the system.
for (const auto& pair : menus_) {
GlobalMenuBarX11* menu = pair.first;
DbusAppmenu* menu = pair.first;
switch (pair.second) {
case kUninitialized:
if (service_has_owner_)
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_REGISTRAR_X11_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_REGISTRAR_X11_H_
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_REGISTRAR_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_REGISTRAR_H_
#include <map>
#include <string>
......@@ -18,25 +18,25 @@ class Bus;
class ObjectProxy;
} // namespace dbus
class GlobalMenuBarX11;
class DbusAppmenu;
// Advertises our menu bars to com.canonical.AppMenu.Registrar.
//
// GlobalMenuBarRegistrarX11 is responsible for managing the dbus::Bus shared by
// DbusAppmenuRegistrar is responsible for managing the dbus::Bus shared by
// each menu. We need a separate object to own the dbus channel and to
// register/unregister the mapping between a menu and the com.canonical.dbusmenu
// instance we are offering.
class GlobalMenuBarRegistrarX11 {
class DbusAppmenuRegistrar {
public:
static GlobalMenuBarRegistrarX11* GetInstance();
static DbusAppmenuRegistrar* GetInstance();
void OnMenuBarCreated(GlobalMenuBarX11* menu);
void OnMenuBarDestroyed(GlobalMenuBarX11* menu);
void OnMenuBarCreated(DbusAppmenu* menu);
void OnMenuBarDestroyed(DbusAppmenu* menu);
dbus::Bus* bus() { return bus_.get(); }
private:
friend struct base::DefaultSingletonTraits<GlobalMenuBarRegistrarX11>;
friend struct base::DefaultSingletonTraits<DbusAppmenuRegistrar>;
enum MenuState {
// Initialize() hasn't been called.
......@@ -56,15 +56,15 @@ class GlobalMenuBarRegistrarX11 {
kRegistered,
};
GlobalMenuBarRegistrarX11();
~GlobalMenuBarRegistrarX11();
DbusAppmenuRegistrar();
~DbusAppmenuRegistrar();
void InitializeMenu(GlobalMenuBarX11* menu);
void InitializeMenu(DbusAppmenu* menu);
// Sends the actual message.
void RegisterMenu(GlobalMenuBarX11* menu);
void RegisterMenu(DbusAppmenu* menu);
void OnMenuInitialized(GlobalMenuBarX11* menu, bool success);
void OnMenuInitialized(DbusAppmenu* menu, bool success);
void OnNameOwnerChanged(const std::string& service_owner);
......@@ -74,11 +74,11 @@ class GlobalMenuBarRegistrarX11 {
// Maps menus to flags that indicate if the menu has been successfully
// initialized.
std::map<GlobalMenuBarX11*, MenuState> menus_;
std::map<DbusAppmenu*, MenuState> menus_;
base::WeakPtrFactory<GlobalMenuBarRegistrarX11> weak_ptr_factory_{this};
base::WeakPtrFactory<DbusAppmenuRegistrar> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarRegistrarX11);
DISALLOW_COPY_AND_ASSIGN(DbusAppmenuRegistrar);
};
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_REGISTRAR_X11_H_
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_DBUS_APPMENU_REGISTRAR_H_
......@@ -45,7 +45,7 @@ PrefNotifierImpl::~PrefNotifierImpl() {
// preferences which are known to have subscriptions outliving the
// profile.
if (
// For GlobalMenuBarX11, crbug.com/946668
// For DbusAppmenu, crbug.com/946668
pref_name == "bookmark_bar.show_on_all_tabs" ||
// For BrowserWindowPropertyManager, crbug.com/942491
pref_name == "profile.icon_version" ||
......
......@@ -181,8 +181,8 @@ src:*ui/gtk/unity_service.cc
src:*components/cronet/native/*
src:*third_party/breakpad/breakpad/src/client/linux/handler/exception_handler_unittest.cc
# chrome/browser/ui/views/frame/global_menu_bar_x11.cc
fun:*GlobalMenuBarX11*
# chrome/browser/ui/views/frame/dbus_appmenu.cc
fun:*dbus_appmenu*
# third_party/skia/include/gpu/gl/GrGLFunctions.h
fun:*GrGLFunction*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment