Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ | |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "components/password_manager/core/browser/affiliation_fetcher_delegate. h" | |
| 13 #include "components/password_manager/core/browser/affiliation_utils.h" | |
| 14 #include "net/url_request/url_fetcher_delegate.h" | |
| 15 | |
| 16 class GURL; | |
| 17 | |
| 18 namespace net { | |
| 19 class URLRequestContextGetter; | |
| 20 } // namespace net | |
| 21 | |
| 22 namespace password_manager { | |
| 23 | |
| 24 // Fetches authoritative information regarding which facets are affiliated with | |
| 25 // each other, that is, which facets belong to the same logical application. | |
| 26 // See affiliation_utils.h for a definition of what this means. | |
| 27 // | |
| 28 // An instance is good for exactly one fetch, and may be used from any thread, | |
|
Randy Smith (Not in Mondays)
2014/12/10 22:13:24
Strictly speaking, not any thread; the URLFetcher
engedy
2014/12/11 20:49:24
Rephrased, but I did not want to be overly verbose
Randy Smith (Not in Mondays)
2014/12/11 20:54:35
I'd prefer you just said "and may be used from any
engedy
2014/12/12 14:06:12
Sounds good, thanks for the proposal. Done.
| |
| 29 // but is not thread-safe. | |
| 30 class AffiliationFetcher : net::URLFetcherDelegate { | |
| 31 public: | |
| 32 ~AffiliationFetcher() override; | |
| 33 | |
| 34 // Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| | |
| 35 // using the specified |request_context_getter|, and will provide the results | |
| 36 // to the |delegate| on the same thread that creates the instance. | |
| 37 static AffiliationFetcher* Create( | |
|
Garrett Casto
2014/12/11 08:18:39
Out of curiosity, any particular reason for the fa
engedy
2014/12/11 20:49:24
I am going to add a way to insert a custom factory
| |
| 38 net::URLRequestContextGetter* request_context_getter, | |
| 39 const std::vector<FacetURI>& facet_uris, | |
| 40 AffiliationFetcherDelegate* delegate); | |
| 41 | |
| 42 // Actually starts the request, and will call the delegate with the results on | |
| 43 // the same thread when done. If |this| is destroyed before completion, the | |
| 44 // in-flight request is cancelled, and the delegate will not be called. | |
| 45 // Further details: | |
| 46 // * No cookies are sent/saved with the request. | |
| 47 // * In case of network/server errors, the request will not be retried. | |
| 48 // * Results are guaranteed to be always fresh and will never be cached. | |
| 49 virtual void StartRequest(); | |
| 50 | |
| 51 const std::vector<FacetURI>& requested_facet_uris() const { | |
| 52 return requested_facet_uris_; | |
| 53 } | |
| 54 | |
| 55 AffiliationFetcherDelegate* delegate() const { return delegate_; } | |
| 56 | |
| 57 protected: | |
| 58 AffiliationFetcher(net::URLRequestContextGetter* request_context_getter, | |
| 59 const std::vector<FacetURI>& facet_uris, | |
| 60 AffiliationFetcherDelegate* delegate); | |
| 61 | |
| 62 private: | |
| 63 // Builds the URL for the affiliation API's lookup method. | |
| 64 GURL BuildQueryURL() const; | |
| 65 | |
| 66 // Prepares and returns the serialized form of the JSON dictionary that will | |
| 67 // be the payload of the POST request. | |
| 68 std::string PreparePayload() const; | |
| 69 | |
| 70 // Parses the server response into |result| and returns true on success. We | |
| 71 // gracefully ignore most unknown fields in the response, so this method will | |
| 72 // return false only if the response is gravely ill-formed. | |
| 73 bool ParseResponse(AffiliationFetcherDelegate::Result* result) const; | |
| 74 | |
| 75 // net::URLFetcherDelegate: | |
| 76 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 77 | |
| 78 const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 79 const std::vector<FacetURI> requested_facet_uris_; | |
| 80 AffiliationFetcherDelegate* const delegate_; | |
| 81 | |
| 82 scoped_ptr<net::URLFetcher> fetcher_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(AffiliationFetcher); | |
| 85 }; | |
| 86 | |
| 87 } // namespace password_manager | |
| 88 | |
| 89 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ | |
| OLD | NEW |