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

Side by Side Diff: chrome/browser/search/suggestions/suggestions_service.cc

Issue 299713007: [Suggestions] Adding a Thumbnail Manager for the Suggestions Service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now swapping Created 6 years, 7 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 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; 65 const char kSuggestionsFieldTrialName[] = "ChromeSuggestions";
66 const char kSuggestionsFieldTrialURLParam[] = "url"; 66 const char kSuggestionsFieldTrialURLParam[] = "url";
67 const char kSuggestionsFieldTrialStateParam[] = "state"; 67 const char kSuggestionsFieldTrialStateParam[] = "state";
68 const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; 68 const char kSuggestionsFieldTrialStateEnabled[] = "enabled";
69 69
70 SuggestionsService::SuggestionsService(Profile* profile) 70 SuggestionsService::SuggestionsService(Profile* profile)
71 : profile_(profile) { 71 : thumbnail_manager_(new ThumbnailManager(profile)),
72 profile_(profile) {
72 // Obtain the URL to use to fetch suggestions data from the Variations param. 73 // Obtain the URL to use to fetch suggestions data from the Variations param.
73 suggestions_url_ = GURL(GetExperimentParam(kSuggestionsFieldTrialURLParam)); 74 suggestions_url_ = GURL(GetExperimentParam(kSuggestionsFieldTrialURLParam));
74 } 75 }
75 76
76 SuggestionsService::~SuggestionsService() { 77 SuggestionsService::~SuggestionsService() {
77 } 78 }
78 79
79 // static 80 // static
80 bool SuggestionsService::IsEnabled() { 81 bool SuggestionsService::IsEnabled() {
81 return GetExperimentParam(kSuggestionsFieldTrialStateParam) == 82 return GetExperimentParam(kSuggestionsFieldTrialStateParam) ==
(...skipping 22 matching lines...) Expand all
104 net::HttpRequestHeaders headers; 105 net::HttpRequestHeaders headers;
105 chrome_variations::VariationsHttpHeaderProvider::GetInstance()-> 106 chrome_variations::VariationsHttpHeaderProvider::GetInstance()->
106 AppendHeaders(pending_request_->GetOriginalURL(), 107 AppendHeaders(pending_request_->GetOriginalURL(),
107 profile_->IsOffTheRecord(), false, &headers); 108 profile_->IsOffTheRecord(), false, &headers);
108 pending_request_->SetExtraRequestHeaders(headers.ToString()); 109 pending_request_->SetExtraRequestHeaders(headers.ToString());
109 pending_request_->Start(); 110 pending_request_->Start();
110 111
111 last_request_started_time_ = base::TimeTicks::Now(); 112 last_request_started_time_ = base::TimeTicks::Now();
112 } 113 }
113 114
115 void SuggestionsService::GetPageThumbnail(
116 const GURL& url,
117 base::Callback<void(const GURL&, const SkBitmap*)> callback) {
118 thumbnail_manager_->GetPageThumbnail(url, callback);
119 }
120
114 void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { 121 void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
116 DCHECK_EQ(pending_request_.get(), source); 123 DCHECK_EQ(pending_request_.get(), source);
117 124
118 // The fetcher will be deleted when the request is handled. 125 // The fetcher will be deleted when the request is handled.
119 scoped_ptr<const net::URLFetcher> request(pending_request_.release()); 126 scoped_ptr<const net::URLFetcher> request(pending_request_.release());
120 const net::URLRequestStatus& request_status = request->GetStatus(); 127 const net::URLRequestStatus& request_status = request->GetStatus();
121 if (request_status.status() != net::URLRequestStatus::SUCCESS) { 128 if (request_status.status() != net::URLRequestStatus::SUCCESS) {
122 UMA_HISTOGRAM_SPARSE_SLOWLY("Suggestions.FailedRequestErrorCode", 129 UMA_HISTOGRAM_SPARSE_SLOWLY("Suggestions.FailedRequestErrorCode",
123 -request_status.error()); 130 -request_status.error());
(...skipping 23 matching lines...) Expand all
147 bool success = request->GetResponseAsString(&suggestions_data); 154 bool success = request->GetResponseAsString(&suggestions_data);
148 DCHECK(success); 155 DCHECK(success);
149 156
150 // Compute suggestions, and dispatch then to requestors. On error still 157 // Compute suggestions, and dispatch then to requestors. On error still
151 // dispatch empty suggestions. 158 // dispatch empty suggestions.
152 SuggestionsProfile suggestions; 159 SuggestionsProfile suggestions;
153 if (suggestions_data.empty()) { 160 if (suggestions_data.empty()) {
154 LogResponseState(RESPONSE_EMPTY); 161 LogResponseState(RESPONSE_EMPTY);
155 } else if (suggestions.ParseFromString(suggestions_data)) { 162 } else if (suggestions.ParseFromString(suggestions_data)) {
156 LogResponseState(RESPONSE_VALID); 163 LogResponseState(RESPONSE_VALID);
164 thumbnail_manager_->InitializeThumbnailMap(suggestions);
157 } else { 165 } else {
158 LogResponseState(RESPONSE_INVALID); 166 LogResponseState(RESPONSE_INVALID);
159 } 167 }
160 168
161 DispatchRequestsAndClear(suggestions, &waiting_requestors_); 169 DispatchRequestsAndClear(suggestions, &waiting_requestors_);
162 } 170 }
163 171
164 void SuggestionsService::Shutdown() { 172 void SuggestionsService::Shutdown() {
165 // Cancel pending request. 173 // Cancel pending request.
166 pending_request_.reset(NULL); 174 pending_request_.reset(NULL);
167 175
168 // Dispatch empty suggestions to requestors. 176 // Dispatch empty suggestions to requestors.
169 DispatchRequestsAndClear(SuggestionsProfile(), &waiting_requestors_); 177 DispatchRequestsAndClear(SuggestionsProfile(), &waiting_requestors_);
170 } 178 }
171 179
172 } // namespace suggestions 180 } // namespace suggestions
OLDNEW
« no previous file with comments | « chrome/browser/search/suggestions/suggestions_service.h ('k') | chrome/browser/search/suggestions/thumbnail_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698