Commit 9aa878c3 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[Nearby] Move HTTP error/result enums to common directory

The HTTP result enum is not needed by the HTTP client, but the HTTP
result enum requires knowledge of the HTTP error enum. So, it is
necessary to move the HTTP error enum out of the "client" directory,
and house all HTTP enums in the "common" directory.

Change-Id: I5458d892f85b4045d2407954d16ef66f447139e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333871
Commit-Queue: Josh Nohle <nohle@chromium.org>
Auto-Submit: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#795242}
parent 6246c58f
...@@ -12,14 +12,13 @@ source_set("client") { ...@@ -12,14 +12,13 @@ source_set("client") {
"nearby_share_client_impl.h", "nearby_share_client_impl.h",
"nearby_share_http_notifier.cc", "nearby_share_http_notifier.cc",
"nearby_share_http_notifier.h", "nearby_share_http_notifier.h",
"nearby_share_request_error.cc",
"nearby_share_request_error.h",
"nearby_share_switches.cc", "nearby_share_switches.cc",
"nearby_share_switches.h", "nearby_share_switches.h",
] ]
deps = [ deps = [
"//base", "//base",
"//chrome/browser/nearby_sharing/common",
"//chrome/browser/nearby_sharing/logging", "//chrome/browser/nearby_sharing/logging",
"//chrome/browser/nearby_sharing/proto", "//chrome/browser/nearby_sharing/proto",
"//components/signin/public/identity_manager", "//components/signin/public/identity_manager",
...@@ -42,6 +41,7 @@ source_set("test_support") { ...@@ -42,6 +41,7 @@ source_set("test_support") {
deps = [ deps = [
":client", ":client",
"//base", "//base",
"//chrome/browser/nearby_sharing/common",
"//chrome/browser/nearby_sharing/proto", "//chrome/browser/nearby_sharing/proto",
] ]
} }
...@@ -58,6 +58,7 @@ source_set("unit_tests") { ...@@ -58,6 +58,7 @@ source_set("unit_tests") {
":client", ":client",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//chrome/browser/nearby_sharing/common",
"//chrome/browser/nearby_sharing/proto", "//chrome/browser/nearby_sharing/proto",
"//components/signin/public/identity_manager:test_support", "//components/signin/public/identity_manager:test_support",
"//net", "//net",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h" #include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -20,7 +20,7 @@ class NearbyShareApiCallFlow { ...@@ -20,7 +20,7 @@ class NearbyShareApiCallFlow {
public: public:
using ResultCallback = using ResultCallback =
base::OnceCallback<void(const std::string& serialized_response)>; base::OnceCallback<void(const std::string& serialized_response)>;
using ErrorCallback = base::OnceCallback<void(NearbyShareRequestError error)>; using ErrorCallback = base::OnceCallback<void(NearbyShareHttpError error)>;
using QueryParameters = std::vector<std::pair<std::string, std::string>>; using QueryParameters = std::vector<std::pair<std::string, std::string>>;
NearbyShareApiCallFlow() = default; NearbyShareApiCallFlow() = default;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow_impl.h" #include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow_impl.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "chrome/browser/nearby_sharing/logging/logging.h" #include "chrome/browser/nearby_sharing/logging/logging.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
...@@ -21,22 +22,6 @@ const char kProtobufContentType[] = "application/x-protobuf"; ...@@ -21,22 +22,6 @@ const char kProtobufContentType[] = "application/x-protobuf";
const char kQueryParameterAlternateOutputKey[] = "alt"; const char kQueryParameterAlternateOutputKey[] = "alt";
const char kQueryParameterAlternateOutputProto[] = "proto"; const char kQueryParameterAlternateOutputProto[] = "proto";
NearbyShareRequestError GetErrorForHttpResponseCode(int response_code) {
if (response_code == 400)
return NearbyShareRequestError::kBadRequest;
if (response_code == 403)
return NearbyShareRequestError::kAuthenticationError;
if (response_code == 404)
return NearbyShareRequestError::kEndpointNotFound;
if (response_code >= 500 && response_code < 600)
return NearbyShareRequestError::kInternalServerError;
return NearbyShareRequestError::kUnknown;
}
} // namespace } // namespace
NearbyShareApiCallFlowImpl::NearbyShareApiCallFlowImpl() = default; NearbyShareApiCallFlowImpl::NearbyShareApiCallFlowImpl() = default;
...@@ -132,7 +117,7 @@ void NearbyShareApiCallFlowImpl::ProcessApiCallSuccess( ...@@ -132,7 +117,7 @@ void NearbyShareApiCallFlowImpl::ProcessApiCallSuccess(
const network::mojom::URLResponseHead* head, const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) { std::unique_ptr<std::string> body) {
if (!body) { if (!body) {
std::move(error_callback_).Run(NearbyShareRequestError::kResponseMalformed); std::move(error_callback_).Run(NearbyShareHttpError::kResponseMalformed);
return; return;
} }
std::move(result_callback_).Run(std::move(*body)); std::move(result_callback_).Run(std::move(*body));
...@@ -142,15 +127,15 @@ void NearbyShareApiCallFlowImpl::ProcessApiCallFailure( ...@@ -142,15 +127,15 @@ void NearbyShareApiCallFlowImpl::ProcessApiCallFailure(
int net_error, int net_error,
const network::mojom::URLResponseHead* head, const network::mojom::URLResponseHead* head,
std::unique_ptr<std::string> body) { std::unique_ptr<std::string> body) {
base::Optional<NearbyShareRequestError> error; base::Optional<NearbyShareHttpError> error;
std::string error_message; std::string error_message;
if (net_error == net::OK) { if (net_error == net::OK) {
int response_code = -1; int response_code = -1;
if (head && head->headers) if (head && head->headers)
response_code = head->headers->response_code(); response_code = head->headers->response_code();
error = GetErrorForHttpResponseCode(response_code); error = NearbyShareHttpErrorForHttpResponseCode(response_code);
} else { } else {
error = NearbyShareRequestError::kOffline; error = NearbyShareHttpError::kOffline;
} }
NS_LOG(ERROR) << "API call failed, error code: " NS_LOG(ERROR) << "API call failed, error code: "
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow.h" #include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h"
#include "google_apis/gaia/oauth2_api_call_flow.h" #include "google_apis/gaia/oauth2_api_call_flow.h"
// NearbyShareApiCallFlowImpl is a wrapper around OAuth2ApiCallFlow // NearbyShareApiCallFlowImpl is a wrapper around OAuth2ApiCallFlow
......
...@@ -131,9 +131,9 @@ class NearbyShareApiCallFlowImplTest : public testing::Test { ...@@ -131,9 +131,9 @@ class NearbyShareApiCallFlowImplTest : public testing::Test {
result_ = std::make_unique<std::string>(result); result_ = std::make_unique<std::string>(result);
} }
void OnError(NearbyShareRequestError network_error) { void OnError(NearbyShareHttpError network_error) {
EXPECT_FALSE(result_ || network_error_); EXPECT_FALSE(result_ || network_error_);
network_error_ = std::make_unique<NearbyShareRequestError>(network_error); network_error_ = std::make_unique<NearbyShareHttpError>(network_error);
} }
void CheckNearbySharingClientHttpPostRequest( void CheckNearbySharingClientHttpPostRequest(
...@@ -270,7 +270,7 @@ class NearbyShareApiCallFlowImplTest : public testing::Test { ...@@ -270,7 +270,7 @@ class NearbyShareApiCallFlowImplTest : public testing::Test {
} }
std::unique_ptr<std::string> result_; std::unique_ptr<std::string> result_;
std::unique_ptr<NearbyShareRequestError> network_error_; std::unique_ptr<NearbyShareHttpError> network_error_;
private: private:
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
...@@ -305,21 +305,21 @@ TEST_F(NearbyShareApiCallFlowImplTest, PostRequestFailure) { ...@@ -305,21 +305,21 @@ TEST_F(NearbyShareApiCallFlowImplTest, PostRequestFailure) {
StartPostRequestApiCallFlow(); StartPostRequestApiCallFlow();
CompleteCurrentPostRequest(net::ERR_FAILED); CompleteCurrentPostRequest(net::ERR_FAILED);
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kOffline, *network_error_); EXPECT_EQ(NearbyShareHttpError::kOffline, *network_error_);
} }
TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestFailure) { TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestFailure) {
StartPatchRequestApiCallFlow(); StartPatchRequestApiCallFlow();
CompleteCurrentPatchRequest(net::ERR_FAILED); CompleteCurrentPatchRequest(net::ERR_FAILED);
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kOffline, *network_error_); EXPECT_EQ(NearbyShareHttpError::kOffline, *network_error_);
} }
TEST_F(NearbyShareApiCallFlowImplTest, GetRequestFailure) { TEST_F(NearbyShareApiCallFlowImplTest, GetRequestFailure) {
StartGetRequestApiCallFlow(); StartGetRequestApiCallFlow();
CompleteCurrentPostRequest(net::ERR_FAILED); CompleteCurrentPostRequest(net::ERR_FAILED);
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kOffline, *network_error_); EXPECT_EQ(NearbyShareHttpError::kOffline, *network_error_);
} }
TEST_F(NearbyShareApiCallFlowImplTest, RequestStatus500) { TEST_F(NearbyShareApiCallFlowImplTest, RequestStatus500) {
...@@ -327,7 +327,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, RequestStatus500) { ...@@ -327,7 +327,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, RequestStatus500) {
CompleteCurrentPostRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR, CompleteCurrentPostRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR,
"Nearby Sharing Meltdown."); "Nearby Sharing Meltdown.");
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kInternalServerError, *network_error_); EXPECT_EQ(NearbyShareHttpError::kInternalServerError, *network_error_);
} }
TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestStatus500) { TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestStatus500) {
...@@ -335,7 +335,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestStatus500) { ...@@ -335,7 +335,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, PatchRequestStatus500) {
CompleteCurrentPatchRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR, CompleteCurrentPatchRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR,
"Nearby Sharing Meltdown."); "Nearby Sharing Meltdown.");
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kInternalServerError, *network_error_); EXPECT_EQ(NearbyShareHttpError::kInternalServerError, *network_error_);
} }
TEST_F(NearbyShareApiCallFlowImplTest, GetRequestStatus500) { TEST_F(NearbyShareApiCallFlowImplTest, GetRequestStatus500) {
...@@ -343,7 +343,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, GetRequestStatus500) { ...@@ -343,7 +343,7 @@ TEST_F(NearbyShareApiCallFlowImplTest, GetRequestStatus500) {
CompleteCurrentPostRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR, CompleteCurrentPostRequest(net::OK, net::HTTP_INTERNAL_SERVER_ERROR,
"Nearby Sharing Meltdown."); "Nearby Sharing Meltdown.");
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
EXPECT_EQ(NearbyShareRequestError::kInternalServerError, *network_error_); EXPECT_EQ(NearbyShareHttpError::kInternalServerError, *network_error_);
} }
// The empty string is a valid protocol buffer message serialization. // The empty string is a valid protocol buffer message serialization.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <string> #include <string>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h" #include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
namespace nearbyshare { namespace nearbyshare {
namespace proto { namespace proto {
...@@ -32,7 +32,7 @@ class NearbyShareClient { ...@@ -32,7 +32,7 @@ class NearbyShareClient {
public: public:
using CheckContactsReachabilityCallback = base::OnceCallback<void( using CheckContactsReachabilityCallback = base::OnceCallback<void(
const nearbyshare::proto::CheckContactsReachabilityResponse&)>; const nearbyshare::proto::CheckContactsReachabilityResponse&)>;
using ErrorCallback = base::OnceCallback<void(NearbyShareRequestError)>; using ErrorCallback = base::OnceCallback<void(NearbyShareHttpError)>;
using ListContactPeopleCallback = base::OnceCallback<void( using ListContactPeopleCallback = base::OnceCallback<void(
const nearbyshare::proto::ListContactPeopleResponse&)>; const nearbyshare::proto::ListContactPeopleResponse&)>;
using ListPublicCertificatesCallback = base::OnceCallback<void( using ListPublicCertificatesCallback = base::OnceCallback<void(
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow_impl.h" #include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow_impl.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_http_notifier.h" #include "chrome/browser/nearby_sharing/client/nearby_share_http_notifier.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_switches.h" #include "chrome/browser/nearby_sharing/client/nearby_share_switches.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "chrome/browser/nearby_sharing/logging/logging.h" #include "chrome/browser/nearby_sharing/logging/logging.h"
#include "chrome/browser/nearby_sharing/proto/certificate_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/certificate_rpc.pb.h"
#include "chrome/browser/nearby_sharing/proto/contact_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/contact_rpc.pb.h"
...@@ -335,7 +336,7 @@ void NearbyShareClientImpl::OnAccessTokenFetched( ...@@ -335,7 +336,7 @@ void NearbyShareClientImpl::OnAccessTokenFetched(
access_token_fetcher_.reset(); access_token_fetcher_.reset();
if (error.state() != GoogleServiceAuthError::NONE) { if (error.state() != GoogleServiceAuthError::NONE) {
OnApiCallFailed(NearbyShareRequestError::kAuthenticationError); OnApiCallFailed(NearbyShareHttpError::kAuthenticationError);
return; return;
} }
access_token_used_ = access_token_info.token; access_token_used_ = access_token_info.token;
...@@ -383,14 +384,14 @@ void NearbyShareClientImpl::OnFlowSuccess( ...@@ -383,14 +384,14 @@ void NearbyShareClientImpl::OnFlowSuccess(
const std::string& serialized_response) { const std::string& serialized_response) {
ResponseProto response; ResponseProto response;
if (!response.ParseFromString(serialized_response)) { if (!response.ParseFromString(serialized_response)) {
OnApiCallFailed(NearbyShareRequestError::kResponseMalformed); OnApiCallFailed(NearbyShareHttpError::kResponseMalformed);
return; return;
} }
std::move(result_callback).Run(response); std::move(result_callback).Run(response);
notifier_->NotifyOfResponse(response); notifier_->NotifyOfResponse(response);
} }
void NearbyShareClientImpl::OnApiCallFailed(NearbyShareRequestError error) { void NearbyShareClientImpl::OnApiCallFailed(NearbyShareHttpError error) {
std::move(error_callback_).Run(error); std::move(error_callback_).Run(error);
NS_LOG(ERROR) << error; NS_LOG(ERROR) << error;
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow.h" #include "chrome/browser/nearby_sharing/client/nearby_share_api_call_flow.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_client.h" #include "chrome/browser/nearby_sharing/client/nearby_share_client.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h" #include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -116,7 +116,7 @@ class NearbyShareClientImpl : public NearbyShareClient { ...@@ -116,7 +116,7 @@ class NearbyShareClientImpl : public NearbyShareClient {
const std::string& serialized_response); const std::string& serialized_response);
// Called when the current API call fails at any step. // Called when the current API call fails at any step.
void OnApiCallFailed(NearbyShareRequestError error); void OnApiCallFailed(NearbyShareHttpError error);
// Constructs and executes the actual HTTP request. // Constructs and executes the actual HTTP request.
std::unique_ptr<NearbyShareApiCallFlow> api_call_flow_; std::unique_ptr<NearbyShareApiCallFlow> api_call_flow_;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/nearby_sharing/client/nearby_share_client_impl.h" #include "chrome/browser/nearby_sharing/client/nearby_share_client_impl.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_http_notifier.h" #include "chrome/browser/nearby_sharing/client/nearby_share_http_notifier.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_switches.h" #include "chrome/browser/nearby_sharing/client/nearby_share_switches.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "chrome/browser/nearby_sharing/proto/certificate_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/certificate_rpc.pb.h"
#include "chrome/browser/nearby_sharing/proto/contact_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/contact_rpc.pb.h"
#include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h"
...@@ -268,7 +269,7 @@ class NearbyShareClientImplTest : public testing::Test, ...@@ -268,7 +269,7 @@ class NearbyShareClientImplTest : public testing::Test,
} }
// Ends the current API request with |error|. // Ends the current API request with |error|.
void FailApiCallFlow(NearbyShareRequestError error) { void FailApiCallFlow(NearbyShareHttpError error) {
std::move(api_call_flow_->error_callback_).Run(error); std::move(api_call_flow_->error_callback_).Run(error);
} }
...@@ -372,7 +373,7 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceSuccess) { ...@@ -372,7 +373,7 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceSuccess) {
base::BindOnce( base::BindOnce(
&SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>, &SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -429,12 +430,12 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceFailure) { ...@@ -429,12 +430,12 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceFailure) {
nearbyshare::proto::UpdateDeviceRequest request; nearbyshare::proto::UpdateDeviceRequest request;
request.mutable_device()->set_name(kDeviceName1); request.mutable_device()->set_name(kDeviceName1);
NearbyShareRequestError error; NearbyShareHttpError error;
client_->UpdateDevice( client_->UpdateDevice(
request, request,
base::BindOnce( base::BindOnce(
&NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>), &NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error)); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -445,8 +446,8 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceFailure) { ...@@ -445,8 +446,8 @@ TEST_F(NearbyShareClientImplTest, UpdateDeviceFailure) {
"https://www.nearbysharing-pa.testgoogleapis.com/v1/users/me/devices/" + "https://www.nearbysharing-pa.testgoogleapis.com/v1/users/me/devices/" +
std::string(kDeviceName1)); std::string(kDeviceName1));
FailApiCallFlow(NearbyShareRequestError::kInternalServerError); FailApiCallFlow(NearbyShareHttpError::kInternalServerError);
EXPECT_EQ(NearbyShareRequestError::kInternalServerError, error); EXPECT_EQ(NearbyShareHttpError::kInternalServerError, error);
} }
TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) { TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) {
...@@ -460,7 +461,7 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) { ...@@ -460,7 +461,7 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) {
base::BindOnce(&SaveResultConstRef< base::BindOnce(&SaveResultConstRef<
nearbyshare::proto::CheckContactsReachabilityResponse>, nearbyshare::proto::CheckContactsReachabilityResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -501,13 +502,13 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) { ...@@ -501,13 +502,13 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilitySuccess) {
} }
TEST_F(NearbyShareClientImplTest, CheckContactsReachabilityFailure) { TEST_F(NearbyShareClientImplTest, CheckContactsReachabilityFailure) {
NearbyShareRequestError error; NearbyShareHttpError error;
nearbyshare::proto::CheckContactsReachabilityRequest request_proto; nearbyshare::proto::CheckContactsReachabilityRequest request_proto;
client_->CheckContactsReachability( client_->CheckContactsReachability(
request_proto, request_proto,
base::BindOnce(&NotCalledConstRef< base::BindOnce(&NotCalledConstRef<
nearbyshare::proto::CheckContactsReachabilityResponse>), nearbyshare::proto::CheckContactsReachabilityResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error)); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -517,8 +518,8 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilityFailure) { ...@@ -517,8 +518,8 @@ TEST_F(NearbyShareClientImplTest, CheckContactsReachabilityFailure) {
"https://www.nearbysharing-pa.testgoogleapis.com/v1/" "https://www.nearbysharing-pa.testgoogleapis.com/v1/"
"contactsReachability:check"); "contactsReachability:check");
FailApiCallFlow(NearbyShareRequestError::kAuthenticationError); FailApiCallFlow(NearbyShareHttpError::kAuthenticationError);
EXPECT_EQ(NearbyShareRequestError::kAuthenticationError, error); EXPECT_EQ(NearbyShareHttpError::kAuthenticationError, error);
} }
TEST_F(NearbyShareClientImplTest, ListContactPeopleSuccess) { TEST_F(NearbyShareClientImplTest, ListContactPeopleSuccess) {
...@@ -533,7 +534,7 @@ TEST_F(NearbyShareClientImplTest, ListContactPeopleSuccess) { ...@@ -533,7 +534,7 @@ TEST_F(NearbyShareClientImplTest, ListContactPeopleSuccess) {
base::BindOnce( base::BindOnce(
&SaveResultConstRef<nearbyshare::proto::ListContactPeopleResponse>, &SaveResultConstRef<nearbyshare::proto::ListContactPeopleResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -594,7 +595,7 @@ TEST_F(NearbyShareClientImplTest, ListPublicCertificatesSuccess) { ...@@ -594,7 +595,7 @@ TEST_F(NearbyShareClientImplTest, ListPublicCertificatesSuccess) {
base::BindOnce(&SaveResultConstRef< base::BindOnce(&SaveResultConstRef<
nearbyshare::proto::ListPublicCertificatesResponse>, nearbyshare::proto::ListPublicCertificatesResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -665,29 +666,29 @@ TEST_F(NearbyShareClientImplTest, ListPublicCertificatesSuccess) { ...@@ -665,29 +666,29 @@ TEST_F(NearbyShareClientImplTest, ListPublicCertificatesSuccess) {
} }
TEST_F(NearbyShareClientImplTest, FetchAccessTokenFailure) { TEST_F(NearbyShareClientImplTest, FetchAccessTokenFailure) {
NearbyShareRequestError error; NearbyShareHttpError error;
client_->UpdateDevice( client_->UpdateDevice(
nearbyshare::proto::UpdateDeviceRequest(), nearbyshare::proto::UpdateDeviceRequest(),
base::BindOnce( base::BindOnce(
&NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>), &NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error)); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithError( .WaitForAccessTokenRequestIfNecessaryAndRespondWithError(
GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
EXPECT_EQ(NearbyShareRequestError::kAuthenticationError, error); EXPECT_EQ(NearbyShareHttpError::kAuthenticationError, error);
} }
TEST_F(NearbyShareClientImplTest, ParseResponseProtoFailure) { TEST_F(NearbyShareClientImplTest, ParseResponseProtoFailure) {
nearbyshare::proto::UpdateDeviceRequest request_proto; nearbyshare::proto::UpdateDeviceRequest request_proto;
request_proto.mutable_device()->set_name(kDeviceName1); request_proto.mutable_device()->set_name(kDeviceName1);
NearbyShareRequestError error; NearbyShareHttpError error;
client_->UpdateDevice( client_->UpdateDevice(
request_proto, request_proto,
base::BindOnce( base::BindOnce(
&NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>), &NotCalledConstRef<nearbyshare::proto::UpdateDeviceResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error)); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -699,7 +700,7 @@ TEST_F(NearbyShareClientImplTest, ParseResponseProtoFailure) { ...@@ -699,7 +700,7 @@ TEST_F(NearbyShareClientImplTest, ParseResponseProtoFailure) {
std::string(kDeviceName1)); std::string(kDeviceName1));
FinishApiCallFlowRaw("Not a valid serialized response message."); FinishApiCallFlowRaw("Not a valid serialized response message.");
EXPECT_EQ(NearbyShareRequestError::kResponseMalformed, error); EXPECT_EQ(NearbyShareHttpError::kResponseMalformed, error);
} }
TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) { TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) {
...@@ -713,7 +714,7 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) { ...@@ -713,7 +714,7 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) {
base::BindOnce( base::BindOnce(
&SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>, &SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -726,12 +727,12 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) { ...@@ -726,12 +727,12 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestBeforeFirstRequestSucceeds) {
// With request pending, make second request. // With request pending, make second request.
{ {
NearbyShareRequestError error; NearbyShareHttpError error;
EXPECT_DCHECK_DEATH(client_->CheckContactsReachability( EXPECT_DCHECK_DEATH(client_->CheckContactsReachability(
nearbyshare::proto::CheckContactsReachabilityRequest(), nearbyshare::proto::CheckContactsReachabilityRequest(),
base::BindOnce(&NotCalledConstRef< base::BindOnce(&NotCalledConstRef<
nearbyshare::proto::CheckContactsReachabilityResponse>), nearbyshare::proto::CheckContactsReachabilityResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error))); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error)));
} }
// Complete first request. // Complete first request.
...@@ -756,7 +757,7 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestAfterFirstRequestSucceeds) { ...@@ -756,7 +757,7 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestAfterFirstRequestSucceeds) {
base::BindOnce( base::BindOnce(
&SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>, &SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
...@@ -775,12 +776,12 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestAfterFirstRequestSucceeds) { ...@@ -775,12 +776,12 @@ TEST_F(NearbyShareClientImplTest, MakeSecondRequestAfterFirstRequestSucceeds) {
// Second request fails. // Second request fails.
{ {
NearbyShareRequestError error; NearbyShareHttpError error;
EXPECT_DCHECK_DEATH(client_->CheckContactsReachability( EXPECT_DCHECK_DEATH(client_->CheckContactsReachability(
nearbyshare::proto::CheckContactsReachabilityRequest(), nearbyshare::proto::CheckContactsReachabilityRequest(),
base::BindOnce(&NotCalledConstRef< base::BindOnce(&NotCalledConstRef<
nearbyshare::proto::CheckContactsReachabilityResponse>), nearbyshare::proto::CheckContactsReachabilityResponse>),
base::BindOnce(&SaveResult<NearbyShareRequestError>, &error))); base::BindOnce(&SaveResult<NearbyShareHttpError>, &error)));
} }
} }
...@@ -796,7 +797,7 @@ TEST_F(NearbyShareClientImplTest, GetAccessTokenUsed) { ...@@ -796,7 +797,7 @@ TEST_F(NearbyShareClientImplTest, GetAccessTokenUsed) {
base::BindOnce( base::BindOnce(
&SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>, &SaveResultConstRef<nearbyshare::proto::UpdateDeviceResponse>,
&result_proto), &result_proto),
base::BindOnce(&NotCalled<NearbyShareRequestError>)); base::BindOnce(&NotCalled<NearbyShareHttpError>));
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
kAccessToken, base::Time::Max()); kAccessToken, base::Time::Max());
......
// Copyright 2020 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 "chrome/browser/nearby_sharing/client/nearby_share_request_error.h"
std::ostream& operator<<(std::ostream& stream,
const NearbyShareRequestError& error) {
switch (error) {
case NearbyShareRequestError::kOffline:
stream << "[offline]";
break;
case NearbyShareRequestError::kEndpointNotFound:
stream << "[endpoint not found]";
break;
case NearbyShareRequestError::kAuthenticationError:
stream << "[authentication error]";
break;
case NearbyShareRequestError::kBadRequest:
stream << "[bad request]";
break;
case NearbyShareRequestError::kResponseMalformed:
stream << "[response malformed]";
break;
case NearbyShareRequestError::kInternalServerError:
stream << "[internal server error]";
break;
case NearbyShareRequestError::kUnknown:
stream << "[unknown]";
break;
}
return stream;
}
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
source_set("common") { source_set("common") {
sources = [ sources = [
"nearby_share_enums.h", "nearby_share_enums.h",
"nearby_share_http_result.cc",
"nearby_share_http_result.h",
"nearby_share_prefs.cc", "nearby_share_prefs.cc",
"nearby_share_prefs.h", "nearby_share_prefs.h",
] ]
......
// Copyright 2020 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 "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
NearbyShareHttpError NearbyShareHttpErrorForHttpResponseCode(
int response_code) {
if (response_code == 400)
return NearbyShareHttpError::kBadRequest;
if (response_code == 403)
return NearbyShareHttpError::kAuthenticationError;
if (response_code == 404)
return NearbyShareHttpError::kEndpointNotFound;
if (response_code >= 500 && response_code < 600)
return NearbyShareHttpError::kInternalServerError;
return NearbyShareHttpError::kUnknown;
}
NearbyShareHttpResult NearbyShareHttpErrorToResult(NearbyShareHttpError error) {
switch (error) {
case NearbyShareHttpError::kOffline:
return NearbyShareHttpResult::kHttpErrorOffline;
case NearbyShareHttpError::kEndpointNotFound:
return NearbyShareHttpResult::kHttpErrorEndpointNotFound;
case NearbyShareHttpError::kAuthenticationError:
return NearbyShareHttpResult::kHttpErrorAuthenticationError;
case NearbyShareHttpError::kBadRequest:
return NearbyShareHttpResult::kHttpErrorBadRequest;
case NearbyShareHttpError::kResponseMalformed:
return NearbyShareHttpResult::kHttpErrorResponseMalformed;
case NearbyShareHttpError::kInternalServerError:
return NearbyShareHttpResult::kHttpErrorInternalServerError;
case NearbyShareHttpError::kUnknown:
return NearbyShareHttpResult::kHttpErrorUnknown;
}
}
std::ostream& operator<<(std::ostream& stream,
const NearbyShareHttpResult& result) {
switch (result) {
case NearbyShareHttpResult::kSuccess:
stream << "[Success]";
break;
case NearbyShareHttpResult::kTimeout:
stream << "[Timeout]";
break;
case NearbyShareHttpResult::kHttpErrorOffline:
stream << "[HTTP Error: Offline]";
break;
case NearbyShareHttpResult::kHttpErrorEndpointNotFound:
stream << "[HTTP Error: Endpoint not found]";
break;
case NearbyShareHttpResult::kHttpErrorAuthenticationError:
stream << "[HTTP Error: Authentication error]";
break;
case NearbyShareHttpResult::kHttpErrorBadRequest:
stream << "[HTTP Error: Bad request]";
break;
case NearbyShareHttpResult::kHttpErrorResponseMalformed:
stream << "[HTTP Error: Response malformed]";
break;
case NearbyShareHttpResult::kHttpErrorInternalServerError:
stream << "[HTTP Error: Internal server error]";
break;
case NearbyShareHttpResult::kHttpErrorUnknown:
stream << "[HTTP Error: Unknown]";
break;
}
return stream;
}
std::ostream& operator<<(std::ostream& stream,
const NearbyShareHttpError& error) {
stream << NearbyShareHttpErrorToResult(error);
return stream;
}
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_REQUEST_ERROR_H_ #ifndef CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
#define CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_REQUEST_ERROR_H_ #define CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
#include <ostream> #include <ostream>
enum class NearbyShareRequestError { enum class NearbyShareHttpError {
// Request could not be completed because the device is offline or has issues // Request could not be completed because the device is offline or has issues
// sending the HTTP request. // sending the HTTP request.
kOffline, kOffline,
...@@ -31,7 +31,27 @@ enum class NearbyShareRequestError { ...@@ -31,7 +31,27 @@ enum class NearbyShareRequestError {
kUnknown kUnknown
}; };
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class NearbyShareHttpResult {
kSuccess = 0,
kTimeout = 1,
kHttpErrorOffline = 2,
kHttpErrorEndpointNotFound = 3,
kHttpErrorAuthenticationError = 4,
kHttpErrorBadRequest = 5,
kHttpErrorResponseMalformed = 6,
kHttpErrorInternalServerError = 7,
kHttpErrorUnknown = 8,
kMaxValue = kHttpErrorUnknown
};
NearbyShareHttpError NearbyShareHttpErrorForHttpResponseCode(int response_code);
NearbyShareHttpResult NearbyShareHttpErrorToResult(NearbyShareHttpError error);
std::ostream& operator<<(std::ostream& stream,
const NearbyShareHttpResult& error);
std::ostream& operator<<(std::ostream& stream, std::ostream& operator<<(std::ostream& stream,
const NearbyShareRequestError& error); const NearbyShareHttpError& error);
#endif // CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_REQUEST_ERROR_H_ #endif // CHROME_BROWSER_NEARBY_SHARING_COMMON_NEARBY_SHARE_HTTP_RESULT_H_
...@@ -10,47 +10,12 @@ ...@@ -10,47 +10,12 @@
namespace { namespace {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UpdaterResultCode {
kSuccess = 0,
kTimeout = 1,
kHttpErrorOffline = 2,
kHttpErrorEndpointNotFound = 3,
kHttpErrorAuthenticationError = 4,
kHttpErrorBadRequest = 5,
kHttpErrorResponseMalformed = 6,
kHttpErrorInternalServerError = 7,
kHttpErrorUnknown = 8,
kMaxValue = kHttpErrorUnknown
};
const char kDeviceIdPrefix[] = "users/me/devices/"; const char kDeviceIdPrefix[] = "users/me/devices/";
const char kDeviceNameFieldMaskPath[] = "device.display_name"; const char kDeviceNameFieldMaskPath[] = "device.display_name";
const char kContactsFieldMaskPath[] = "device.contacts"; const char kContactsFieldMaskPath[] = "device.contacts";
const char kCertificatesFieldMaskPath[] = "device.public_certificates"; const char kCertificatesFieldMaskPath[] = "device.public_certificates";
UpdaterResultCode RequestErrorToUpdaterResultCode( void RecordResultMetrics(NearbyShareHttpResult result) {
NearbyShareRequestError error) {
switch (error) {
case NearbyShareRequestError::kOffline:
return UpdaterResultCode::kHttpErrorOffline;
case NearbyShareRequestError::kEndpointNotFound:
return UpdaterResultCode::kHttpErrorEndpointNotFound;
case NearbyShareRequestError::kAuthenticationError:
return UpdaterResultCode::kHttpErrorAuthenticationError;
case NearbyShareRequestError::kBadRequest:
return UpdaterResultCode::kHttpErrorBadRequest;
case NearbyShareRequestError::kResponseMalformed:
return UpdaterResultCode::kHttpErrorResponseMalformed;
case NearbyShareRequestError::kInternalServerError:
return UpdaterResultCode::kHttpErrorInternalServerError;
case NearbyShareRequestError::kUnknown:
return UpdaterResultCode::kHttpErrorUnknown;
}
}
void RecordResultMetrics(UpdaterResultCode code) {
// TODO(crbug.com/1105579): Record a histogram value for each result. // TODO(crbug.com/1105579): Record a histogram value for each result.
} }
...@@ -130,20 +95,20 @@ void NearbyShareDeviceDataUpdaterImpl::OnRpcSuccess( ...@@ -130,20 +95,20 @@ void NearbyShareDeviceDataUpdaterImpl::OnRpcSuccess(
timer_.Stop(); timer_.Stop();
nearbyshare::proto::UpdateDeviceResponse response_copy(response); nearbyshare::proto::UpdateDeviceResponse response_copy(response);
client_.reset(); client_.reset();
RecordResultMetrics(UpdaterResultCode::kSuccess); RecordResultMetrics(NearbyShareHttpResult::kSuccess);
FinishAttempt(response_copy); FinishAttempt(response_copy);
} }
void NearbyShareDeviceDataUpdaterImpl::OnRpcFailure( void NearbyShareDeviceDataUpdaterImpl::OnRpcFailure(
NearbyShareRequestError error) { NearbyShareHttpError error) {
timer_.Stop(); timer_.Stop();
client_.reset(); client_.reset();
RecordResultMetrics(RequestErrorToUpdaterResultCode(error)); RecordResultMetrics(NearbyShareHttpErrorToResult(error));
FinishAttempt(/*response=*/base::nullopt); FinishAttempt(/*response=*/base::nullopt);
} }
void NearbyShareDeviceDataUpdaterImpl::OnTimeout() { void NearbyShareDeviceDataUpdaterImpl::OnTimeout() {
client_.reset(); client_.reset();
RecordResultMetrics(UpdaterResultCode::kTimeout); RecordResultMetrics(NearbyShareHttpResult::kTimeout);
FinishAttempt(/*response=*/base::nullopt); FinishAttempt(/*response=*/base::nullopt);
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h" #include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "chrome/browser/nearby_sharing/local_device_data/nearby_share_device_data_updater.h" #include "chrome/browser/nearby_sharing/local_device_data/nearby_share_device_data_updater.h"
#include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h"
...@@ -51,7 +51,7 @@ class NearbyShareDeviceDataUpdaterImpl : public NearbyShareDeviceDataUpdater { ...@@ -51,7 +51,7 @@ class NearbyShareDeviceDataUpdaterImpl : public NearbyShareDeviceDataUpdater {
void HandleNextRequest() override; void HandleNextRequest() override;
void OnTimeout(); void OnTimeout();
void OnRpcSuccess(const nearbyshare::proto::UpdateDeviceResponse& response); void OnRpcSuccess(const nearbyshare::proto::UpdateDeviceResponse& response);
void OnRpcFailure(NearbyShareRequestError error); void OnRpcFailure(NearbyShareHttpError error);
base::TimeDelta timeout_; base::TimeDelta timeout_;
NearbyShareClientFactory* client_factory_ = nullptr; NearbyShareClientFactory* client_factory_ = nullptr;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/time/clock.h" #include "base/time/clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/nearby_sharing/client/fake_nearby_share_client.h" #include "chrome/browser/nearby_sharing/client/fake_nearby_share_client.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h" #include "chrome/browser/nearby_sharing/common/nearby_share_http_result.h"
#include "chrome/browser/nearby_sharing/local_device_data/nearby_share_device_data_updater_impl.h" #include "chrome/browser/nearby_sharing/local_device_data/nearby_share_device_data_updater_impl.h"
#include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h" #include "chrome/browser/nearby_sharing/proto/device_rpc.pb.h"
#include "chrome/browser/nearby_sharing/proto/rpc_resources.pb.h" #include "chrome/browser/nearby_sharing/proto/rpc_resources.pb.h"
...@@ -179,7 +179,7 @@ class NearbyShareDeviceDataUpdaterImplTest : public ::testing::Test { ...@@ -179,7 +179,7 @@ class NearbyShareDeviceDataUpdaterImplTest : public ::testing::Test {
break; break;
case UpdateDeviceRequestResult::kHttpFailure: case UpdateDeviceRequestResult::kHttpFailure:
std::move(client->update_device_requests()[0].error_callback) std::move(client->update_device_requests()[0].error_callback)
.Run(NearbyShareRequestError::kBadRequest); .Run(NearbyShareHttpError::kBadRequest);
break; break;
case UpdateDeviceRequestResult::kTimeout: case UpdateDeviceRequestResult::kTimeout:
FastForward(kTestTimeout); FastForward(kTestTimeout);
......
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