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

Side by Side Diff: components/password_manager/core/browser/affiliation_fetcher.cc

Issue 1065773006: Revert "Add experiment to exercise AffiliationService with dummy data, plus add related UMA histogr… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
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 "components/password_manager/core/browser/affiliation_fetcher.h" 5 #include "components/password_manager/core/browser/affiliation_fetcher.h"
6 6
7 #include "base/metrics/histogram_macros.h"
8 #include "base/metrics/sparse_histogram.h"
9 #include "components/password_manager/core/browser/affiliation_api.pb.h" 7 #include "components/password_manager/core/browser/affiliation_api.pb.h"
10 #include "components/password_manager/core/browser/affiliation_utils.h" 8 #include "components/password_manager/core/browser/affiliation_utils.h"
11 #include "components/password_manager/core/browser/test_affiliation_fetcher_fact ory.h" 9 #include "components/password_manager/core/browser/test_affiliation_fetcher_fact ory.h"
12 #include "google_apis/google_api_keys.h" 10 #include "google_apis/google_api_keys.h"
13 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
14 #include "net/base/url_util.h" 12 #include "net/base/url_util.h"
15 #include "net/http/http_status_code.h" 13 #include "net/http/http_status_code.h"
16 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
18 #include "url/gurl.h" 16 #include "url/gurl.h"
19 17
20 namespace password_manager { 18 namespace password_manager {
21 19
22 namespace {
23
24 // Enumeration listing the possible outcomes of fetching affiliation information
25 // from the Affiliation API. This is used in UMA histograms, so do not change
26 // existing values, only add new values at the end.
27 enum AffiliationFetchResult {
28 AFFILIATION_FETCH_RESULT_SUCCESS,
29 AFFILIATION_FETCH_RESULT_FAILURE,
30 AFFILIATION_FETCH_RESULT_MALFORMED,
31 AFFILIATION_FETCH_RESULT_MAX
32 };
33
34 // Records the given fetch |result| into the respective UMA histogram, as well
35 // as the response and error codes of |fetcher| if it is non-null.
36 void ReportStatistics(AffiliationFetchResult result,
37 const net::URLFetcher* fetcher) {
38 UMA_HISTOGRAM_ENUMERATION("PasswordManager.AffiliationFetcher.FetchResult",
39 result, AFFILIATION_FETCH_RESULT_MAX);
40 if (fetcher) {
41 UMA_HISTOGRAM_SPARSE_SLOWLY(
42 "PasswordManager.AffiliationFetcher.FetchHttpResponseCode",
43 fetcher->GetResponseCode());
44 // Network error codes are negative. See: src/net/base/net_error_list.h.
45 UMA_HISTOGRAM_SPARSE_SLOWLY(
46 "PasswordManager.AffiliationFetcher.FetchErrorCode",
47 -fetcher->GetStatus().error());
48 }
49 }
50
51 } // namespace
52
53 static TestAffiliationFetcherFactory* g_testing_factory = nullptr; 20 static TestAffiliationFetcherFactory* g_testing_factory = nullptr;
54 21
55 AffiliationFetcher::AffiliationFetcher( 22 AffiliationFetcher::AffiliationFetcher(
56 net::URLRequestContextGetter* request_context_getter, 23 net::URLRequestContextGetter* request_context_getter,
57 const std::vector<FacetURI>& facet_uris, 24 const std::vector<FacetURI>& facet_uris,
58 AffiliationFetcherDelegate* delegate) 25 AffiliationFetcherDelegate* delegate)
59 : request_context_getter_(request_context_getter), 26 : request_context_getter_(request_context_getter),
60 requested_facet_uris_(facet_uris), 27 requested_facet_uris_(facet_uris),
61 delegate_(delegate) { 28 delegate_(delegate) {
62 for (const FacetURI& uri : requested_facet_uris_) { 29 for (const FacetURI& uri : requested_facet_uris_) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (!facet_uri_to_class_index.count(uri)) 154 if (!facet_uri_to_class_index.count(uri))
188 result->push_back(AffiliatedFacets(1, uri)); 155 result->push_back(AffiliatedFacets(1, uri));
189 } 156 }
190 157
191 return true; 158 return true;
192 } 159 }
193 160
194 void AffiliationFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 161 void AffiliationFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
195 DCHECK_EQ(source, fetcher_.get()); 162 DCHECK_EQ(source, fetcher_.get());
196 163
197 // Note that invoking the |delegate_| may destroy |this| synchronously, so the 164 scoped_ptr<AffiliationFetcherDelegate::Result> result(
198 // invocation must happen last.
199 scoped_ptr<AffiliationFetcherDelegate::Result> result_data(
200 new AffiliationFetcherDelegate::Result); 165 new AffiliationFetcherDelegate::Result);
201 if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS && 166 if (fetcher_->GetStatus().status() == net::URLRequestStatus::SUCCESS &&
202 fetcher_->GetResponseCode() == net::HTTP_OK) { 167 fetcher_->GetResponseCode() == net::HTTP_OK) {
203 if (ParseResponse(result_data.get())) { 168 if (ParseResponse(result.get()))
204 ReportStatistics(AFFILIATION_FETCH_RESULT_SUCCESS, nullptr); 169 delegate_->OnFetchSucceeded(result.Pass());
205 delegate_->OnFetchSucceeded(result_data.Pass()); 170 else
206 } else {
207 ReportStatistics(AFFILIATION_FETCH_RESULT_MALFORMED, nullptr);
208 delegate_->OnMalformedResponse(); 171 delegate_->OnMalformedResponse();
209 }
210 } else { 172 } else {
211 ReportStatistics(AFFILIATION_FETCH_RESULT_FAILURE, fetcher_.get());
212 delegate_->OnFetchFailed(); 173 delegate_->OnFetchFailed();
213 } 174 }
214 } 175 }
215 176
216 } // namespace password_manager 177 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698