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

Side by Side Diff: ui/app_list/views/app_list_main_view.cc

Issue 334293005: Fix use-after-free when switching profiles in the experimental app list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/app_list/views/app_list_main_view.h" 5 #include "ui/app_list/views/app_list_main_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 21 matching lines...) Expand all
32 namespace app_list { 32 namespace app_list {
33 33
34 namespace { 34 namespace {
35 35
36 // Inner padding space in pixels of bubble contents. 36 // Inner padding space in pixels of bubble contents.
37 const int kInnerPadding = 1; 37 const int kInnerPadding = 1;
38 38
39 // The maximum allowed time to wait for icon loading in milliseconds. 39 // The maximum allowed time to wait for icon loading in milliseconds.
40 const int kMaxIconLoadingWaitTimeInMs = 50; 40 const int kMaxIconLoadingWaitTimeInMs = 50;
41 41
42 const int kContentsViewIndex = 1;
43
44 } // namespace 42 } // namespace
45 43
46 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
47 // AppListMainView::IconLoader 45 // AppListMainView::IconLoader
48 46
49 class AppListMainView::IconLoader : public AppListItemObserver { 47 class AppListMainView::IconLoader : public AppListItemObserver {
50 public: 48 public:
51 IconLoader(AppListMainView* owner, 49 IconLoader(AppListMainView* owner,
52 AppListItem* item, 50 AppListItem* item,
53 float scale) 51 float scale)
(...skipping 29 matching lines...) Expand all
83 //////////////////////////////////////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////////////////
84 // AppListMainView: 82 // AppListMainView:
85 83
86 AppListMainView::AppListMainView(AppListViewDelegate* delegate, 84 AppListMainView::AppListMainView(AppListViewDelegate* delegate,
87 int initial_apps_page, 85 int initial_apps_page,
88 gfx::NativeView parent) 86 gfx::NativeView parent)
89 : delegate_(delegate), 87 : delegate_(delegate),
90 model_(delegate->GetModel()), 88 model_(delegate->GetModel()),
91 search_box_view_(NULL), 89 search_box_view_(NULL),
92 contents_view_(NULL), 90 contents_view_(NULL),
91 contents_switcher_view_(NULL),
93 weak_ptr_factory_(this) { 92 weak_ptr_factory_(this) {
94 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 93 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
95 kInnerPadding, 94 kInnerPadding,
96 kInnerPadding, 95 kInnerPadding,
97 kInnerPadding)); 96 kInnerPadding));
98 97
99 search_box_view_ = new SearchBoxView(this, delegate); 98 search_box_view_ = new SearchBoxView(this, delegate);
100 AddChildView(search_box_view_); 99 AddChildView(search_box_view_);
101 AddContentsView(); 100 AddContentsView();
102 if (app_list::switches::IsExperimentalAppListEnabled())
103 AddChildView(new ContentsSwitcherView(contents_view_));
104 101
105 // Switch the apps grid view to the specified page. 102 // Switch the apps grid view to the specified page.
106 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); 103 app_list::PaginationModel* pagination_model = GetAppsPaginationModel();
107 if (pagination_model->is_valid_page(initial_apps_page)) 104 if (pagination_model->is_valid_page(initial_apps_page))
108 pagination_model->SelectPage(initial_apps_page, false); 105 pagination_model->SelectPage(initial_apps_page, false);
109 106
110 // Starts icon loading early. 107 // Starts icon loading early.
111 PreloadIcons(parent); 108 PreloadIcons(parent);
112 } 109 }
113 110
114 void AppListMainView::AddContentsView() { 111 void AppListMainView::AddContentsView() {
115 contents_view_ = new ContentsView(this, model_, delegate_); 112 contents_view_ = new ContentsView(this, model_, delegate_);
116 AddChildViewAt(contents_view_, kContentsViewIndex); 113 DCHECK_EQ(1, child_count());
Matt Giuca 2014/06/17 05:49:26 This doesn't seem robust. Is this assuming that th
calamity 2014/06/17 09:15:39 It's not. AddChildViewAt was there to fix a bug th
Matt Giuca 2014/06/18 00:06:06 I'm a little unsure what you mean here. Does "It's
calamity 2014/06/18 01:00:02 Oops. Actually removed.
114 AddChildView(contents_view_);
115 if (app_list::switches::IsExperimentalAppListEnabled()) {
116 contents_switcher_view_ = new ContentsSwitcherView(contents_view_);
117 AddChildView(contents_switcher_view_);
118 }
117 119
118 search_box_view_->set_contents_view(contents_view_); 120 search_box_view_->set_contents_view(contents_view_);
119 121
120 contents_view_->SetPaintToLayer(true); 122 contents_view_->SetPaintToLayer(true);
121 contents_view_->SetFillsBoundsOpaquely(false); 123 contents_view_->SetFillsBoundsOpaquely(false);
122 contents_view_->layer()->SetMasksToBounds(true); 124 contents_view_->layer()->SetMasksToBounds(true);
123 } 125 }
124 126
125 AppListMainView::~AppListMainView() { 127 AppListMainView::~AppListMainView() {
126 pending_icon_loaders_.clear(); 128 pending_icon_loaders_.clear();
(...skipping 30 matching lines...) Expand all
157 void AppListMainView::Prerender() { 159 void AppListMainView::Prerender() {
158 contents_view_->Prerender(); 160 contents_view_->Prerender();
159 } 161 }
160 162
161 void AppListMainView::ModelChanged() { 163 void AppListMainView::ModelChanged() {
162 pending_icon_loaders_.clear(); 164 pending_icon_loaders_.clear();
163 model_ = delegate_->GetModel(); 165 model_ = delegate_->GetModel();
164 search_box_view_->ModelChanged(); 166 search_box_view_->ModelChanged();
165 delete contents_view_; 167 delete contents_view_;
166 contents_view_ = NULL; 168 contents_view_ = NULL;
169 if (contents_switcher_view_)
170 delete contents_switcher_view_;
171 contents_switcher_view_ = NULL;
Matt Giuca 2014/06/17 05:49:25 nit: May as well put this line inside the if state
calamity 2014/06/17 09:15:39 Done.
167 AddContentsView(); 172 AddContentsView();
168 Layout(); 173 Layout();
169 } 174 }
170 175
171 void AppListMainView::UpdateSearchBoxVisibility() { 176 void AppListMainView::UpdateSearchBoxVisibility() {
172 search_box_view_->SetVisible( 177 search_box_view_->SetVisible(
173 !contents_view_->IsNamedPageActive(ContentsView::NAMED_PAGE_START) || 178 !contents_view_->IsNamedPageActive(ContentsView::NAMED_PAGE_START) ||
174 contents_view_->IsShowingSearchResults()); 179 contents_view_->IsShowingSearchResults());
175 } 180 }
176 181
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Resubmit the query via a posted task so that all observers for the 290 // Resubmit the query via a posted task so that all observers for the
286 // uninstall notification are notified. 291 // uninstall notification are notified.
287 base::MessageLoop::current()->PostTask( 292 base::MessageLoop::current()->PostTask(
288 FROM_HERE, 293 FROM_HERE,
289 base::Bind(&AppListMainView::QueryChanged, 294 base::Bind(&AppListMainView::QueryChanged,
290 weak_ptr_factory_.GetWeakPtr(), 295 weak_ptr_factory_.GetWeakPtr(),
291 search_box_view_)); 296 search_box_view_));
292 } 297 }
293 298
294 } // namespace app_list 299 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698