Index: components/password_manager/core/browser/affiliation_fetcher.h |
diff --git a/components/password_manager/core/browser/affiliation_fetcher.h b/components/password_manager/core/browser/affiliation_fetcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..55be105aefdeb056d8efff1c04e95ee72a6eab9e |
--- /dev/null |
+++ b/components/password_manager/core/browser/affiliation_fetcher.h |
@@ -0,0 +1,89 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ |
+#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ |
+ |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "components/password_manager/core/browser/affiliation_fetcher_delegate.h" |
+#include "components/password_manager/core/browser/affiliation_utils.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+ |
+class GURL; |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+} // namespace net |
+ |
+namespace password_manager { |
+ |
+// Fetches authoritative information regarding which facets are affiliated with |
+// each other, that is, which facets belong to the same logical application. |
+// See affiliation_utils.h for a definition of what this means. |
+// |
+// 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.
|
+// but is not thread-safe. |
+class AffiliationFetcher : net::URLFetcherDelegate { |
+ public: |
+ ~AffiliationFetcher() override; |
+ |
+ // Constructs a fetcher to retrieve affiliations for each facet in |facet_ids| |
+ // using the specified |request_context_getter|, and will provide the results |
+ // to the |delegate| on the same thread that creates the instance. |
+ 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
|
+ net::URLRequestContextGetter* request_context_getter, |
+ const std::vector<FacetURI>& facet_uris, |
+ AffiliationFetcherDelegate* delegate); |
+ |
+ // Actually starts the request, and will call the delegate with the results on |
+ // the same thread when done. If |this| is destroyed before completion, the |
+ // in-flight request is cancelled, and the delegate will not be called. |
+ // Further details: |
+ // * No cookies are sent/saved with the request. |
+ // * In case of network/server errors, the request will not be retried. |
+ // * Results are guaranteed to be always fresh and will never be cached. |
+ virtual void StartRequest(); |
+ |
+ const std::vector<FacetURI>& requested_facet_uris() const { |
+ return requested_facet_uris_; |
+ } |
+ |
+ AffiliationFetcherDelegate* delegate() const { return delegate_; } |
+ |
+ protected: |
+ AffiliationFetcher(net::URLRequestContextGetter* request_context_getter, |
+ const std::vector<FacetURI>& facet_uris, |
+ AffiliationFetcherDelegate* delegate); |
+ |
+ private: |
+ // Builds the URL for the affiliation API's lookup method. |
+ GURL BuildQueryURL() const; |
+ |
+ // Prepares and returns the serialized form of the JSON dictionary that will |
+ // be the payload of the POST request. |
+ std::string PreparePayload() const; |
+ |
+ // Parses the server response into |result| and returns true on success. We |
+ // gracefully ignore most unknown fields in the response, so this method will |
+ // return false only if the response is gravely ill-formed. |
+ bool ParseResponse(AffiliationFetcherDelegate::Result* result) const; |
+ |
+ // net::URLFetcherDelegate: |
+ void OnURLFetchComplete(const net::URLFetcher* source) override; |
+ |
+ const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
+ const std::vector<FacetURI> requested_facet_uris_; |
+ AffiliationFetcherDelegate* const delegate_; |
+ |
+ scoped_ptr<net::URLFetcher> fetcher_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AffiliationFetcher); |
+}; |
+ |
+} // namespace password_manager |
+ |
+#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_FETCHER_H_ |