OLD | NEW |
---|---|
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 "chrome/browser/custom_home_pages_table_model.h" | 5 #include "chrome/browser/custom_home_pages_table_model.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 89 |
90 /** | 90 /** |
91 * Move a number of existing entries to a new position, reordering the table. | 91 * Move a number of existing entries to a new position, reordering the table. |
92 * | 92 * |
93 * We determine the range of elements affected by the move, save the moved | 93 * We determine the range of elements affected by the move, save the moved |
94 * elements, compact the remaining ones, and re-insert moved elements. | 94 * elements, compact the remaining ones, and re-insert moved elements. |
95 * Expects |index_list| to be ordered ascending. | 95 * Expects |index_list| to be ordered ascending. |
96 */ | 96 */ |
97 void CustomHomePagesTableModel::MoveURLs(int insert_before, | 97 void CustomHomePagesTableModel::MoveURLs(int insert_before, |
98 const std::vector<int>& index_list) { | 98 const std::vector<int>& index_list) { |
99 // Was causing crashes when just a DCHECK(), see http://crbug.com/136576. | 99 DCHECK(!index_list.empty()); |
100 if (index_list.empty() || insert_before < 0 || insert_before > RowCount()) { | 100 DCHECK(insert_before >= 0 && insert_before <= RowCount()) |
101 NOTREACHED(); | 101 << "Index out of range: " << insert_before; |
Dan Beam
2013/03/09 00:22:04
is this meant to stay here or debugging code? I'd
dcheng
2013/03/09 01:06:22
I figured it didn't matter since it was only going
| |
102 return; | |
103 } | |
104 | 102 |
105 // The range of elements that needs to be reshuffled is [ |first|, |last| ). | 103 // The range of elements that needs to be reshuffled is [ |first|, |last| ). |
106 int first = std::min(insert_before, index_list.front()); | 104 int first = std::min(insert_before, index_list.front()); |
107 int last = std::max(insert_before, index_list.back() + 1); | 105 int last = std::max(insert_before, index_list.back() + 1); |
108 | 106 |
109 // Save the dragged elements. Also, adjust insertion point if it is before a | 107 // Save the dragged elements. Also, adjust insertion point if it is before a |
110 // dragged element. | 108 // dragged element. |
111 std::vector<Entry> moved_entries; | 109 std::vector<Entry> moved_entries; |
112 for (size_t i = 0; i < index_list.size(); ++i) { | 110 for (size_t i = 0; i < index_list.size(); ++i) { |
113 moved_entries.push_back(entries_[index_list[i]]); | 111 moved_entries.push_back(entries_[index_list[i]]); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 return NULL; | 265 return NULL; |
268 } | 266 } |
269 | 267 |
270 string16 CustomHomePagesTableModel::FormattedURL(int row) const { | 268 string16 CustomHomePagesTableModel::FormattedURL(int row) const { |
271 std::string languages = | 269 std::string languages = |
272 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 270 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
273 string16 url = net::FormatUrl(entries_[row].url, languages); | 271 string16 url = net::FormatUrl(entries_[row].url, languages); |
274 url = base::i18n::GetDisplayStringInLTRDirectionality(url); | 272 url = base::i18n::GetDisplayStringInLTRDirectionality(url); |
275 return url; | 273 return url; |
276 } | 274 } |
OLD | NEW |