Remove deprecate WIN INET API for Financial Ping
R=gab@chromium.org, rogerta@chromium.org Bug: 1442469 Change-Id: I1a16573d9737f63675671038836c639598b4bc68 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4632358 Commit-Queue: Etienne Bergeron <etienneb@chromium.org> Reviewed-by: Roger Tawa <rogerta@chromium.org> Cr-Commit-Position: refs/heads/main@{#1160758}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c8346b825b
commit
51afba3d10
@ -9,10 +9,6 @@ import("//build/config/chromeos/ui_mode.gni")
|
||||
import("//rlz/buildflags/buildflags.gni")
|
||||
import("//testing/test.gni")
|
||||
|
||||
config("rlz_lib_config") {
|
||||
defines = [ "RLZ_NETWORK_IMPLEMENTATION_CHROME_NET" ]
|
||||
}
|
||||
|
||||
source_set("rlz_utils") {
|
||||
sources = [
|
||||
"lib/assert.cc",
|
||||
@ -148,8 +144,6 @@ if (enable_rlz_support) {
|
||||
"//chromeos/ash/components/system",
|
||||
]
|
||||
}
|
||||
|
||||
public_configs = [ ":rlz_lib_config" ]
|
||||
}
|
||||
|
||||
source_set("test_support") {
|
||||
|
@ -39,28 +39,6 @@
|
||||
#include "base/time/time.h"
|
||||
#endif
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET)
|
||||
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
namespace {
|
||||
|
||||
class InternetHandle {
|
||||
public:
|
||||
InternetHandle(HINTERNET handle) { handle_ = handle; }
|
||||
~InternetHandle() { if (handle_) InternetCloseHandle(handle_); }
|
||||
operator HINTERNET() const { return handle_; }
|
||||
bool operator!() const { return (handle_ == NULL); }
|
||||
|
||||
private:
|
||||
HINTERNET handle_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#else
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/time/time.h"
|
||||
@ -68,8 +46,6 @@ class InternetHandle {
|
||||
#include "net/traffic_annotation/network_traffic_annotation.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
#endif
|
||||
|
||||
namespace rlz_lib {
|
||||
|
||||
using base::subtle::AtomicWord;
|
||||
@ -165,7 +141,6 @@ bool FinancialPing::FormRequest(Product product,
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
namespace {
|
||||
|
||||
// A waitable event used to detect when either:
|
||||
@ -235,8 +210,6 @@ bool send_financial_ping_interrupted_for_test = false;
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
|
||||
// The signal for the current ping request. It can be used to cancel the request
|
||||
// in case of a shutdown.
|
||||
scoped_refptr<RefCountedWaitableEvent>& GetPingResultEvent() {
|
||||
@ -262,8 +235,6 @@ bool FinancialPing::SetURLLoaderFactory(
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void PingRlzServer(std::string url,
|
||||
scoped_refptr<RefCountedWaitableEvent> event) {
|
||||
// Copy the pointer to stack because g_URLLoaderFactory may be set to NULL
|
||||
@ -317,7 +288,6 @@ void PingRlzServer(std::string url,
|
||||
base::BindOnce(&OnURLLoadComplete, std::move(url_loader),
|
||||
std::move(event)));
|
||||
}
|
||||
#endif
|
||||
|
||||
FinancialPing::PingResponse FinancialPing::PingServer(const char* request,
|
||||
std::string* response) {
|
||||
@ -326,59 +296,6 @@ FinancialPing::PingResponse FinancialPing::PingServer(const char* request,
|
||||
|
||||
response->clear();
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET)
|
||||
// Initialize WinInet.
|
||||
InternetHandle inet_handle = InternetOpenA(kFinancialPingUserAgent,
|
||||
INTERNET_OPEN_TYPE_PRECONFIG,
|
||||
NULL, NULL, 0);
|
||||
if (!inet_handle)
|
||||
return PING_FAILURE;
|
||||
|
||||
// Open network connection.
|
||||
InternetHandle connection_handle = InternetConnectA(inet_handle,
|
||||
kFinancialServer, kFinancialPort, "", "", INTERNET_SERVICE_HTTP,
|
||||
INTERNET_FLAG_NO_CACHE_WRITE, 0);
|
||||
if (!connection_handle)
|
||||
return PING_FAILURE;
|
||||
|
||||
// Prepare the HTTP request.
|
||||
const DWORD kFlags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES |
|
||||
INTERNET_FLAG_SECURE;
|
||||
InternetHandle http_handle =
|
||||
HttpOpenRequestA(connection_handle, "GET", request, NULL, NULL,
|
||||
kFinancialPingResponseObjects, kFlags, NULL);
|
||||
if (!http_handle)
|
||||
return PING_FAILURE;
|
||||
|
||||
// Timeouts are probably:
|
||||
// INTERNET_OPTION_SEND_TIMEOUT, INTERNET_OPTION_RECEIVE_TIMEOUT
|
||||
|
||||
// Send the HTTP request. Note: Fails if user is working in off-line mode.
|
||||
if (!HttpSendRequest(http_handle, NULL, 0, NULL, 0))
|
||||
return PING_FAILURE;
|
||||
|
||||
// Check the response status.
|
||||
DWORD status;
|
||||
DWORD status_size = sizeof(status);
|
||||
if (!HttpQueryInfo(http_handle, HTTP_QUERY_STATUS_CODE |
|
||||
HTTP_QUERY_FLAG_NUMBER, &status, &status_size, NULL) ||
|
||||
200 != status)
|
||||
return PING_FAILURE;
|
||||
|
||||
// Get the response text.
|
||||
std::unique_ptr<char[]> buffer(new char[kMaxPingResponseLength]);
|
||||
if (buffer.get() == NULL)
|
||||
return PING_FAILURE;
|
||||
|
||||
DWORD bytes_read = 0;
|
||||
while (InternetReadFile(http_handle, buffer.get(), kMaxPingResponseLength,
|
||||
&bytes_read) && bytes_read > 0) {
|
||||
response->append(buffer.get(), bytes_read);
|
||||
bytes_read = 0;
|
||||
};
|
||||
|
||||
return PING_SUCCESSFUL;
|
||||
#else
|
||||
std::string url =
|
||||
base::StringPrintf("https://%s%s", kFinancialServer, request);
|
||||
|
||||
@ -416,7 +333,6 @@ FinancialPing::PingResponse FinancialPing::PingServer(const char* request,
|
||||
|
||||
*response = event->TakeResponse();
|
||||
return PING_SUCCESSFUL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FinancialPing::IsPingTime(Product product, bool no_delay) {
|
||||
@ -466,7 +382,6 @@ bool FinancialPing::ClearLastPingTime(Product product) {
|
||||
return store->ClearPingTime(product);
|
||||
}
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
namespace test {
|
||||
|
||||
void ResetSendFinancialPingInterrupted() {
|
||||
@ -478,6 +393,5 @@ bool WasSendFinancialPingInterrupted() {
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
#endif
|
||||
|
||||
} // namespace rlz_lib
|
||||
|
@ -10,13 +10,11 @@
|
||||
#include <string>
|
||||
#include "rlz/lib/rlz_enums.h"
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
namespace network {
|
||||
namespace mojom {
|
||||
class URLLoaderFactory;
|
||||
}
|
||||
} // namespace network
|
||||
#endif
|
||||
|
||||
namespace rlz_lib {
|
||||
|
||||
@ -58,21 +56,17 @@ class FinancialPing {
|
||||
// Ping the financial server with request. Writes to RlzValueStore.
|
||||
static PingResponse PingServer(const char* request, std::string* response);
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
static bool SetURLLoaderFactory(network::mojom::URLLoaderFactory* factory);
|
||||
#endif
|
||||
|
||||
private:
|
||||
FinancialPing() {}
|
||||
~FinancialPing() {}
|
||||
};
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
namespace test {
|
||||
void ResetSendFinancialPingInterrupted();
|
||||
bool WasSendFinancialPingInterrupted();
|
||||
} // namespace test
|
||||
#endif
|
||||
|
||||
} // namespace rlz_lib
|
||||
|
||||
|
@ -221,11 +221,9 @@ bool GetProductEventsAsCgiHelper(rlz_lib::Product product, char* cgi,
|
||||
|
||||
namespace rlz_lib {
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
bool SetURLLoaderFactory(network::mojom::URLLoaderFactory* factory) {
|
||||
return FinancialPing::SetURLLoaderFactory(factory);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool GetProductEventsAsCgi(Product product, char* cgi, size_t cgi_size) {
|
||||
if (!cgi || cgi_size <= 0) {
|
||||
|
@ -22,32 +22,11 @@
|
||||
#include "rlz/lib/rlz_enums.h"
|
||||
#include "rlz/lib/supplementary_branding.h"
|
||||
|
||||
// Define one of
|
||||
// + RLZ_NETWORK_IMPLEMENTATION_WIN_INET: Uses win inet to send financial pings.
|
||||
// + RLZ_NETWORK_IMPLEMENTATION_CHROME_NET: Uses chrome's network stack to send
|
||||
// financial pings. rlz_lib::SetURLLoaderFactory() must be called before
|
||||
// any calls to SendFinancialPing().
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
|
||||
defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
#error Exactly one of RLZ_NETWORK_IMPLEMENTATION_WIN_INET and \
|
||||
RLZ_NETWORK_IMPLEMENTATION_CHROME_NET should be defined.
|
||||
#endif
|
||||
#if !defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
|
||||
!defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#define RLZ_NETWORK_IMPLEMENTATION_WIN_INET
|
||||
#else
|
||||
#define RLZ_NETWORK_IMPLEMENTATION_CHROME_NET
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
namespace network {
|
||||
namespace mojom {
|
||||
class URLLoaderFactory;
|
||||
} // namespace mojom
|
||||
} // namespace network
|
||||
#endif
|
||||
|
||||
namespace rlz_lib {
|
||||
|
||||
@ -72,10 +51,8 @@ const size_t kMaxRlzLength = 64;
|
||||
// The maximum length of a CGI string in bytes.
|
||||
const size_t kMaxCgiLength = 2048;
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
// Set the URLLoaderFactory used by SendFinancialPing().
|
||||
bool RLZ_LIB_API SetURLLoaderFactory(network::mojom::URLLoaderFactory* factory);
|
||||
#endif
|
||||
|
||||
// RLZ storage functions.
|
||||
|
||||
@ -170,8 +147,7 @@ bool RLZ_LIB_API ParseFinancialPingResponse(Product product,
|
||||
// This ping method should be called daily. (More frequent calls will fail).
|
||||
// Also, if there are no events, the call will succeed only once a week.
|
||||
//
|
||||
// If RLZ_NETWORK_IMPLEMENTATION_CHROME_NET is set, SetURLLoaderFactory() needs
|
||||
// to be called before calling this function.
|
||||
// SetURLLoaderFactory() needs to be called before calling this function.
|
||||
//
|
||||
// product : The product to ping for.
|
||||
// access_points : The access points this product affects. Array must be
|
||||
|
@ -41,14 +41,12 @@
|
||||
#include "rlz/win/lib/machine_deal.h"
|
||||
#endif
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "net/url_request/url_request_test_util.h"
|
||||
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
|
||||
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||
#include "services/network/test/test_url_loader_factory.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#include "base/files/important_file_writer.h"
|
||||
@ -574,7 +572,6 @@ TEST_F(RlzLibTest, SendFinancialPing) {
|
||||
if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
|
||||
return;
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
#if BUILDFLAG(IS_APPLE)
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
#endif
|
||||
@ -583,7 +580,6 @@ TEST_F(RlzLibTest, SendFinancialPing) {
|
||||
|
||||
URLLoaderFactoryRAII set_factory(
|
||||
test_url_loader_factory.GetSafeWeakWrapper().get());
|
||||
#endif
|
||||
|
||||
MachineDealCodeHelper::Clear();
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
@ -615,8 +611,6 @@ TEST_F(RlzLibTest, SendFinancialPing) {
|
||||
/* skip_time_check */ true);
|
||||
}
|
||||
|
||||
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
|
||||
|
||||
void ResetURLLoaderFactory() {
|
||||
rlz_lib::SetURLLoaderFactory(nullptr);
|
||||
}
|
||||
@ -655,7 +649,6 @@ TEST_F(RlzLibTest, SendFinancialPingDuringShutdown) {
|
||||
EXPECT_TRUE(rlz_lib::test::WasSendFinancialPingInterrupted());
|
||||
rlz_lib::test::ResetSendFinancialPingInterrupted();
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(RlzLibTest, ClearProductState) {
|
||||
MachineDealCodeHelper::Clear();
|
||||
|
Reference in New Issue
Block a user