Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cdesouza-chromium committed Oct 30, 2024
1 parent 486ff21 commit 1b0e53b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 134 deletions.
21 changes: 1 addition & 20 deletions browser/ui/views/sidebar/sidebar_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ void SidebarContainerView::WillShowSidePanel() {
StartObservingContextualSidePanelEntry(active_web_contents);

auto* global_registry = side_panel_coordinator_->GetWindowRegistry();
AddSidePanelRegistryObservation(global_registry);
for (const auto& entry : global_registry->entries()) {
AddSidePanelEntryObservation(entry.get());
}
Expand Down Expand Up @@ -803,14 +802,6 @@ void SidebarContainerView::OnEntryHidden(SidePanelEntry* entry) {
}
}

void SidebarContainerView::OnEntryWillDestroy(SidePanelEntry* entry) {
side_panel_entries_observed_.erase(entry);
}

void SidebarContainerView::OnRegistryWillDestroy(SidePanelRegistry* registry) {
side_panel_registry_observation_.RemoveObservation(registry);
}

void SidebarContainerView::UpdateActiveItemState() {
DVLOG(1) << "Update active item state";

Expand Down Expand Up @@ -878,7 +869,6 @@ void SidebarContainerView::StartObservingContextualSidePanelEntry(
}

// Adding observations for the side panel entries from tab not seen before.
AddSidePanelRegistryObservation(registry);
for (const auto& entry : registry->entries()) {
AddSidePanelEntryObservation(entry.get());
}
Expand Down Expand Up @@ -907,20 +897,11 @@ BraveBrowser* SidebarContainerView::GetBraveBrowser() const {
}

void SidebarContainerView::AddSidePanelEntryObservation(SidePanelEntry* entry) {
if (side_panel_entries_observed_.count(entry)) {
if (entry->IsBeingObservedBy(this)) {
return;
}

side_panel_entries_observed_.insert(entry);
entry->AddObserver(this);
}
void SidebarContainerView::AddSidePanelRegistryObservation(
SidePanelRegistry* registry) {
if (side_panel_registry_observation_.IsObservingSource(registry)) {
return;
}
side_panel_registry_observation_.AddObservation(registry);
}

BEGIN_METADATA(SidebarContainerView)
END_METADATA
19 changes: 0 additions & 19 deletions browser/ui/views/sidebar/sidebar_container_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class SidebarContainerView
public SidebarShowOptionsEventDetectWidget::Delegate,
public sidebar::SidebarModel::Observer,
public SidePanelEntryObserver,
public SidePanelRegistry::Observer,
public SidePanelViewStateObserver,
public TabStripModelObserver {
METADATA_HEADER(SidebarContainerView, views::View)
Expand Down Expand Up @@ -132,10 +131,6 @@ class SidebarContainerView
void OnEntryShown(SidePanelEntry* entry) override;
void OnEntryHidden(SidePanelEntry* entry) override;

// SidePanelRegistry::Observer:
void OnEntryWillDestroy(SidePanelEntry* entry) override;
void OnRegistryWillDestroy(SidePanelRegistry* registry) override;

// TabStripModelObserver:
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
Expand Down Expand Up @@ -204,9 +199,6 @@ class SidebarContainerView
// Adds a passive observation for the given side panel entry.
void AddSidePanelEntryObservation(SidePanelEntry* entry);

// Adds a observation for the given side panel registry.
void AddSidePanelRegistryObservation(SidePanelRegistry* registry);

raw_ptr<Browser> browser_ = nullptr;
raw_ptr<SidePanelCoordinator> side_panel_coordinator_ = nullptr;
raw_ptr<BraveSidePanel> side_panel_ = nullptr;
Expand All @@ -230,17 +222,6 @@ class SidebarContainerView
base::ScopedObservation<sidebar::SidebarModel,
sidebar::SidebarModel::Observer>
sidebar_model_observation_{this};

// The multishot observation for the side panel registries, which will
// deregister themselves when going out of scope.
base::ScopedMultiSourceObservation<SidePanelRegistry,
SidePanelRegistry::Observer>
side_panel_registry_observation_{this};

// This is a passive observations for side panel entries, to prevent double
// observer additions. These observations are supposed to outlive the observed
// objects, so `RemoveObservation` is never called on these entries.
base::flat_set<SidePanelEntry*> side_panel_entries_observed_;
};

#endif // BRAVE_BROWSER_UI_VIEWS_SIDEBAR_SIDEBAR_CONTAINER_VIEW_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"

#include "src/chrome/browser/ui/views/side_panel/side_panel_entry.cc"

bool SidePanelEntry::IsBeingObservedBy(SidePanelEntryObserver* observer) {
return observers_.HasObserver(observer);
}
17 changes: 17 additions & 0 deletions chromium_src/chrome/browser/ui/views/side_panel/side_panel_entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SIDE_PANEL_ENTRY_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SIDE_PANEL_ENTRY_H_

#define SupportsNewTabButton(...) \
SupportsNewTabButton(__VA_ARGS__); \
bool IsBeingObservedBy(SidePanelEntryObserver* observer)

#include "src/chrome/browser/ui/views/side_panel/side_panel_entry.h" // IWYU pragma: export

#undef SupportsNewTabButton

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SIDE_PANEL_ENTRY_H_

This file was deleted.

This file was deleted.

0 comments on commit 1b0e53b

Please sign in to comment.