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 is not thread-safe. |
| 29 class AffiliationFetcher : net::URLFetcherDelegate { |
| 30 public: |
| 31 ~AffiliationFetcher() override; |
| 32 |
| 33 // Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| |
| 34 // using the specified |request_context_getter|, and will provide the results |
| 35 // to the |delegate| on the same thread that creates the instance. |
| 36 static AffiliationFetcher* Create( |
| 37 net::URLRequestContextGetter* request_context_getter, |
| 38 const std::vector<FacetURI>& facet_uris, |
| 39 AffiliationFetcherDelegate* delegate); |
| 40 |
| 41 // Actually starts the request, and will call the delegate with the results on |
| 42 // the same thread when done. If |this| is destroyed before completion, the |
| 43 // in-flight request is cancelled, and the delegate will not be called. |
| 44 // Further details: |
| 45 // * No cookies are sent/saved with the request. |
| 46 // * In case of network/server errors, the request will not be retried. |
| 47 // * Results are guaranteed to be always fresh and will never be cached. |
| 48 virtual void StartRequest(); |
| 49 |
| 50 const std::vector<FacetURI>& requested_facet_uris() const { |
| 51 return requested_facet_uris_; |
| 52 } |
| 53 |
| 54 AffiliationFetcherDelegate* delegate() const { return delegate_; } |
| 55 |
| 56 protected: |
| 57 AffiliationFetcher(net::URLRequestContextGetter* request_context_getter, |
| 58 const std::vector<FacetURI>& facet_uris, |
| 59 AffiliationFetcherDelegate* delegate); |
| 60 |
| 61 private: |
| 62 // Builds the URL for the Affiliation API's lookup method. |
| 63 GURL BuildQueryURL() const; |
| 64 |
| 65 // Prepares and returns the serialized protocol buffer message that will be |
| 66 // the payload of the POST request. |
| 67 std::string PreparePayload() const; |
| 68 |
| 69 // Parses the server response into |result| and returns true on success, and |
| 70 // false if the response was gravely ill-formed (unknown kinds of facet URIs |
| 71 // and new fields in the protocol buffers are ignored). |
| 72 bool ParseResponse(AffiliationFetcherDelegate::Result* result) const; |
| 73 |
| 74 // net::URLFetcherDelegate: |
| 75 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 76 |
| 77 const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 78 const std::vector<FacetURI> requested_facet_uris_; |
| 79 AffiliationFetcherDelegate* const delegate_; |
| 80 |
| 81 scoped_ptr<net::URLFetcher> fetcher_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(AffiliationFetcher); |
| 84 }; |
| 85 |
| 86 } // namespace password_manager |
| 87 |
| 88 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ |
OLD | NEW |