Index: ui/app_list/views/apps_grid_view.cc |
diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc |
index 491883e420fe14bb68c40c65f4d80f009da4b6e4..e714e0c88abacc620089f6922bad73158a9c6320 100644 |
--- a/ui/app_list/views/apps_grid_view.cc |
+++ b/ui/app_list/views/apps_grid_view.cc |
@@ -237,6 +237,7 @@ AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, |
PaginationModel* pagination_model, |
content::WebContents* start_page_contents) |
: model_(NULL), |
+ apps_(NULL), |
delegate_(delegate), |
pagination_model_(pagination_model), |
page_switcher_view_(new PageSwitcher(pagination_model)), |
@@ -272,11 +273,12 @@ AppsGridView::~AppsGridView() { |
if (drag_view_) |
EndDrag(true); |
- if (model_) { |
+ if (model_) |
model_->RemoveObserver(this); |
- model_->apps()->RemoveObserver(this); |
- } |
pagination_model_->RemoveObserver(this); |
+ |
+ if (apps_) |
+ apps_->RemoveObserver(this); |
} |
void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { |
@@ -291,16 +293,24 @@ void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { |
} |
void AppsGridView::SetModel(AppListModel* model) { |
- if (model_) { |
+ LOG(ERROR) << "AppsGridView::SetModel"; |
xiyuan
2013/10/22 18:15:46
nit: remove this
jennyz
2013/10/22 18:21:31
Done.
|
+ if (model_) |
model_->RemoveObserver(this); |
- model_->apps()->RemoveObserver(this); |
- } |
model_ = model; |
- if (model_) { |
+ if (model_) |
model_->AddObserver(this); |
- model_->apps()->AddObserver(this); |
- } |
+ |
+ Update(); |
+} |
+ |
+void AppsGridView::SetApps(AppListModel::Apps* apps) { |
+ LOG(ERROR) << "AppsGridView::SetApps"; |
xiyuan
2013/10/22 18:15:46
nit: remove this
jennyz
2013/10/22 18:21:31
Done.
|
+ if (apps_) |
+ apps_->RemoveObserver(this); |
+ |
+ apps_ = apps; |
+ apps_->AddObserver(this); |
Update(); |
} |
@@ -625,17 +635,14 @@ void AppsGridView::ViewHierarchyChanged( |
} |
} |
-// static |
-AppsGridView* AppsGridView::GetLastGridViewForTest() { |
- return last_created_grid_view_for_test; |
-} |
- |
void AppsGridView::Update() { |
DCHECK(!selected_view_ && !drag_view_); |
+ if (!apps_) |
+ return; |
view_model_.Clear(); |
- if (model_ && model_->apps()->item_count()) |
- ListItemsAdded(0, model_->apps()->item_count()); |
+ if (apps_ && apps_->item_count()) |
+ ListItemsAdded(0, apps_->item_count()); |
} |
void AppsGridView::UpdatePaging() { |
@@ -648,7 +655,7 @@ void AppsGridView::UpdatePaging() { |
void AppsGridView::UpdatePulsingBlockViews() { |
const int available_slots = |
- tiles_per_page() - model_->apps()->item_count() % tiles_per_page(); |
+ tiles_per_page() - apps_->item_count() % tiles_per_page(); |
const int desired = model_->status() == AppListModel::STATUS_SYNCING ? |
available_slots : 0; |
@@ -670,9 +677,9 @@ void AppsGridView::UpdatePulsingBlockViews() { |
} |
views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
- DCHECK_LT(index, model_->apps()->item_count()); |
+ DCHECK_LT(index, apps_->item_count()); |
AppListItemView* view = new AppListItemView(this, |
- model_->apps()->GetItemAt(index)); |
+ apps_->GetItemAt(index)); |
view->SetIconSize(icon_size_); |
#if defined(USE_AURA) |
view->SetPaintToLayer(true); |
@@ -1107,10 +1114,10 @@ void AppsGridView::MoveItemInModel(views::View* item_view, |
if (target_model_index == current_model_index) |
return; |
- model_->apps()->RemoveObserver(this); |
- model_->apps()->Move(current_model_index, target_model_index); |
+ apps_->RemoveObserver(this); |
+ apps_->Move(current_model_index, target_model_index); |
view_model_.Move(current_model_index, target_model_index); |
- model_->apps()->AddObserver(this); |
+ apps_->AddObserver(this); |
if (pagination_model_->selected_page() != target.page) |
pagination_model_->SelectPage(target.page, false); |