| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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/search_result_container_view.h" | 5 #include "ui/app_list/views/search_result_container_view.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" |
| 9 | 11 |
| 10 namespace app_list { | 12 namespace app_list { |
| 11 | 13 |
| 12 SearchResultContainerView::SearchResultContainerView() | 14 SearchResultContainerView::SearchResultContainerView() |
| 13 : delegate_(nullptr), | 15 : delegate_(nullptr), |
| 14 selected_index_(-1), | 16 selected_index_(-1), |
| 15 num_results_(0), | 17 num_results_(0), |
| 16 results_(NULL), | 18 results_(NULL), |
| 17 update_factory_(this) { | 19 update_factory_(this) { |
| 18 } | 20 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool SearchResultContainerView::IsValidSelectionIndex(int index) const { | 52 bool SearchResultContainerView::IsValidSelectionIndex(int index) const { |
| 51 return index >= 0 && index <= num_results() - 1; | 53 return index >= 0 && index <= num_results() - 1; |
| 52 } | 54 } |
| 53 | 55 |
| 54 void SearchResultContainerView::ScheduleUpdate() { | 56 void SearchResultContainerView::ScheduleUpdate() { |
| 55 // When search results are added one by one, each addition generates an update | 57 // When search results are added one by one, each addition generates an update |
| 56 // request. Consolidates those update requests into one Update call. | 58 // request. Consolidates those update requests into one Update call. |
| 57 if (!update_factory_.HasWeakPtrs()) { | 59 if (!update_factory_.HasWeakPtrs()) { |
| 58 base::MessageLoop::current()->PostTask( | 60 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, | 61 FROM_HERE, base::Bind(&SearchResultContainerView::DoUpdate, |
| 60 base::Bind(&SearchResultContainerView::DoUpdate, | 62 update_factory_.GetWeakPtr())); |
| 61 update_factory_.GetWeakPtr())); | |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 bool SearchResultContainerView::UpdateScheduled() { | 66 bool SearchResultContainerView::UpdateScheduled() { |
| 66 return update_factory_.HasWeakPtrs(); | 67 return update_factory_.HasWeakPtrs(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void SearchResultContainerView::ListItemsAdded(size_t start, size_t count) { | 70 void SearchResultContainerView::ListItemsAdded(size_t start, size_t count) { |
| 70 ScheduleUpdate(); | 71 ScheduleUpdate(); |
| 71 } | 72 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 void SearchResultContainerView::DoUpdate() { | 87 void SearchResultContainerView::DoUpdate() { |
| 87 update_factory_.InvalidateWeakPtrs(); | 88 update_factory_.InvalidateWeakPtrs(); |
| 88 num_results_ = Update(); | 89 num_results_ = Update(); |
| 89 Layout(); | 90 Layout(); |
| 90 if (delegate_) | 91 if (delegate_) |
| 91 delegate_->OnSearchResultContainerResultsChanged(); | 92 delegate_->OnSearchResultContainerResultsChanged(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 } // namespace app_list | 95 } // namespace app_list |
| OLD | NEW |