OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/search/suggestions/suggestions_service.h" | 5 #include "chrome/browser/search/suggestions/suggestions_service.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 << GetExperimentParam(kSuggestionsFieldTrialCommonParamsParam) << "&" | 112 << GetExperimentParam(kSuggestionsFieldTrialCommonParamsParam) << "&" |
113 << GetExperimentParam(kSuggestionsFieldTrialBlacklistUrlParam) << "="; | 113 << GetExperimentParam(kSuggestionsFieldTrialBlacklistUrlParam) << "="; |
114 return blacklist_url_prefix_stream.str(); | 114 return blacklist_url_prefix_stream.str(); |
115 } | 115 } |
116 | 116 |
117 } // namespace | 117 } // namespace |
118 | 118 |
119 SuggestionsService::SuggestionsService( | 119 SuggestionsService::SuggestionsService( |
120 net::URLRequestContextGetter* url_request_context, | 120 net::URLRequestContextGetter* url_request_context, |
121 scoped_ptr<SuggestionsStore> suggestions_store, | 121 scoped_ptr<SuggestionsStore> suggestions_store, |
122 scoped_ptr<ThumbnailManager> thumbnail_manager, | 122 scoped_ptr<ImageManager> thumbnail_manager, |
123 scoped_ptr<BlacklistStore> blacklist_store) | 123 scoped_ptr<BlacklistStore> blacklist_store) |
124 : suggestions_store_(suggestions_store.Pass()), | 124 : suggestions_store_(suggestions_store.Pass()), |
125 blacklist_store_(blacklist_store.Pass()), | 125 blacklist_store_(blacklist_store.Pass()), |
126 thumbnail_manager_(thumbnail_manager.Pass()), | 126 thumbnail_manager_(thumbnail_manager.Pass()), |
127 url_request_context_(url_request_context), | 127 url_request_context_(url_request_context), |
128 blacklist_delay_sec_(kBlacklistDefaultDelaySec), | 128 blacklist_delay_sec_(kBlacklistDefaultDelaySec), |
129 weak_ptr_factory_(this), | 129 weak_ptr_factory_(this), |
130 request_timeout_ms_(kDefaultRequestTimeoutMs) { | 130 request_timeout_ms_(kDefaultRequestTimeoutMs) { |
131 // Obtain various parameters from Variations. | 131 // Obtain various parameters from Variations. |
132 suggestions_url_ = | 132 suggestions_url_ = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 // Form new request. | 181 // Form new request. |
182 DCHECK(waiting_requestors_.empty()); | 182 DCHECK(waiting_requestors_.empty()); |
183 waiting_requestors_.push_back(callback); | 183 waiting_requestors_.push_back(callback); |
184 IssueRequest(suggestions_url_); | 184 IssueRequest(suggestions_url_); |
185 } | 185 } |
186 | 186 |
187 void SuggestionsService::GetPageThumbnail( | 187 void SuggestionsService::GetPageThumbnail( |
188 const GURL& url, | 188 const GURL& url, |
189 base::Callback<void(const GURL&, const SkBitmap*)> callback) { | 189 base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
190 thumbnail_manager_->GetPageThumbnail(url, callback); | 190 thumbnail_manager_->GetImageForURL(url, callback); |
191 } | 191 } |
192 | 192 |
193 void SuggestionsService::BlacklistURL( | 193 void SuggestionsService::BlacklistURL( |
194 const GURL& candidate_url, | 194 const GURL& candidate_url, |
195 const SuggestionsService::ResponseCallback& callback) { | 195 const SuggestionsService::ResponseCallback& callback) { |
196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
197 waiting_requestors_.push_back(callback); | 197 waiting_requestors_.push_back(callback); |
198 | 198 |
199 // Blacklist locally, for immediate effect. | 199 // Blacklist locally, for immediate effect. |
200 if (!blacklist_store_->BlacklistUrl(candidate_url)) { | 200 if (!blacklist_store_->BlacklistUrl(candidate_url)) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 DCHECK(success); | 308 DCHECK(success); |
309 | 309 |
310 // Compute suggestions, and dispatch then to requestors. On error still | 310 // Compute suggestions, and dispatch then to requestors. On error still |
311 // dispatch empty suggestions. | 311 // dispatch empty suggestions. |
312 SuggestionsProfile suggestions; | 312 SuggestionsProfile suggestions; |
313 if (suggestions_data.empty()) { | 313 if (suggestions_data.empty()) { |
314 LogResponseState(RESPONSE_EMPTY); | 314 LogResponseState(RESPONSE_EMPTY); |
315 suggestions_store_->ClearSuggestions(); | 315 suggestions_store_->ClearSuggestions(); |
316 } else if (suggestions.ParseFromString(suggestions_data)) { | 316 } else if (suggestions.ParseFromString(suggestions_data)) { |
317 LogResponseState(RESPONSE_VALID); | 317 LogResponseState(RESPONSE_VALID); |
318 thumbnail_manager_->InitializeThumbnailMap(suggestions); | 318 thumbnail_manager_->Initialize(suggestions); |
319 suggestions_store_->StoreSuggestions(suggestions); | 319 suggestions_store_->StoreSuggestions(suggestions); |
320 } else { | 320 } else { |
321 LogResponseState(RESPONSE_INVALID); | 321 LogResponseState(RESPONSE_INVALID); |
322 suggestions_store_->LoadSuggestions(&suggestions); | 322 suggestions_store_->LoadSuggestions(&suggestions); |
323 } | 323 } |
324 | 324 |
325 FilterAndServe(&suggestions); | 325 FilterAndServe(&suggestions); |
326 ScheduleBlacklistUpload(true); | 326 ScheduleBlacklistUpload(true); |
327 } | 327 } |
328 | 328 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 if (last_request_successful) { | 382 if (last_request_successful) { |
383 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; | 383 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |
384 } else { | 384 } else { |
385 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; | 385 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; |
386 if (candidate_delay < kBlacklistMaxDelaySec) | 386 if (candidate_delay < kBlacklistMaxDelaySec) |
387 blacklist_delay_sec_ = candidate_delay; | 387 blacklist_delay_sec_ = candidate_delay; |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 } // namespace suggestions | 391 } // namespace suggestions |
OLD | NEW |