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

Side by Side Diff: ash/common/system/status_area_widget.cc

Issue 2557593009: Fix Chrome crashes on calling OnTrayVisibilityChange (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/status_area_widget.h" 5 #include "ash/common/system/status_area_widget.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/wm_shelf.h" 8 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/common/system/overview/overview_button_tray.h" 9 #include "ash/common/system/overview/overview_button_tray.h"
10 #include "ash/common/system/status_area_widget_delegate.h" 10 #include "ash/common/system/status_area_widget_delegate.h"
(...skipping 25 matching lines...) Expand all
36 overview_button_tray_(nullptr), 36 overview_button_tray_(nullptr),
37 system_tray_(nullptr), 37 system_tray_(nullptr),
38 web_notification_tray_(nullptr), 38 web_notification_tray_(nullptr),
39 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
40 logout_button_tray_(nullptr), 40 logout_button_tray_(nullptr),
41 palette_tray_(nullptr), 41 palette_tray_(nullptr),
42 virtual_keyboard_tray_(nullptr), 42 virtual_keyboard_tray_(nullptr),
43 ime_menu_tray_(nullptr), 43 ime_menu_tray_(nullptr),
44 #endif 44 #endif
45 login_status_(LoginStatus::NOT_LOGGED_IN), 45 login_status_(LoginStatus::NOT_LOGGED_IN),
46 wm_shelf_(wm_shelf) { 46 wm_shelf_(wm_shelf),
47 is_initialized_(false) {
47 views::Widget::InitParams params( 48 views::Widget::InitParams params(
48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 49 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
49 params.delegate = status_area_widget_delegate_; 50 params.delegate = status_area_widget_delegate_;
50 params.name = "StatusAreaWidget"; 51 params.name = "StatusAreaWidget";
51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 52 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
52 status_container->GetRootWindowController() 53 status_container->GetRootWindowController()
53 ->ConfigureWidgetInitParamsForContainer( 54 ->ConfigureWidgetInitParamsForContainer(
54 this, status_container->GetShellWindowId(), &params); 55 this, status_container->GetShellWindowId(), &params);
55 Init(params); 56 Init(params);
56 set_focus_on_creation(false); 57 set_focus_on_creation(false);
(...skipping 19 matching lines...) Expand all
76 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); 77 system_tray_->InitializeTrayItems(delegate, web_notification_tray_);
77 web_notification_tray_->Initialize(); 78 web_notification_tray_->Initialize();
78 #if defined(OS_CHROMEOS) 79 #if defined(OS_CHROMEOS)
79 logout_button_tray_->Initialize(); 80 logout_button_tray_->Initialize();
80 virtual_keyboard_tray_->Initialize(); 81 virtual_keyboard_tray_->Initialize();
81 ime_menu_tray_->Initialize(); 82 ime_menu_tray_->Initialize();
82 #endif 83 #endif
83 overview_button_tray_->Initialize(); 84 overview_button_tray_->Initialize();
84 SetShelfAlignment(system_tray_->shelf_alignment()); 85 SetShelfAlignment(system_tray_->shelf_alignment());
85 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); 86 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
87 is_initialized_ = true;
86 } 88 }
87 89
88 void StatusAreaWidget::Shutdown() { 90 void StatusAreaWidget::Shutdown() {
91 is_initialized_ = false;
89 system_tray_->Shutdown(); 92 system_tray_->Shutdown();
90 // Destroy the trays early, causing them to be removed from the view 93 // Destroy the trays early, causing them to be removed from the view
91 // hierarchy. Do not used scoped pointers since we don't want to destroy them 94 // hierarchy. Do not used scoped pointers since we don't want to destroy them
92 // in the destructor if Shutdown() is not called (e.g. in tests). 95 // in the destructor if Shutdown() is not called (e.g. in tests).
93 delete web_notification_tray_; 96 delete web_notification_tray_;
94 web_notification_tray_ = nullptr; 97 web_notification_tray_ = nullptr;
95 // Must be destroyed after |web_notification_tray_|. 98 // Must be destroyed after |web_notification_tray_|.
96 delete system_tray_; 99 delete system_tray_;
97 system_tray_ = nullptr; 100 system_tray_ = nullptr;
98 #if defined(OS_CHROMEOS) 101 #if defined(OS_CHROMEOS)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); 144 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
142 #endif 145 #endif
143 if (overview_button_tray_) 146 if (overview_button_tray_)
144 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); 147 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
145 } 148 }
146 149
147 void StatusAreaWidget::OnTrayVisibilityChanged(TrayBackgroundView* tray) { 150 void StatusAreaWidget::OnTrayVisibilityChanged(TrayBackgroundView* tray) {
148 if (!ash::MaterialDesignController::IsShelfMaterial()) 151 if (!ash::MaterialDesignController::IsShelfMaterial())
149 return; 152 return;
150 153
154 // OnTrayVisibilityChanged could be called asynchronously by different events,
155 // when a primary display is add to the system, as a result these unexpected
156 // access to uninitialized |tray| lead to Chrome crashes. |is_initialized_| is
157 // added to prevent to access |tray| before its initialization.
varkha 2016/12/09 00:59:03 nit: I think this early return is self-explanatory
yiyix 2016/12/09 20:04:53 True, i kinda of want to give some background abou
158 if (!is_initialized_) {
159 return;
160 }
161
151 // No separator is required between |system_tray_| and |overview_button_tray_| 162 // No separator is required between |system_tray_| and |overview_button_tray_|
152 // and no separator is required for the right most tray item. 163 // and no separator is required for the right most tray item.
153 if (tray == overview_button_tray_ || tray == system_tray_) { 164 if (tray == overview_button_tray_ || tray == system_tray_) {
154 tray->SetSeparatorVisibility(false); 165 tray->SetSeparatorVisibility(false);
155 return; 166 return;
156 } 167 }
157 #if defined(OS_CHROMEOS) 168 #if defined(OS_CHROMEOS)
158 // If |logout_button_tray_| is visible, check if |tray| is visible and to 169 // If |logout_button_tray_| is visible, check if |tray| is visible and to
159 // the left of |logout_button_tray_|. If it is the case, then no separator 170 // the left of |logout_button_tray_|. If it is the case, then no separator
160 // is required between |tray| and |logout_button_tray_|. If 171 // is required between |tray| and |logout_button_tray_|. If
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return false; 308 return false;
298 } 309 }
299 #endif 310 #endif
300 311
301 void StatusAreaWidget::AddOverviewButtonTray() { 312 void StatusAreaWidget::AddOverviewButtonTray() {
302 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); 313 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
303 status_area_widget_delegate_->AddTray(overview_button_tray_); 314 status_area_widget_delegate_->AddTray(overview_button_tray_);
304 } 315 }
305 316
306 } // namespace ash 317 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698