Commit 6b3af2a5 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Revert "[Nearby Share] Add NearbyShareClient, NearbyShareClientImpl"

This reverts commit c858e90e.

Reason for revert: compile failure on win64 bot
https://ci.chromium.org/p/chrome/builders/ci/win64-chrome/3761?blamelist=1#blamelist-tab

Original change's description:
> [Nearby Share] Add NearbyShareClient, NearbyShareClientImpl
> 
> Implement an HTTP client to make calls to the OnePlatform server
> defined here:
> https://source.corp.google.com/piper///depot/google3/google/internal/location/nearby/sharing/v1/service.proto
> 
> Bug: b/154863110
> Change-Id: I0a3b06d067e7f06a0fc933f2cf69aac4ca20036f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229299
> Reviewed-by: Josh Nohle <nohle@chromium.org>
> Reviewed-by: James Vecore <vecore@google.com>
> Commit-Queue: Curt Clemens <cclem@google.com>
> Cr-Commit-Position: refs/heads/master@{#782646}

TBR=nohle@chromium.org,vecore@google.com,cclem@google.com

Change-Id: I55c1fd117a81bda2135a3f0dcb56ef2ee88f4524
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/154863110
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2268205Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782675}
parent c6b3f03f
......@@ -3288,13 +3288,8 @@ static_library("browser") {
"nearby_sharing/client/nearby_share_api_call_flow.h",
"nearby_sharing/client/nearby_share_api_call_flow_impl.cc",
"nearby_sharing/client/nearby_share_api_call_flow_impl.h",
"nearby_sharing/client/nearby_share_client.h",
"nearby_sharing/client/nearby_share_client_impl.cc",
"nearby_sharing/client/nearby_share_client_impl.h",
"nearby_sharing/client/nearby_share_request_error.cc",
"nearby_sharing/client/nearby_share_request_error.h",
"nearby_sharing/client/switches.cc",
"nearby_sharing/client/switches.h",
"nearby_sharing/fast_initiation_manager.cc",
"nearby_sharing/fast_initiation_manager.h",
"nearby_sharing/file_attachment.cc",
......
// 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.
#ifndef CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_H_
#define CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_H_
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace nearbyshare {
namespace proto {
class CheckContactsReachabilityRequest;
class CheckContactsReachabilityResponse;
class ListContactPeopleRequest;
class ListContactPeopleResponse;
class ListPublicCertificatesRequest;
class ListPublicCertificatesResponse;
class UpdateDeviceRequest;
class UpdateDeviceResponse;
} // namespace proto
} // namespace nearbyshare
// Interface for making API requests to the NearbyShare service, which
// manages certificates and provides access to contacts.
// Implementations shall only processes a single request, so create a new
// instance for each request you make. DO NOT REUSE.
class NearbyShareClient {
public:
using CheckContactsReachabilityCallback = base::OnceCallback<void(
const nearbyshare::proto::CheckContactsReachabilityResponse&)>;
using ErrorCallback = base::OnceCallback<void(NearbyShareRequestError)>;
using ListContactPeopleCallback = base::OnceCallback<void(
const nearbyshare::proto::ListContactPeopleResponse&)>;
using ListPublicCertificatesCallback = base::OnceCallback<void(
const nearbyshare::proto::ListPublicCertificatesResponse&)>;
using UpdateDeviceCallback =
base::OnceCallback<void(const nearbyshare::proto::UpdateDeviceResponse&)>;
NearbyShareClient() = default;
virtual ~NearbyShareClient() = default;
// NearbyShareService v1: UpdateDevice
virtual void UpdateDevice(
const nearbyshare::proto::UpdateDeviceRequest& request,
UpdateDeviceCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) = 0;
// NearbyShareService v1: CheckContactsReachability
virtual void CheckContactsReachability(
const nearbyshare::proto::CheckContactsReachabilityRequest& request,
CheckContactsReachabilityCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) = 0;
// NearbyShareService v1: ListContactPeople
virtual void ListContactPeople(
const nearbyshare::proto::ListContactPeopleRequest& request,
ListContactPeopleCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) = 0;
// NearbyShareService v1: ListPublicCertificates
virtual void ListPublicCertificates(
const nearbyshare::proto::ListPublicCertificatesRequest& request,
ListPublicCertificatesCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) = 0;
// Returns the access token used to make the request. If no request has been
// made yet, this function will return an empty string.
virtual std::string GetAccessTokenUsed() = 0;
};
// Interface for creating NearbyShareClient instances. Because each
// NearbyShareClient instance can only be used for one API call, a factory
// makes it easier to make multiple requests in sequence or in parallel.
class NearbyShareClientFactory {
public:
NearbyShareClientFactory() = default;
~NearbyShareClientFactory() = default;
virtual std::unique_ptr<NearbyShareClient> CreateInstance() = 0;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_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.
#ifndef CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_IMPL_H_
#define CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_IMPL_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/memory/weak_ptr.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_client.h"
#include "chrome/browser/nearby_sharing/client/nearby_share_request_error.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "url/gurl.h"
namespace signin {
struct AccessTokenInfo;
class IdentityManager;
class PrimaryAccountAccessTokenFetcher;
} // namespace signin
namespace network {
class SharedURLLoaderFactory;
} // namespace network
class GoogleServiceAuthError;
// An implementation of NearbyShareClient that fetches access tokens for the
// primary account and makes HTTP calls using NearbyShareApiCallFlow.
class NearbyShareClientImpl : public NearbyShareClient {
public:
// Creates the client using |url_loader_factory| to make the HTTP request
// through |api_call_flow|.
NearbyShareClientImpl(
std::unique_ptr<NearbyShareApiCallFlow> api_call_flow,
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
~NearbyShareClientImpl() override;
NearbyShareClientImpl(NearbyShareClientImpl&) = delete;
NearbyShareClientImpl& operator=(NearbyShareClientImpl&) = delete;
// NearbyShareClient:
void UpdateDevice(const nearbyshare::proto::UpdateDeviceRequest& request,
UpdateDeviceCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation) override;
void CheckContactsReachability(
const nearbyshare::proto::CheckContactsReachabilityRequest& request,
CheckContactsReachabilityCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
override;
void ListContactPeople(
const nearbyshare::proto::ListContactPeopleRequest& request,
ListContactPeopleCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
override;
void ListPublicCertificates(
const nearbyshare::proto::ListPublicCertificatesRequest& request,
ListPublicCertificatesCallback&& callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
override;
std::string GetAccessTokenUsed() override;
private:
enum class RequestType { kGet, kPost, kPatch };
// Starts a call to the API given by |request_url|. The client first fetches
// the access token and then makes the HTTP request.
// |request_url|: API endpoint.
// |request_type|: Whether the request is a GET, POST, or PATCH.
// |serialized_request|: Serialized request message proto that will be sent
// as the body of a POST or PATCH request. Null if
// request type is not POST or PATCH.
// |request_as_query_parameters|: The request message proto represented as
// key-value pairs that will be sent as query
// parameters in a GET request. Note: A key
// can have multiple values. Null if request
// type is not GET.
// |response_callback|: Callback for a successful request.
// |error_callback|: Callback for a failed request.
// |partial_traffic_annotation|: A partial tag used to mark a source of
// network traffic.
template <class ResponseProto>
void MakeApiCall(
const GURL& request_url,
RequestType request_type,
const base::Optional<std::string>& serialized_request,
const base::Optional<NearbyShareApiCallFlow::QueryParameters>&
request_as_query_parameters,
base::OnceCallback<void(const ResponseProto&)>&& response_callback,
ErrorCallback&& error_callback,
const net::PartialNetworkTrafficAnnotationTag&
partial_traffic_annotation);
// Called when the access token is obtained so the API request can be made.
template <class ResponseProto>
void OnAccessTokenFetched(
RequestType request_type,
const base::Optional<std::string>& serialized_request,
const base::Optional<NearbyShareApiCallFlow::QueryParameters>&
request_as_query_parameters,
base::OnceCallback<void(const ResponseProto&)>&& response_callback,
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info);
// Called when NearbyShareApiCallFlow completes successfully to deserialize
// and return the result.
template <class ResponseProto>
void OnFlowSuccess(
base::OnceCallback<void(const ResponseProto&)>&& result_callback,
const std::string& serialized_response);
// Called when the current API call fails at any step.
void OnApiCallFailed(NearbyShareRequestError error);
// Constructs and executes the actual HTTP request.
std::unique_ptr<NearbyShareApiCallFlow> api_call_flow_;
signin::IdentityManager* identity_manager_;
// Fetches the access token authorizing the API calls.
std::unique_ptr<signin::PrimaryAccountAccessTokenFetcher>
access_token_fetcher_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// True if an API call has been started. Remains true even after the API call
// completes.
bool has_call_started_;
// URL of the current request.
GURL request_url_;
// The access token fetched by |access_token_fetcher_|.
std::string access_token_used_;
// Called when the current request fails.
ErrorCallback error_callback_;
base::WeakPtrFactory<NearbyShareClientImpl> weak_ptr_factory_{this};
};
// Implementation of NearbyShareClientFactory.
class NearbyShareClientFactoryImpl : public NearbyShareClientFactory {
public:
// |identity_manager|: Gets the user's access token.
// Not owned, so |identity_manager| needs to outlive this object.
// |url_loader_factory|: Used to make the HTTP requests.
NearbyShareClientFactoryImpl(
signin::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
~NearbyShareClientFactoryImpl();
NearbyShareClientFactoryImpl(NearbyShareClientFactoryImpl&) = delete;
NearbyShareClientFactoryImpl& operator=(NearbyShareClientFactoryImpl&) =
delete;
// NearbyShareClientFactory:
std::unique_ptr<NearbyShareClient> CreateInstance() override;
private:
signin::IdentityManager* identity_manager_;
const scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_CLIENT_NEARBY_SHARE_CLIENT_IMPL_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/client/switches.h"
namespace switches {
// Overrides the default URL for Google APIs (https://www.googleapis.com) used
// by Nearby Share
const char kNearbyShareHTTPHost[] = "nearbysharing-http-host";
} // namespace switches
// 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.
#ifndef CHROME_BROWSER_NEARBY_SHARING_CLIENT_SWITCHES_H_
#define CHROME_BROWSER_NEARBY_SHARING_CLIENT_SWITCHES_H_
namespace switches {
// All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file.
extern const char kNearbyShareHTTPHost[];
} // namespace switches
#endif // CHROME_BROWSER_NEARBY_SHARING_CLIENT_SWITCHES_H_
......@@ -3614,7 +3614,6 @@ test("unit_tests") {
"../browser/media/feeds/media_feeds_service_unittest.cc",
"../browser/media/kaleidoscope/kaleidoscope_switches_unittest.cc",
"../browser/nearby_sharing/client/nearby_share_api_call_flow_impl_unittest.cc",
"../browser/nearby_sharing/client/nearby_share_client_impl_unittest.cc",
"../browser/nearby_sharing/fake_nearby_connections_manager.cc",
"../browser/nearby_sharing/fake_nearby_connections_manager.h",
"../browser/nearby_sharing/fast_initiation_manager_unittest.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