Commit 1543431a authored by Mark Pilgrim's avatar Mark Pilgrim Committed by Commit Bot

Remove unused AssetLinkRetriever

Bug: 844947
Change-Id: Iab736aaeffc70816f803a30d09bf65d712802134
Reviewed-on: https://chromium-review.googlesource.com/1135591
Commit-Queue: Doug Turner <dougt@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarThiemo Nagel <tnagel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576132}
parent 3da795c1
......@@ -139,8 +139,6 @@ static_library("browser") {
"psl_matching_helper.h",
"site_affiliation/asset_link_data.cc",
"site_affiliation/asset_link_data.h",
"site_affiliation/asset_link_retriever.cc",
"site_affiliation/asset_link_retriever.h",
"sql_table_builder.cc",
"sql_table_builder.h",
"statistics_table.cc",
......@@ -393,7 +391,6 @@ source_set("unit_tests") {
"password_ui_utils_unittest.cc",
"psl_matching_helper_unittest.cc",
"site_affiliation/asset_link_data_unittest.cc",
"site_affiliation/asset_link_retriever_unittest.cc",
"sql_table_builder_unittest.cc",
"statistics_table_unittest.cc",
"suppressed_form_fetcher_unittest.cc",
......
// 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 <memory>
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/task_runner_util.h"
#include "base/task_scheduler/post_task.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: NO
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;
} else {
state_ = State::PARSING;
std::string response_string;
source->GetResponseAsString(&response_string);
scoped_refptr<base::TaskRunner> task_runner =
base::CreateTaskRunnerWithTraits({base::TaskPriority::USER_BLOCKING});
auto data = std::make_unique<AssetLinkData>();
AssetLinkData* data_raw = data.get();
base::PostTaskAndReplyWithResult(
task_runner.get(), FROM_HERE,
base::BindOnce(&AssetLinkData::Parse, base::Unretained(data_raw),
std::move(response_string)),
base::BindOnce(&AssetLinkRetriever::OnResponseParsed, this,
std::move(data)));
}
fetcher_.reset();
}
void AssetLinkRetriever::OnResponseParsed(std::unique_ptr<AssetLinkData> data,
bool result) {
error_ = !result;
if (result)
data_ = std::move(*data);
state_ = State::FINISHED;
}
} // namespace password_manager
// 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.
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_RETRIEVER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_RETRIEVER_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/password_manager/core/browser/site_affiliation/asset_link_data.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
namespace net {
class URLRequestContextGetter;
}
namespace password_manager {
// The class is responsible for fetching and parsing the digit asset links file.
// The file is a JSON containing different directives for the domain. The class
// is only interested in those related to credentials delegations.
// The spec is
// https://github.com/google/digitalassetlinks/blob/master/well-known/details.md
class AssetLinkRetriever : public base::RefCounted<AssetLinkRetriever>,
public net::URLFetcherDelegate {
public:
enum class State {
INACTIVE,
NETWORK_REQUEST,
PARSING,
FINISHED,
};
explicit AssetLinkRetriever(GURL file_url);
// Starts a network request if the current state is INACTIVE. All the calls
// afterwards are ignored.
void Start(net::URLRequestContextGetter* context_getter);
State state() const { return state_; }
bool error() const { return error_; }
const std::vector<GURL>& includes() const { return data_.includes(); }
const std::vector<GURL>& targets() const { return data_.targets(); }
private:
friend class base::RefCounted<AssetLinkRetriever>;
~AssetLinkRetriever() override;
// net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override;
void OnResponseParsed(std::unique_ptr<AssetLinkData> data, bool result);
// URL of the file retrieved.
const GURL url_;
// Current state of the retrieval.
State state_;
// Whether the reading finished with error.
bool error_;
// Actual data from the asset link.
AssetLinkData data_;
std::unique_ptr<net::URLFetcher> fetcher_;
DISALLOW_COPY_AND_ASSIGN(AssetLinkRetriever);
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_RETRIEVER_H_
// 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 <memory>
#include "base/test/scoped_task_environment.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace password_manager {
namespace {
using ::testing::IsEmpty;
using ::testing::ElementsAre;
constexpr char kAssetLinkFile[] =
"https://example.com/.well-known/assetlinks.json";
// A test URL fecther which is very cautious about not following the redirects.
class AssetLinksTestFetcher : public net::FakeURLFetcher {
public:
using FakeURLFetcher::FakeURLFetcher;
~AssetLinksTestFetcher() override { EXPECT_TRUE(stop_on_redirect_); }
// FakeURLFetcher:
void SetStopOnRedirect(bool stop_on_redirect) override {
FakeURLFetcher::SetStopOnRedirect(stop_on_redirect);
stop_on_redirect_ = stop_on_redirect;
}
private:
bool stop_on_redirect_ = false;
DISALLOW_COPY_AND_ASSIGN(AssetLinksTestFetcher);
};
std::unique_ptr<net::FakeURLFetcher> AssetLinksFetcherCreator(
const GURL& url,
net::URLFetcherDelegate* delegate,
const std::string& response_data,
net::HttpStatusCode response_code,
net::URLRequestStatus::Status status) {
return std::make_unique<AssetLinksTestFetcher>(url, delegate, response_data,
response_code, status);
}
class AssetLinkRetrieverTest : public testing::Test {
public:
AssetLinkRetrieverTest();
net::TestURLRequestContextGetter* request_context() const {
return request_context_.get();
}
net::FakeURLFetcherFactory& factory() { return factory_; }
void RunUntilIdle() { scoped_task_environment_.RunUntilIdle(); }
private:
base::test::ScopedTaskEnvironment scoped_task_environment_;
scoped_refptr<net::TestURLRequestContextGetter> request_context_;
net::FakeURLFetcherFactory factory_;
DISALLOW_COPY_AND_ASSIGN(AssetLinkRetrieverTest);
};
AssetLinkRetrieverTest::AssetLinkRetrieverTest()
: request_context_(new net::TestURLRequestContextGetter(
base::ThreadTaskRunnerHandle::Get())),
factory_(nullptr, base::Bind(&AssetLinksFetcherCreator)) {}
// Load the asset links resource that isn't available.
TEST_F(AssetLinkRetrieverTest, LoadNonExistent) {
scoped_refptr<AssetLinkRetriever> asset_link_retriever =
base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
factory().SetFakeResponse(GURL(kAssetLinkFile), std::string(),
net::HTTP_NOT_FOUND, net::URLRequestStatus::FAILED);
asset_link_retriever->Start(request_context());
EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
asset_link_retriever->state());
RunUntilIdle();
EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
EXPECT_TRUE(asset_link_retriever->error());
}
// Load the asset links resource that replies with redirect. It should be
// treated as an error.
TEST_F(AssetLinkRetrieverTest, LoadRedirect) {
scoped_refptr<AssetLinkRetriever> asset_link_retriever =
base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
factory().SetFakeResponse(GURL(kAssetLinkFile), std::string(),
net::HTTP_FOUND, net::URLRequestStatus::CANCELED);
asset_link_retriever->Start(request_context());
EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
asset_link_retriever->state());
RunUntilIdle();
EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
EXPECT_TRUE(asset_link_retriever->error());
}
// Load a valid asset links resource.
TEST_F(AssetLinkRetrieverTest, LoadValidFile) {
scoped_refptr<AssetLinkRetriever> asset_link_retriever =
base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
constexpr char json[] =
u8R"([{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://www.google.com"
}
},{
"include": "https://go/assetlinks.json"
}])";
factory().SetFakeResponse(GURL(kAssetLinkFile), json, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
asset_link_retriever->Start(request_context());
EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
asset_link_retriever->state());
RunUntilIdle();
EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
EXPECT_FALSE(asset_link_retriever->error());
EXPECT_THAT(asset_link_retriever->includes(),
ElementsAre(GURL("https://go/assetlinks.json")));
EXPECT_THAT(asset_link_retriever->targets(),
ElementsAre(GURL("https://www.google.com")));
}
// Load a broken resource.
TEST_F(AssetLinkRetrieverTest, LoadInvalidFile) {
scoped_refptr<AssetLinkRetriever> asset_link_retriever =
base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
constexpr char json[] = u8R"([{111}])";
factory().SetFakeResponse(GURL(kAssetLinkFile), json, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
asset_link_retriever->Start(request_context());
EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
asset_link_retriever->state());
RunUntilIdle();
EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
EXPECT_TRUE(asset_link_retriever->error());
EXPECT_THAT(asset_link_retriever->includes(), IsEmpty());
EXPECT_THAT(asset_link_retriever->targets(), IsEmpty());
}
} // namespace
} // namespace password_manager
......@@ -17,7 +17,6 @@ Refer to README.md for content description and update process.
<item id="android_device_manager_socket" hash_code="37249086" type="0" content_hash_code="6436865" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_device_manager.cc"/>
<item id="android_web_socket" hash_code="39356976" type="0" content_hash_code="12310113" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_web_socket.cc"/>
<item id="appcache_update_job" hash_code="25790702" type="0" content_hash_code="27424887" os_list="linux,windows" file_path="content/browser/appcache/appcache_update_request_base.cc"/>
<item id="asset_links" hash_code="89771989" type="0" content_hash_code="72216357" os_list="linux,windows" file_path="components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc"/>
<item id="autofill_query" hash_code="88863520" type="0" content_hash_code="15563339" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/>
<item id="autofill_upload" hash_code="104798869" type="0" content_hash_code="110634763" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/>
<item id="backdrop_collection_images_download" hash_code="34767164" type="0" content_hash_code="103835921" os_list="linux,windows" file_path="chrome/browser/search/background/ntp_background_service.cc"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment