| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const int kDefaultRequestTimeoutMs = 200; | 72 const int kDefaultRequestTimeoutMs = 200; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; | 76 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; |
| 77 const char kSuggestionsFieldTrialURLParam[] = "url"; | 77 const char kSuggestionsFieldTrialURLParam[] = "url"; |
| 78 const char kSuggestionsFieldTrialSuggestionsSuffixParam[] = | 78 const char kSuggestionsFieldTrialSuggestionsSuffixParam[] = |
| 79 "suggestions_suffix"; | 79 "suggestions_suffix"; |
| 80 const char kSuggestionsFieldTrialBlacklistSuffixParam[] = "blacklist_suffix"; | 80 const char kSuggestionsFieldTrialBlacklistSuffixParam[] = "blacklist_suffix"; |
| 81 const char kSuggestionsFieldTrialStateParam[] = "state"; | 81 const char kSuggestionsFieldTrialStateParam[] = "state"; |
| 82 const char kSuggestionsFieldTrialControlParam[] = "control"; |
| 82 const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; | 83 const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; |
| 83 const char kSuggestionsFieldTrialTimeoutMs[] = "timeout_ms"; | 84 const char kSuggestionsFieldTrialTimeoutMs[] = "timeout_ms"; |
| 84 | 85 |
| 85 SuggestionsService::SuggestionsService( | 86 SuggestionsService::SuggestionsService( |
| 86 Profile* profile, scoped_ptr<SuggestionsStore> suggestions_store) | 87 Profile* profile, scoped_ptr<SuggestionsStore> suggestions_store) |
| 87 : suggestions_store_(suggestions_store.Pass()), | 88 : suggestions_store_(suggestions_store.Pass()), |
| 88 thumbnail_manager_(new ThumbnailManager(profile)), | 89 thumbnail_manager_(new ThumbnailManager(profile)), |
| 89 profile_(profile), | 90 profile_(profile), |
| 90 weak_ptr_factory_(this), | 91 weak_ptr_factory_(this), |
| 91 request_timeout_ms_(kDefaultRequestTimeoutMs) { | 92 request_timeout_ms_(kDefaultRequestTimeoutMs) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 } | 105 } |
| 105 | 106 |
| 106 SuggestionsService::~SuggestionsService() {} | 107 SuggestionsService::~SuggestionsService() {} |
| 107 | 108 |
| 108 // static | 109 // static |
| 109 bool SuggestionsService::IsEnabled() { | 110 bool SuggestionsService::IsEnabled() { |
| 110 return GetExperimentParam(kSuggestionsFieldTrialStateParam) == | 111 return GetExperimentParam(kSuggestionsFieldTrialStateParam) == |
| 111 kSuggestionsFieldTrialStateEnabled; | 112 kSuggestionsFieldTrialStateEnabled; |
| 112 } | 113 } |
| 113 | 114 |
| 115 // static |
| 116 bool SuggestionsService::IsControlGroup() { |
| 117 return GetExperimentParam(kSuggestionsFieldTrialControlParam) == |
| 118 kSuggestionsFieldTrialStateEnabled; |
| 119 } |
| 120 |
| 114 void SuggestionsService::FetchSuggestionsData( | 121 void SuggestionsService::FetchSuggestionsData( |
| 115 SuggestionsService::ResponseCallback callback) { | 122 SuggestionsService::ResponseCallback callback) { |
| 116 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 117 | 124 |
| 118 FetchSuggestionsDataNoTimeout(callback); | 125 FetchSuggestionsDataNoTimeout(callback); |
| 119 | 126 |
| 120 // Post a task to serve the cached suggestions if the request hasn't completed | 127 // Post a task to serve the cached suggestions if the request hasn't completed |
| 121 // after some time. Cancels the previous such task, if one existed. | 128 // after some time. Cancels the previous such task, if one existed. |
| 122 pending_timeout_closure_.reset(new CancelableClosure(base::Bind( | 129 pending_timeout_closure_.reset(new CancelableClosure(base::Bind( |
| 123 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); | 130 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 return request; | 282 return request; |
| 276 } | 283 } |
| 277 | 284 |
| 278 void SuggestionsService::ServeFromCache() { | 285 void SuggestionsService::ServeFromCache() { |
| 279 SuggestionsProfile suggestions; | 286 SuggestionsProfile suggestions; |
| 280 suggestions_store_->LoadSuggestions(&suggestions); | 287 suggestions_store_->LoadSuggestions(&suggestions); |
| 281 DispatchRequestsAndClear(suggestions, &waiting_requestors_); | 288 DispatchRequestsAndClear(suggestions, &waiting_requestors_); |
| 282 } | 289 } |
| 283 | 290 |
| 284 } // namespace suggestions | 291 } // namespace suggestions |
| OLD | NEW |