Disable flaky UnloadTest.CrossSiteInfiniteBeforeUnloadSync on Mac.
[chromium-blink-merge.git] / ui / app_list / views / search_result_container_view.cc
blobb8a9852e01965260f486b7e6a1e66fafa93aebc3
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/app_list/views/search_result_container_view.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
10 namespace app_list {
12 SearchResultContainerView::SearchResultContainerView()
13 : selected_index_(-1),
14 num_results_(0),
15 results_(NULL),
16 update_factory_(this) {
19 SearchResultContainerView::~SearchResultContainerView() {
20 if (results_)
21 results_->RemoveObserver(this);
24 void SearchResultContainerView::SetResults(
25 AppListModel::SearchResults* results) {
26 if (results_)
27 results_->RemoveObserver(this);
29 results_ = results;
30 if (results_)
31 results_->AddObserver(this);
33 DoUpdate();
36 void SearchResultContainerView::SetSelectedIndex(int selected_index) {
37 DCHECK(IsValidSelectionIndex(selected_index));
38 int old_selected = selected_index_;
39 selected_index_ = selected_index;
40 UpdateSelectedIndex(old_selected, selected_index_);
43 void SearchResultContainerView::ClearSelectedIndex() {
44 int old_selected = selected_index_;
45 selected_index_ = -1;
46 UpdateSelectedIndex(old_selected, selected_index_);
49 bool SearchResultContainerView::IsValidSelectionIndex(int index) const {
50 return index >= 0 && index <= num_results() - 1;
53 void SearchResultContainerView::ScheduleUpdate() {
54 // When search results are added one by one, each addition generates an update
55 // request. Consolidates those update requests into one Update call.
56 if (!update_factory_.HasWeakPtrs()) {
57 base::MessageLoop::current()->PostTask(
58 FROM_HERE,
59 base::Bind(&SearchResultContainerView::DoUpdate,
60 update_factory_.GetWeakPtr()));
64 bool SearchResultContainerView::UpdateScheduled() {
65 return update_factory_.HasWeakPtrs();
68 void SearchResultContainerView::ListItemsAdded(size_t start, size_t count) {
69 ScheduleUpdate();
72 void SearchResultContainerView::ListItemsRemoved(size_t start, size_t count) {
73 ScheduleUpdate();
76 void SearchResultContainerView::ListItemMoved(size_t index,
77 size_t target_index) {
78 ScheduleUpdate();
81 void SearchResultContainerView::ListItemsChanged(size_t start, size_t count) {
82 ScheduleUpdate();
85 void SearchResultContainerView::DoUpdate() {
86 update_factory_.InvalidateWeakPtrs();
87 num_results_ = Update();
88 Layout();
89 PreferredSizeChanged();
92 } // namespace app_list