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..8a6e347bc42da27ab47e2bc56f0f239fd8eadd8a 100644 |
--- a/ash/system/cast/tray_cast.cc |
+++ b/ash/system/cast/tray_cast.cc |
@@ -42,6 +42,10 @@ const int kStopButtonRightPadding = 18; |
// Returns the active CastConfigDelegate instance. |
ash::CastConfigDelegate* GetCastConfigDelegate() { |
+ if (!ash::Shell::GetInstance() || |
+ !ash::Shell::GetInstance()->system_tray_delegate()) |
+ return nullptr; |
stevenjb
2016/01/12 23:31:49
nit: {}
jdufault
2016/01/12 23:59:22
Done.
|
+ |
return ash::Shell::GetInstance() |
->system_tray_delegate() |
->GetCastConfigDelegate(); |
@@ -125,12 +129,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 +415,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 +423,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 +553,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); |
+ |
+ if (GetCastConfigDelegate()) |
+ GetCastConfigDelegate()->RemoveObserver(this); |
} |
void TrayCast::StartCastForTest(const std::string& receiver_id) { |
@@ -597,10 +600,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 +647,7 @@ bool TrayCast::HasCastExtension() { |
cast_config_delegate->HasCastExtension(); |
} |
-void TrayCast::OnReceiversUpdated( |
+void TrayCast::OnDevicesUpdated( |
const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { |
receivers_and_activities_ = receivers_activities; |