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

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

Issue 1169903002: Fix crash when opening up the status tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Perform initialization in class body Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/cast/tray_cast.cc
diff --git a/ash/system/cast/tray_cast.cc b/ash/system/cast/tray_cast.cc
index 7d5dd57ec560cef5327e00beafd38491c39a6847..220e259510ce8b96add07d2c69c039a40dae4fa7 100644
--- a/ash/system/cast/tray_cast.cc
+++ b/ash/system/cast/tray_cast.cc
@@ -60,6 +60,7 @@ class CastSelectDefaultView : public TrayItemMore {
const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
CastConfigDelegate* cast_config_delegate_;
+ base::WeakPtrFactory<CastSelectDefaultView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView);
};
@@ -68,7 +69,8 @@ CastSelectDefaultView::CastSelectDefaultView(
CastConfigDelegate* cast_config_delegate,
bool show_more)
: TrayItemMore(owner, show_more),
- cast_config_delegate_(cast_config_delegate) {
+ cast_config_delegate_(cast_config_delegate),
+ weak_ptr_factory_(this) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia());
@@ -99,8 +101,9 @@ void CastSelectDefaultView::UpdateLabel() {
cast_config_delegate_->HasCastExtension() == false)
return;
- cast_config_delegate_->GetReceiversAndActivities(base::Bind(
- &CastSelectDefaultView::UpdateLabelCallback, base::Unretained(this)));
+ cast_config_delegate_->GetReceiversAndActivities(
+ base::Bind(&CastSelectDefaultView::UpdateLabelCallback,
+ weak_ptr_factory_.GetWeakPtr()));
}
// This view is displayed when the screen is actively being casted; it allows
@@ -130,12 +133,13 @@ class CastCastView : public views::View, public views::ButtonListener {
views::Label* title_;
views::Label* details_;
TrayPopupLabelButton* stop_button_;
+ base::WeakPtrFactory<CastCastView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CastCastView);
};
CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate)
- : cast_config_delegate_(cast_config_delegate) {
+ : cast_config_delegate_(cast_config_delegate), weak_ptr_factory_(this) {
// We will initialize the primary tray view which shows a stop button here.
set_background(views::Background::CreateSolidBackground(kBackgroundColor));
@@ -216,8 +220,8 @@ void CastCastView::UpdateLabel() {
cast_config_delegate_->HasCastExtension() == false)
return;
- cast_config_delegate_->GetReceiversAndActivities(
- base::Bind(&CastCastView::UpdateLabelCallback, base::Unretained(this)));
+ cast_config_delegate_->GetReceiversAndActivities(base::Bind(
+ &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr()));
}
void CastCastView::UpdateLabelCallback(
@@ -405,10 +409,11 @@ class CastDetailedView : public TrayDetailsView, public ViewClickListener {
CastConfigDelegate* cast_config_delegate_;
user::LoginStatus login_;
- views::View* options_;
+ views::View* options_ = nullptr;
CastConfigDelegate::ReceiversAndActivites 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);
};
@@ -419,7 +424,7 @@ CastDetailedView::CastDetailedView(SystemTrayItem* owner,
: TrayDetailsView(owner),
cast_config_delegate_(cast_config_delegate),
login_(login),
- options_(nullptr) {
+ weak_ptr_factory_(this) {
CreateItems();
UpdateReceiverList();
}
@@ -434,8 +439,9 @@ void CastDetailedView::CreateItems() {
}
void CastDetailedView::UpdateReceiverList() {
- cast_config_delegate_->GetReceiversAndActivities(base::Bind(
- &CastDetailedView::UpdateReceiverListCallback, base::Unretained(this)));
+ cast_config_delegate_->GetReceiversAndActivities(
+ base::Bind(&CastDetailedView::UpdateReceiverListCallback,
+ weak_ptr_factory_.GetWeakPtr()));
}
void CastDetailedView::UpdateReceiverListCallback(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698