OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/history_model.h" | 5 #include "chrome/browser/history_model.h" |
6 | 6 |
7 #include "chrome/browser/bookmarks/bookmark_bar_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
9 | 9 |
10 // The max number of results to retrieve when browsing user's history. | 10 // The max number of results to retrieve when browsing user's history. |
11 static const int kMaxBrowseResults = 800; | 11 static const int kMaxBrowseResults = 800; |
12 | 12 |
13 // The max number of search results to retrieve. | 13 // The max number of search results to retrieve. |
14 static const int kMaxSearchResults = 100; | 14 static const int kMaxSearchResults = 100; |
15 | 15 |
16 HistoryModel::HistoryModel(Profile* profile, const std::wstring& search_text) | 16 HistoryModel::HistoryModel(Profile* profile, const std::wstring& search_text) |
17 : BaseHistoryModel(profile), | 17 : BaseHistoryModel(profile), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const GURL& HistoryModel::GetURL(int index) { | 54 const GURL& HistoryModel::GetURL(int index) { |
55 return results_[index].url(); | 55 return results_[index].url(); |
56 } | 56 } |
57 | 57 |
58 history::URLID HistoryModel::GetURLID(int index) { | 58 history::URLID HistoryModel::GetURLID(int index) { |
59 return results_[index].id(); | 59 return results_[index].id(); |
60 } | 60 } |
61 | 61 |
62 bool HistoryModel::IsStarred(int index) { | 62 bool HistoryModel::IsStarred(int index) { |
63 if (star_state_[index] == UNKNOWN) { | 63 if (star_state_[index] == UNKNOWN) { |
64 bool is_starred = | 64 bool is_starred = profile_->GetBookmarkModel()->IsBookmarked(GetURL(index)); |
65 profile_->GetBookmarkBarModel()->IsBookmarked(GetURL(index)); | |
66 star_state_[index] = is_starred ? STARRED : NOT_STARRED; | 65 star_state_[index] = is_starred ? STARRED : NOT_STARRED; |
67 } | 66 } |
68 return (star_state_[index] == STARRED); | 67 return (star_state_[index] == STARRED); |
69 } | 68 } |
70 | 69 |
71 const Snippet& HistoryModel::GetSnippet(int index) { | 70 const Snippet& HistoryModel::GetSnippet(int index) { |
72 return results_[index].snippet(); | 71 return results_[index].snippet(); |
73 } | 72 } |
74 | 73 |
75 void HistoryModel::RemoveFromModel(int start, int length) { | 74 void HistoryModel::RemoveFromModel(int start, int length) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 163 } |
165 | 164 |
166 void HistoryModel::SetPageStarred(int index, bool state) { | 165 void HistoryModel::SetPageStarred(int index, bool state) { |
167 const history::URLResult& result = results_[index]; | 166 const history::URLResult& result = results_[index]; |
168 if (!UpdateStarredStateOfURL(result.url(), state)) | 167 if (!UpdateStarredStateOfURL(result.url(), state)) |
169 return; // Nothing was changed. | 168 return; // Nothing was changed. |
170 | 169 |
171 if (observer_) | 170 if (observer_) |
172 observer_->ModelChanged(false); | 171 observer_->ModelChanged(false); |
173 | 172 |
174 BookmarkBarModel* bb_model = profile_->GetBookmarkBarModel(); | 173 BookmarkModel* bb_model = profile_->GetBookmarkModel(); |
175 if (bb_model) | 174 if (bb_model) |
176 bb_model->SetURLStarred(result.url(), result.title(), state); | 175 bb_model->SetURLStarred(result.url(), result.title(), state); |
177 } | 176 } |
178 | 177 |
179 void HistoryModel::Refresh() { | 178 void HistoryModel::Refresh() { |
180 cancelable_consumer_.CancelAllRequests(); | 179 cancelable_consumer_.CancelAllRequests(); |
181 if (observer_) | 180 if (observer_) |
182 observer_->ModelEndWork(); | 181 observer_->ModelEndWork(); |
183 search_depth_ = 0; | 182 search_depth_ = 0; |
184 InitVisitRequest(search_depth_); | 183 InitVisitRequest(search_depth_); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 size_t num_matches; | 279 size_t num_matches; |
281 const size_t* match_indices = results_.MatchesForURL(url, &num_matches); | 280 const size_t* match_indices = results_.MatchesForURL(url, &num_matches); |
282 for (size_t i = 0; i < num_matches; i++) { | 281 for (size_t i = 0; i < num_matches; i++) { |
283 if (IsStarred(static_cast<int>(match_indices[i])) != is_starred) { | 282 if (IsStarred(static_cast<int>(match_indices[i])) != is_starred) { |
284 star_state_[match_indices[i]] = is_starred ? STARRED : NOT_STARRED; | 283 star_state_[match_indices[i]] = is_starred ? STARRED : NOT_STARRED; |
285 changed = true; | 284 changed = true; |
286 } | 285 } |
287 } | 286 } |
288 return changed; | 287 return changed; |
289 } | 288 } |
OLD | NEW |