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

Unified Diff: ash/system/cast/tray_cast.cc

Issue 1567103005: Replace base::CallbackList with base::ObserverList in CastConfigDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add DLL export to fix windows build Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ash/system/cast/tray_cast.cc
diff --git a/ash/system/cast/tray_cast.cc b/ash/system/cast/tray_cast.cc
index b155c680c9aca0ad0ff5954ee4b2c05002a0ca98..1df2b1ca00d189d74c9689768db3b99ca905ec26 100644
--- a/ash/system/cast/tray_cast.cc
+++ b/ash/system/cast/tray_cast.cc
@@ -42,6 +42,11 @@ const int kStopButtonRightPadding = 18;
// Returns the active CastConfigDelegate instance.
ash::CastConfigDelegate* GetCastConfigDelegate() {
+ if (!ash::Shell::GetInstance() ||
achuithb 2016/01/13 09:21:25 Could you please add a comment here explaining whe
jdufault 2016/01/13 19:43:26 Done.
+ !ash::Shell::GetInstance()->system_tray_delegate()) {
+ return nullptr;
+ }
+
return ash::Shell::GetInstance()
->system_tray_delegate()
->GetCastConfigDelegate();
@@ -125,12 +130,11 @@ class CastCastView : public views::View, public views::ButtonListener {
views::ImageView* icon_;
views::Label* label_;
TrayPopupLabelButton* stop_button_;
- base::WeakPtrFactory<CastCastView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CastCastView);
};
-CastCastView::CastCastView() : weak_ptr_factory_(this) {
+CastCastView::CastCastView() {
// We will initialize the primary tray view which shows a stop button here.
set_background(views::Background::CreateSolidBackground(kBackgroundColor));
@@ -412,7 +416,6 @@ class CastDetailedView : public TrayDetailsView, public ViewClickListener {
receivers_and_activities_;
// A mapping from the view pointer to the associated activity id.
std::map<views::View*, std::string> receiver_activity_map_;
- base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
};
@@ -421,7 +424,7 @@ CastDetailedView::CastDetailedView(
SystemTrayItem* owner,
user::LoginStatus login,
const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities)
- : TrayDetailsView(owner), login_(login), weak_ptr_factory_(this) {
+ : TrayDetailsView(owner), login_(login) {
CreateItems();
UpdateReceiverList(receivers_and_activities);
}
@@ -551,14 +554,15 @@ void CastDetailedView::OnViewClicked(views::View* sender) {
} // namespace tray
-TrayCast::TrayCast(SystemTray* system_tray)
- : SystemTrayItem(system_tray),
- weak_ptr_factory_(this) {
+TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) {
Shell::GetInstance()->AddShellObserver(this);
}
TrayCast::~TrayCast() {
Shell::GetInstance()->RemoveShellObserver(this);
achuithb 2016/01/13 09:21:25 Do we need to check Shell::GetInstance here?
jdufault 2016/01/13 19:43:26 Done.
+
+ if (GetCastConfigDelegate())
achuithb 2016/01/13 09:21:25 Using a temporary is an option here so we don't ca
jdufault 2016/01/13 19:43:26 Done.
+ GetCastConfigDelegate()->RemoveObserver(this);
}
void TrayCast::StartCastForTest(const std::string& receiver_id) {
@@ -597,10 +601,9 @@ views::View* TrayCast::CreateDefaultView(user::LoginStatus status) {
// - The listener is only added if there is a cast extension. If the call
// below were in the ctor, then the cast tray item would not appear if the
// user installed the extension in an existing session.
- if (!device_update_subscription_) {
- device_update_subscription_ =
- cast_config_delegate->RegisterDeviceUpdateObserver(base::Bind(
- &TrayCast::OnReceiversUpdated, weak_ptr_factory_.GetWeakPtr()));
+ if (!added_observer_) {
+ cast_config_delegate->AddObserver(this);
+ added_observer_ = true;
}
// The extension updates its view model whenever the popup is opened, so we
@@ -645,7 +648,7 @@ bool TrayCast::HasCastExtension() {
cast_config_delegate->HasCastExtension();
}
-void TrayCast::OnReceiversUpdated(
+void TrayCast::OnDevicesUpdated(
const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
receivers_and_activities_ = receivers_activities;

Powered by Google App Engine
This is Rietveld 408576698