Chromium Code Reviews| 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 CHROME_BROWSER_ANDROID_DIGITAL_ASSET_LINKS_DIGITAL_ASSET_LINKS_HANDLER_H _ | |
| 6 #define CHROME_BROWSER_ANDROID_DIGITAL_ASSET_LINKS_DIGITAL_ASSET_LINKS_HANDLER_H _ | |
| 7 | |
| 8 #include "net/url_request/url_fetcher.h" | |
| 9 #include "net/url_request/url_fetcher_delegate.h" | |
| 10 #include "net/url_request/url_request_context_getter.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class DictionaryValue; | |
| 14 } | |
| 15 | |
| 16 namespace digital_asset_links { | |
| 17 | |
| 18 extern const char kDigitalAssetLinksCheckResponseKeyLinked[]; | |
| 19 | |
| 20 typedef base::Callback<void(std::unique_ptr<base::DictionaryValue>)> | |
| 21 RelationshipCheckResultCallback; | |
| 22 | |
| 23 // A handler class for sending REST API requests to DigitalAssetLinks web | |
| 24 // end point. See | |
| 25 // https://developers.google.com/digital-asset-links/v1/getting-started | |
| 26 // for details of usage and APIs. These APIs are used to verify declared | |
| 27 // relationships between different asset types like web domains or Android apps. | |
| 28 // The lifecycle of this handler will be governed by the owner. | |
| 29 class DigitalAssetLinksHandler : public net::URLFetcherDelegate { | |
| 30 public: | |
| 31 explicit DigitalAssetLinksHandler( | |
| 32 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
| 33 ~DigitalAssetLinksHandler() override; | |
| 34 | |
| 35 // Checks whether the given "relationship" has been declared by the target | |
| 36 // "web_domain" for the source Android app which is uniquely defined by the | |
|
nyquist
2017/04/27 04:38:25
Nit: Use vertical bars instead of quotes, i.e. |we
Yusuf
2017/04/27 17:38:55
Done.
| |
| 37 // "package_name" and SHA256 "finger_print" (a string with 32 hexadecimals | |
|
nyquist
2017/04/27 04:38:25
Nit: |fingerprint|
Yusuf
2017/04/27 17:38:55
Done.
| |
| 38 // with : in between) given. Any error in the string params | |
| 39 // here will result in a bad request and a null response to the callback. | |
|
nyquist
2017/04/27 04:38:25
Nit: nullptr
Yusuf
2017/04/27 17:38:55
Done.
| |
| 40 // | |
| 41 // Calling this multiple times on the same handler will cancel the previous | |
| 42 // checks. | |
| 43 // See | |
| 44 // https://developers.google.com/digital-asset-links/reference/rest/v1/assetli nks/check | |
| 45 // for details. | |
| 46 bool CheckDigitalAssetLinkRelationship( | |
| 47 RelationshipCheckResultCallback callback, | |
| 48 const std::string& web_domain, | |
| 49 const std::string& package_name, | |
| 50 const std::string& fingerprint, | |
| 51 const std::string& relationship); | |
| 52 | |
| 53 private: | |
| 54 // net::URLFetcherDelegate: | |
| 55 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 56 | |
| 57 // Callbacks for the SafeJsonParser. | |
| 58 void OnJSONParseSucceeded(std::unique_ptr<base::Value> result); | |
| 59 void OnJSONParseFailed(const std::string& error_message); | |
| 60 | |
| 61 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 62 | |
| 63 std::unique_ptr<net::URLFetcher> url_fetcher_; | |
| 64 | |
| 65 // The per request callback for receiving a URLFetcher result. This gets | |
| 66 // reset every time we get a new CheckDigitalAssetLinkRelationship call. | |
| 67 RelationshipCheckResultCallback callback_; | |
| 68 | |
| 69 base::WeakPtrFactory<DigitalAssetLinksHandler> weak_ptr_factory_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(DigitalAssetLinksHandler); | |
| 72 }; | |
| 73 | |
| 74 } // namespace digital_asset_links | |
| 75 | |
| 76 #endif // CHROME_BROWSER_ANDROID_DIGITAL_ASSET_LINKS_DIGITAL_ASSET_LINKS_HANDLE R_H_ | |
| OLD | NEW |