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

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: Fix missing virtual and wrong type in CreateInstance(). 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_fetcher_factory.h "
8 #include "components/password_manager/core/browser/affiliation_utils.h" 9 #include "components/password_manager/core/browser/affiliation_utils.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 AffiliationFetcherFactory* g_factory = nullptr;
vabr (Chromium) 2015/01/22 14:27:04 I suggest renaming to g_testing_factory, to emphas
engedy 2015/01/22 14:41:14 Done.
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_factory)
43 return g_factory->CreateInstance(context_getter, facet_uris, delegate);
39 return new AffiliationFetcher(context_getter, facet_uris, delegate); 44 return new AffiliationFetcher(context_getter, facet_uris, delegate);
40 } 45 }
41 46
47 // static
48 void AffiliationFetcher::SetFactoryForTesting(
49 AffiliationFetcherFactory* factory) {
50 g_factory = factory;
51 }
52
42 void AffiliationFetcher::StartRequest() { 53 void AffiliationFetcher::StartRequest() {
43 DCHECK(!fetcher_); 54 DCHECK(!fetcher_);
44 55
45 fetcher_.reset( 56 fetcher_.reset(
46 net::URLFetcher::Create(BuildQueryURL(), net::URLFetcher::POST, this)); 57 net::URLFetcher::Create(BuildQueryURL(), net::URLFetcher::POST, this));
47 fetcher_->SetRequestContext(request_context_getter_.get()); 58 fetcher_->SetRequestContext(request_context_getter_.get());
48 fetcher_->SetUploadData("application/x-protobuf", PreparePayload()); 59 fetcher_->SetUploadData("application/x-protobuf", PreparePayload());
49 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 60 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
50 net::LOAD_DO_NOT_SEND_COOKIES | 61 net::LOAD_DO_NOT_SEND_COOKIES |
51 net::LOAD_DO_NOT_SEND_AUTH_DATA | 62 net::LOAD_DO_NOT_SEND_AUTH_DATA |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (ParseResponse(result.get())) 166 if (ParseResponse(result.get()))
156 delegate_->OnFetchSucceeded(result.Pass()); 167 delegate_->OnFetchSucceeded(result.Pass());
157 else 168 else
158 delegate_->OnMalformedResponse(); 169 delegate_->OnMalformedResponse();
159 } else { 170 } else {
160 delegate_->OnFetchFailed(); 171 delegate_->OnFetchFailed();
161 } 172 }
162 } 173 }
163 174
164 } // namespace password_manager 175 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698