OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_SITE_AFFILIATION_ASSET_LINK_RET
RIEVER_H_ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_RET
RIEVER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace net { |
| 16 class URLRequestContextGetter; |
| 17 } |
| 18 |
| 19 namespace password_manager { |
| 20 |
| 21 // The class is responsible for fetching and parsing the digit asset links file. |
| 22 // The file is a JSON containing different directives for the domain. The class |
| 23 // is only interested in those related to credentials delegations. |
| 24 // The spec is |
| 25 // https://github.com/google/digitalassetlinks/blob/master/well-known/details.md |
| 26 class AssetLinkRetriever : public base::RefCounted<AssetLinkRetriever>, |
| 27 public net::URLFetcherDelegate { |
| 28 public: |
| 29 enum class State { |
| 30 INACTIVE, |
| 31 NETWORK_REQUEST, |
| 32 FINISHED, |
| 33 }; |
| 34 |
| 35 explicit AssetLinkRetriever(GURL file_url); |
| 36 |
| 37 // Starts a network request if the current state is INACTIVE. All the calls |
| 38 // afterwards are ignored. |
| 39 void Start(net::URLRequestContextGetter* context_getter); |
| 40 |
| 41 State state() const { return state_; } |
| 42 |
| 43 bool error() const { return error_; } |
| 44 |
| 45 private: |
| 46 friend class base::RefCounted<AssetLinkRetriever>; |
| 47 ~AssetLinkRetriever() override; |
| 48 |
| 49 // net::URLFetcherDelegate: |
| 50 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 51 |
| 52 // URL of the file retrieved. |
| 53 const GURL url_; |
| 54 |
| 55 // Current state of the retrieval. |
| 56 State state_; |
| 57 |
| 58 // Whether the reading finished with error. |
| 59 bool error_; |
| 60 |
| 61 std::unique_ptr<net::URLFetcher> fetcher_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(AssetLinkRetriever); |
| 64 }; |
| 65 |
| 66 } // namespace password_manager |
| 67 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_
RETRIEVER_H_ |
OLD | NEW |