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/autocomplete/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using base::TimeTicks; | 29 using base::TimeTicks; |
30 | 30 |
31 HistoryURLProviderParams::HistoryURLProviderParams( | 31 HistoryURLProviderParams::HistoryURLProviderParams( |
32 const AutocompleteInput& input, | 32 const AutocompleteInput& input, |
33 bool trim_http, | 33 bool trim_http, |
34 const std::wstring& languages) | 34 const std::wstring& languages) |
35 : message_loop(MessageLoop::current()), | 35 : message_loop(MessageLoop::current()), |
36 input(input), | 36 input(input), |
37 trim_http(trim_http), | 37 trim_http(trim_http), |
38 cancel(false), | 38 cancel(false), |
| 39 failed(false), |
39 languages(languages) { | 40 languages(languages) { |
40 } | 41 } |
41 | 42 |
42 void HistoryURLProvider::Start(const AutocompleteInput& input, | 43 void HistoryURLProvider::Start(const AutocompleteInput& input, |
43 bool minimal_changes) { | 44 bool minimal_changes) { |
44 // NOTE: We could try hard to do less work in the |minimal_changes| case | 45 // NOTE: We could try hard to do less work in the |minimal_changes| case |
45 // here; some clever caching would let us reuse the raw matches from the | 46 // here; some clever caching would let us reuse the raw matches from the |
46 // history DB without re-querying. However, we'd still have to go back to | 47 // history DB without re-querying. However, we'd still have to go back to |
47 // the history thread to mark these up properly, and if pass 2 is currently | 48 // the history thread to mark these up properly, and if pass 2 is currently |
48 // running, we'd need to wait for it to return to the main thread before | 49 // running, we'd need to wait for it to return to the main thread before |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 97 } |
97 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | 98 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; |
98 listener_->OnProviderUpdate(true); | 99 listener_->OnProviderUpdate(true); |
99 } | 100 } |
100 | 101 |
101 // Called on the history thread. | 102 // Called on the history thread. |
102 void HistoryURLProvider::ExecuteWithDB(history::HistoryBackend* backend, | 103 void HistoryURLProvider::ExecuteWithDB(history::HistoryBackend* backend, |
103 history::URLDatabase* db, | 104 history::URLDatabase* db, |
104 HistoryURLProviderParams* params) { | 105 HistoryURLProviderParams* params) { |
105 // We may get called with a NULL database if it couldn't be properly | 106 // We may get called with a NULL database if it couldn't be properly |
106 // initialized. In this case we just say the query is complete. | 107 // initialized. |
107 if (db && !params->cancel) { | 108 if (!db) { |
| 109 params->failed = true; |
| 110 } else if (!params->cancel) { |
108 TimeTicks beginning_time = TimeTicks::Now(); | 111 TimeTicks beginning_time = TimeTicks::Now(); |
109 | 112 |
110 DoAutocomplete(backend, db, params); | 113 DoAutocomplete(backend, db, params); |
111 | 114 |
112 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime", | 115 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime", |
113 TimeTicks::Now() - beginning_time); | 116 TimeTicks::Now() - beginning_time); |
114 } | 117 } |
115 | 118 |
116 // Return the results (if any) to the main thread. | 119 // Return the results (if any) to the main thread. |
117 params->message_loop->PostTask(FROM_HERE, NewRunnableMethod( | 120 params->message_loop->PostTask(FROM_HERE, NewRunnableMethod( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 218 |
216 // If the user hasn't already started another query, clear our member pointer | 219 // If the user hasn't already started another query, clear our member pointer |
217 // so we can't write into deleted memory. | 220 // so we can't write into deleted memory. |
218 if (params_ == params_gets_deleted) | 221 if (params_ == params_gets_deleted) |
219 params_ = NULL; | 222 params_ = NULL; |
220 | 223 |
221 // Don't send responses for queries that have been canceled. | 224 // Don't send responses for queries that have been canceled. |
222 if (params->cancel) | 225 if (params->cancel) |
223 return; // Already set done_ when we canceled, no need to set it again. | 226 return; // Already set done_ when we canceled, no need to set it again. |
224 | 227 |
| 228 // Don't modify |matches_| if the query failed, since it might have a default |
| 229 // match in it, whereas |params->matches| will be empty. |
| 230 if (!params->failed) { |
| 231 matches_.swap(params->matches); |
| 232 UpdateStarredStateOfMatches(); |
| 233 } |
| 234 |
225 done_ = true; | 235 done_ = true; |
226 matches_.swap(params->matches); | |
227 UpdateStarredStateOfMatches(); | |
228 listener_->OnProviderUpdate(true); | 236 listener_->OnProviderUpdate(true); |
229 } | 237 } |
230 | 238 |
231 AutocompleteMatch HistoryURLProvider::SuggestExactInput( | 239 AutocompleteMatch HistoryURLProvider::SuggestExactInput( |
232 const AutocompleteInput& input, | 240 const AutocompleteInput& input, |
233 bool trim_http) { | 241 bool trim_http) { |
234 AutocompleteMatch match(this, | 242 AutocompleteMatch match(this, |
235 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, | 243 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, |
236 AutocompleteMatch::URL_WHAT_YOU_TYPED); | 244 AutocompleteMatch::URL_WHAT_YOU_TYPED); |
237 | 245 |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 history_match.input_location - offset, params->input.text().length(), | 837 history_match.input_location - offset, params->input.text().length(), |
830 match.contents.length(), ACMatchClassification::URL, | 838 match.contents.length(), ACMatchClassification::URL, |
831 &match.contents_class); | 839 &match.contents_class); |
832 match.description = info.title(); | 840 match.description = info.title(); |
833 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 841 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
834 ACMatchClassification::NONE, | 842 ACMatchClassification::NONE, |
835 &match.description_class); | 843 &match.description_class); |
836 | 844 |
837 return match; | 845 return match; |
838 } | 846 } |
OLD | NEW |