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

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

Issue 866733002: Add FakeAffiliationFetcher and factory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missing file. Created 5 years, 11 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 "components/password_manager/core/browser/affiliation_api.pb.h" 7 #include "components/password_manager/core/browser/affiliation_api.pb.h"
8 #include "components/password_manager/core/browser/affiliation_utils.h" 8 #include "components/password_manager/core/browser/affiliation_utils.h"
9 #include "components/password_manager/core/browser/test_affiliation_fetcher_fact ory.h"
9 #include "google_apis/google_api_keys.h" 10 #include "google_apis/google_api_keys.h"
10 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
11 #include "net/base/url_util.h" 12 #include "net/base/url_util.h"
12 #include "net/http/http_status_code.h" 13 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace password_manager { 18 namespace password_manager {
18 19
20 static TestAffiliationFetcherFactory* g_testing_factory = nullptr;
21
19 AffiliationFetcher::AffiliationFetcher( 22 AffiliationFetcher::AffiliationFetcher(
20 net::URLRequestContextGetter* request_context_getter, 23 net::URLRequestContextGetter* request_context_getter,
21 const std::vector<FacetURI>& facet_uris, 24 const std::vector<FacetURI>& facet_uris,
22 AffiliationFetcherDelegate* delegate) 25 AffiliationFetcherDelegate* delegate)
23 : request_context_getter_(request_context_getter), 26 : request_context_getter_(request_context_getter),
24 requested_facet_uris_(facet_uris), 27 requested_facet_uris_(facet_uris),
25 delegate_(delegate) { 28 delegate_(delegate) {
26 for (const FacetURI& uri : requested_facet_uris_) { 29 for (const FacetURI& uri : requested_facet_uris_) {
27 DCHECK(uri.is_valid()); 30 DCHECK(uri.is_valid());
28 } 31 }
29 } 32 }
30 33
31 AffiliationFetcher::~AffiliationFetcher() { 34 AffiliationFetcher::~AffiliationFetcher() {
32 } 35 }
33 36
34 // static 37 // static
35 AffiliationFetcher* AffiliationFetcher::Create( 38 AffiliationFetcher* AffiliationFetcher::Create(
36 net::URLRequestContextGetter* context_getter, 39 net::URLRequestContextGetter* context_getter,
37 const std::vector<FacetURI>& facet_uris, 40 const std::vector<FacetURI>& facet_uris,
38 AffiliationFetcherDelegate* delegate) { 41 AffiliationFetcherDelegate* delegate) {
42 if (g_testing_factory) {
43 return g_testing_factory->CreateInstance(context_getter, facet_uris,
44 delegate);
45 }
39 return new AffiliationFetcher(context_getter, facet_uris, delegate); 46 return new AffiliationFetcher(context_getter, facet_uris, delegate);
40 } 47 }
41 48
49 // static
50 void AffiliationFetcher::SetFactoryForTesting(
51 TestAffiliationFetcherFactory* factory) {
52 g_testing_factory = factory;
53 }
54
42 void AffiliationFetcher::StartRequest() { 55 void AffiliationFetcher::StartRequest() {
43 DCHECK(!fetcher_); 56 DCHECK(!fetcher_);
44 57
45 fetcher_.reset( 58 fetcher_.reset(
46 net::URLFetcher::Create(BuildQueryURL(), net::URLFetcher::POST, this)); 59 net::URLFetcher::Create(BuildQueryURL(), net::URLFetcher::POST, this));
47 fetcher_->SetRequestContext(request_context_getter_.get()); 60 fetcher_->SetRequestContext(request_context_getter_.get());
48 fetcher_->SetUploadData("application/x-protobuf", PreparePayload()); 61 fetcher_->SetUploadData("application/x-protobuf", PreparePayload());
49 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 62 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
50 net::LOAD_DO_NOT_SEND_COOKIES | 63 net::LOAD_DO_NOT_SEND_COOKIES |
51 net::LOAD_DO_NOT_SEND_AUTH_DATA | 64 net::LOAD_DO_NOT_SEND_AUTH_DATA |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (ParseResponse(result.get())) 168 if (ParseResponse(result.get()))
156 delegate_->OnFetchSucceeded(result.Pass()); 169 delegate_->OnFetchSucceeded(result.Pass());
157 else 170 else
158 delegate_->OnMalformedResponse(); 171 delegate_->OnMalformedResponse();
159 } else { 172 } else {
160 delegate_->OnFetchFailed(); 173 delegate_->OnFetchFailed();
161 } 174 }
162 } 175 }
163 176
164 } // namespace password_manager 177 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698