Chromium Code Reviews| Index: components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc |
| diff --git a/components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc b/components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..03e9d67a56193fb914a486360cad301106926cef |
| --- /dev/null |
| +++ b/components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc |
| @@ -0,0 +1,75 @@ |
| +// 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 "components/password_manager/core/browser/site_affiliation/asset_link_retriever.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/logging.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/http/http_status_code.h" |
| +#include "net/traffic_annotation/network_traffic_annotation.h" |
| +#include "net/url_request/url_fetcher.h" |
| + |
| +namespace password_manager { |
| + |
| +AssetLinkRetriever::AssetLinkRetriever(GURL file_url) |
| + : url_(std::move(file_url)), state_(State::INACTIVE), error_(false) { |
| + DCHECK(url_.is_valid()); |
| + DCHECK(url_.SchemeIs(url::kHttpsScheme)); |
| +} |
| + |
| +void AssetLinkRetriever::Start(net::URLRequestContextGetter* context_getter) { |
| + if (state_ != State::INACTIVE) |
| + return; |
| + net::NetworkTrafficAnnotationTag traffic_annotation = |
| + net::DefineNetworkTrafficAnnotation("asset_links", R"( |
| + semantics { |
| + sender: "Asset Links Fetcher" |
| + description: |
| + "The asset links is a JSON file hosted on " |
| + "https://<domain>/.well-known/assetlinks.json. It contains " |
| + "different permissions the site gives to apps/other sites. Chrome " |
| + "looks for a permission to delegate the credentials from the site " |
| + "to another domain. It's used for handling the stored credentials " |
| + "in the password manager." |
| + trigger: |
| + "Load a site where it's possible to sign-in. The site can have a " |
| + "password form or use the Credential Management API." |
| + data: "None." |
| + destination: WEBSITE |
| + } |
| + policy { |
| + cookies_allowed: false |
| + setting: "No setting" |
| + policy_exception_justification: |
| + "The file is considered to be a resource of the page loaded." |
| + })"); |
| + fetcher_ = net::URLFetcher::Create(url_, net::URLFetcher::GET, this, |
| + traffic_annotation); |
| + fetcher_->SetRequestContext(context_getter); |
| + fetcher_->SetLoadFlags( |
| + net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | |
| + net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_MAYBE_USER_GESTURE); |
| + fetcher_->SetStopOnRedirect(true); |
| + fetcher_->Start(); |
| + state_ = State::NETWORK_REQUEST; |
| +} |
| + |
| +AssetLinkRetriever::~AssetLinkRetriever() = default; |
| + |
| +void AssetLinkRetriever::OnURLFetchComplete(const net::URLFetcher* source) { |
| + DCHECK(source == fetcher_.get()); |
| + |
| + error_ = !source->GetStatus().is_success() || |
| + source->GetResponseCode() != net::HTTP_OK; |
| + if (error_) { |
| + state_ = State::FINISHED; |
|
vabr (Chromium)
2017/06/18 16:37:51
Why not set the state independently of |error_|? D
vasilii
2017/06/19 12:20:20
Because if there is no error then the next state s
vabr (Chromium)
2017/06/19 13:07:54
Acknowledged.
|
| + } else { |
| + // Start parsing here. |
|
vabr (Chromium)
2017/06/18 16:37:51
nit: This should be a TODO(crbug.com/630555).
vasilii
2017/06/19 12:20:20
Done.
|
| + } |
| + fetcher_.reset(); |
| +} |
| + |
| +} // namespace password_manager |