Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1142)

Side by Side Diff: chrome/browser/history/history_types.cc

Issue 43054: Stop history search going on beyond the start of history.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <limits> 5 #include <limits>
6 6
7 #include "chrome/browser/history/history_types.h" 7 #include "chrome/browser/history/history_types.h"
8 8
9 using base::Time; 9 using base::Time;
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 void URLResult::Swap(URLResult* other) { 86 void URLResult::Swap(URLResult* other) {
87 URLRow::Swap(other); 87 URLRow::Swap(other);
88 std::swap(visit_time_, other->visit_time_); 88 std::swap(visit_time_, other->visit_time_);
89 snippet_.Swap(&other->snippet_); 89 snippet_.Swap(&other->snippet_);
90 title_match_positions_.swap(other->title_match_positions_); 90 title_match_positions_.swap(other->title_match_positions_);
91 } 91 }
92 92
93 // QueryResults ---------------------------------------------------------------- 93 // QueryResults ----------------------------------------------------------------
94 94
95 QueryResults::QueryResults() { 95 QueryResults::QueryResults() : reached_beginning_(false) {
96 } 96 }
97 97
98 QueryResults::~QueryResults() { 98 QueryResults::~QueryResults() {
99 // Free all the URL objects. 99 // Free all the URL objects.
100 STLDeleteContainerPointers(results_.begin(), results_.end()); 100 STLDeleteContainerPointers(results_.begin(), results_.end());
101 } 101 }
102 102
103 const size_t* QueryResults::MatchesForURL(const GURL& url, 103 const size_t* QueryResults::MatchesForURL(const GURL& url,
104 size_t* num_matches) const { 104 size_t* num_matches) const {
105 URLToResultIndices::const_iterator found = url_to_results_.find(url); 105 URLToResultIndices::const_iterator found = url_to_results_.find(url);
106 if (found == url_to_results_.end()) { 106 if (found == url_to_results_.end()) {
107 if (num_matches) 107 if (num_matches)
108 *num_matches = 0; 108 *num_matches = 0;
109 return NULL; 109 return NULL;
110 } 110 }
111 111
112 // All entries in the map should have at least one index, otherwise it 112 // All entries in the map should have at least one index, otherwise it
113 // shouldn't be in the map. 113 // shouldn't be in the map.
114 DCHECK(found->second->size() > 0); 114 DCHECK(found->second->size() > 0);
115 if (num_matches) 115 if (num_matches)
116 *num_matches = found->second->size(); 116 *num_matches = found->second->size();
117 return &found->second->front(); 117 return &found->second->front();
118 } 118 }
119 119
120 void QueryResults::Swap(QueryResults* other) { 120 void QueryResults::Swap(QueryResults* other) {
121 std::swap(first_time_searched_, other->first_time_searched_); 121 std::swap(first_time_searched_, other->first_time_searched_);
122 std::swap(reached_beginning_, other->reached_beginning_);
122 results_.swap(other->results_); 123 results_.swap(other->results_);
123 url_to_results_.swap(other->url_to_results_); 124 url_to_results_.swap(other->url_to_results_);
124 } 125 }
125 126
126 void QueryResults::AppendURLBySwapping(URLResult* result) { 127 void QueryResults::AppendURLBySwapping(URLResult* result) {
127 URLResult* new_result = new URLResult; 128 URLResult* new_result = new URLResult;
128 new_result->Swap(result); 129 new_result->Swap(result);
129 130
130 results_.push_back(new_result); 131 results_.push_back(new_result);
131 AddURLUsageAtIndex(new_result->url(), results_.size() - 1); 132 AddURLUsageAtIndex(new_result->url(), results_.size() - 1);
132 } 133 }
133 134
134 void QueryResults::AppendResultsBySwapping(QueryResults* other, 135 void QueryResults::AppendResultsBySwapping(QueryResults* other,
135 bool remove_dupes) { 136 bool remove_dupes) {
136 if (remove_dupes) { 137 if (remove_dupes) {
137 // Delete all entries in the other array that are already in this one. 138 // Delete all entries in the other array that are already in this one.
138 for (size_t i = 0; i < results_.size(); i++) 139 for (size_t i = 0; i < results_.size(); i++)
139 other->DeleteURL(results_[i]->url()); 140 other->DeleteURL(results_[i]->url());
140 } 141 }
141 142
142 if (first_time_searched_ > other->first_time_searched_) 143 if (first_time_searched_ > other->first_time_searched_)
143 std::swap(first_time_searched_, other->first_time_searched_); 144 std::swap(first_time_searched_, other->first_time_searched_);
144 145
146 if (reached_beginning_ != other->reached_beginning_)
147 std::swap(reached_beginning_, other->reached_beginning_);
148
145 for (size_t i = 0; i < other->results_.size(); i++) { 149 for (size_t i = 0; i < other->results_.size(); i++) {
146 // Just transfer pointer ownership. 150 // Just transfer pointer ownership.
147 results_.push_back(other->results_[i]); 151 results_.push_back(other->results_[i]);
148 AddURLUsageAtIndex(results_.back()->url(), results_.size() - 1); 152 AddURLUsageAtIndex(results_.back()->url(), results_.size() - 1);
149 } 153 }
150 154
151 // We just took ownership of all the results in the input vector. 155 // We just took ownership of all the results in the input vector.
152 other->results_.clear(); 156 other->results_.clear();
153 other->url_to_results_.clear(); 157 other->url_to_results_.clear();
154 } 158 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 for (size_t match = 0; match < i->second->size(); match++) { 230 for (size_t match = 0; match < i->second->size(); match++) {
227 size_t match_index = i->second[match]; 231 size_t match_index = i->second[match];
228 if (match_index >= begin && match_index <= end) 232 if (match_index >= begin && match_index <= end)
229 i->second[match] += delta; 233 i->second[match] += delta;
230 } 234 }
231 } 235 }
232 } 236 }
233 237
234 } // namespace history 238 } // namespace history
235 239
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698