blob: 6b3bb9b1f038cee1257e6735fad45e5e8a654994 [file] [log] [blame]
// Copyright 2017 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.
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
} // namespace network
namespace digital_asset_links {
extern const char kDigitalAssetLinksCheckResponseKeyLinked[];
enum class RelationshipCheckResult {
using RelationshipCheckResultCallback =
// A handler class for sending REST API requests to DigitalAssetLinks web
// end point. See
// for details of usage and APIs. These APIs are used to verify declared
// relationships between different asset types like web domains or Android apps.
// The lifecycle of this handler will be governed by the owner.
class DigitalAssetLinksHandler {
explicit DigitalAssetLinksHandler(
scoped_refptr<network::SharedURLLoaderFactory> factory);
// Checks whether the given "relationship" has been declared by the target
// |web_domain| for the source Android app which is uniquely defined by the
// |package| and SHA256 |fingerprint| (a string with 32 hexadecimals with :
// between) given. Any error in the string params here will result in a bad
// request and a nullptr response to the callback.
// Calling this multiple times on the same handler will cancel the previous
// checks.
// See
// for details.
bool CheckDigitalAssetLinkRelationship(
RelationshipCheckResultCallback callback,
const std::string& web_domain,
const std::string& package,
const std::string& fingerprint,
const std::string& relationship);
void OnURLLoadComplete(const std::string& package,
const std::string& fingerprint,
const std::string& relationship,
std::unique_ptr<std::string> response_body);
// Callbacks for the SafeJsonParser.
void OnJSONParseSucceeded(const std::string& package,
const std::string& fingerprint,
const std::string& relationship,
std::unique_ptr<base::Value> result);
void OnJSONParseFailed(const std::string& error_message);
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory_;
std::unique_ptr<network::SimpleURLLoader> url_loader_;
// The per request callback for receiving a URLFetcher result. This gets
// reset every time we get a new CheckDigitalAssetLinkRelationship call.
RelationshipCheckResultCallback callback_;
base::WeakPtrFactory<DigitalAssetLinksHandler> weak_ptr_factory_;
} // namespace digital_asset_links