From 33e2fdddf4e08eede0ac5d44ec67a78c90d526b8 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Thu, 13 Jul 2023 12:44:34 -0700 Subject: [PATCH] internal cleanup PiperOrigin-RevId: 547888600 --- internal/network/BUILD | 2 - internal/network/http_client_impl.cc | 81 +++++-------------- internal/network/http_client_impl.h | 4 - .../flags/nearby_platform_feature_flags.h | 4 - 4 files changed, 18 insertions(+), 73 deletions(-) diff --git a/internal/network/BUILD b/internal/network/BUILD index 802ea1da..634db625 100644 --- a/internal/network/BUILD +++ b/internal/network/BUILD @@ -55,10 +55,8 @@ cc_library( ], deps = [ ":types", - "//internal/flags:nearby_flags", "//internal/platform:logging", "//internal/platform:types", - "//internal/platform/flags:platform_flags", "//internal/platform/implementation:platform", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", diff --git a/internal/network/http_client_impl.cc b/internal/network/http_client_impl.cc index 1e057c86..9a59c769 100644 --- a/internal/network/http_client_impl.cc +++ b/internal/network/http_client_impl.cc @@ -14,18 +14,14 @@ #include "internal/network/http_client_impl.h" -#include // NOLINT #include -#include // NOLINT #include #include #include #include #include "absl/status/status.h" -#include "internal/flags/nearby_flags.h" #include "internal/network/debug.h" -#include "internal/platform/flags/nearby_platform_feature_flags.h" #include "internal/platform/logging.h" #include "internal/platform/mutex_lock.h" #include "internal/platform/single_thread_executor.h" @@ -37,54 +33,27 @@ void NearbyHttpClient::StartRequest( const HttpRequest& request, std::function&)> callback) { MutexLock lock(&mutex_); - if (NearbyFlags::GetInstance().GetBoolFlag( - platform::config_package_nearby::nearby_platform_feature:: - kEnablePlatformThreadToNetwork)) { - executor_.Execute([request = std::move(request), - callback = std::move(callback)]() { - NEARBY_LOGS(INFO) << __func__ << ": Start async request to url=" - << request.GetUrl().GetUrlPath(); - absl::StatusOr response = InternalGetResponse(request); - if (response.ok()) { - NEARBY_LOGS(INFO) << __func__ << ": Got response from url=" + executor_.Execute( + [request = std::move(request), callback = std::move(callback)]() { + NEARBY_LOGS(INFO) << __func__ << ": Start async request to url=" << request.GetUrl().GetUrlPath(); - } else { - NEARBY_LOGS(ERROR) << __func__ << ": Failed to get response from url=" - << request.GetUrl().GetUrlPath() << ", status" - << response.status(); - } + absl::StatusOr response = InternalGetResponse(request); + if (response.ok()) { + NEARBY_LOGS(INFO) + << __func__ + << ": Got response from url=" << request.GetUrl().GetUrlPath(); + } else { + NEARBY_LOGS(ERROR) << __func__ << ": Failed to get response from url=" + << request.GetUrl().GetUrlPath() << ", status" + << response.status(); + } - if (callback) { - callback(response); - } - NEARBY_LOGS(INFO) << __func__ << ": Completed request to url=" - << request.GetUrl().GetUrlPath(); - }); - } else { - CleanThreads(); - - std::future http_thread = std::async(std::launch::async, [=]() { - NEARBY_LOGS(INFO) << __func__ << ": Start async request to url=" - << request.GetUrl().GetUrlPath(); - absl::StatusOr response = InternalGetResponse(request); - if (response.ok()) { - NEARBY_LOGS(INFO) << __func__ << ": Got response from url=" + if (callback) { + callback(response); + } + NEARBY_LOGS(INFO) << __func__ << ": Completed request to url=" << request.GetUrl().GetUrlPath(); - } else { - NEARBY_LOGS(ERROR) << __func__ << ": Failed to get response from url=" - << request.GetUrl().GetUrlPath() << ", status" - << response.status(); - } - - if (callback) { - callback(response); - } - NEARBY_LOGS(INFO) << __func__ << ": Completed request to url=" - << request.GetUrl().GetUrlPath(); - }); - - http_threads_.push_back(std::move(http_thread)); - } + }); } void NearbyHttpClient::StartCancellableRequest( @@ -158,20 +127,6 @@ absl::StatusOr NearbyHttpClient::GetResponse( return response; } -void NearbyHttpClient::CleanThreads() { - auto it = http_threads_.begin(); - - while (it != http_threads_.end()) { - // Delete the thread if it is ready - auto status = it->wait_for(std::chrono::seconds(0)); - if (status == std::future_status::ready) { - it = http_threads_.erase(it); - } else { - ++it; - } - } -} - absl::StatusOr NearbyHttpClient::InternalGetResponse( const HttpRequest& request) { api::WebRequest web_request; diff --git a/internal/network/http_client_impl.h b/internal/network/http_client_impl.h index 9baa49b2..904c6ced 100644 --- a/internal/network/http_client_impl.h +++ b/internal/network/http_client_impl.h @@ -16,9 +16,7 @@ #define THIRD_PARTY_NEARBY_INTERNAL_NETWORK_HTTP_CLIENT_IMPL_H_ #include -#include // NOLINT #include -#include #include "absl/base/thread_annotations.h" #include "internal/network/http_client.h" @@ -52,13 +50,11 @@ class NearbyHttpClient : public HttpClient { absl::StatusOr GetResponse(const HttpRequest& request) override; private: - void CleanThreads() ABSL_SHARED_LOCKS_REQUIRED(mutex_); static absl::StatusOr InternalGetResponse( const HttpRequest& request); Mutex mutex_; SingleThreadExecutor executor_; - std::vector> http_threads_ ABSL_GUARDED_BY(mutex_); }; } // namespace network diff --git a/internal/platform/flags/nearby_platform_feature_flags.h b/internal/platform/flags/nearby_platform_feature_flags.h index aabb4087..0283353b 100644 --- a/internal/platform/flags/nearby_platform_feature_flags.h +++ b/internal/platform/flags/nearby_platform_feature_flags.h @@ -31,10 +31,6 @@ namespace nearby_platform_feature { constexpr auto kEnableHotspotWin32Socket = flags::Flag(kConfigPackage, "45401992", true); -// Apply platform thread to network library. -constexpr auto kEnablePlatformThreadToNetwork = - flags::Flag(kConfigPackage, "45412711", true); - // Disable/Enable GATT feature in BLE V2. constexpr auto kEnableBleV2Gatt = flags::Flag(kConfigPackage, "45415180", false);