Commit 304220b9 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot
Browse files

Only call LoadOrCreateClientId() once.

Setup for field trials in WebView was causing GetOrCreateClientId()
to be called twice. This CL fixes this bug by adding GetClientId() to
retrieve a client id that has previously been cached by a call to the
renamed LoadOrCreateClientId().

Bug: 678288
Change-Id: Iba90aba771cba7b650062b88134884615f0137f7
Reviewed-on: https://chromium-review.googlesource.com/614641

Reviewed-by: default avatarPaul Miller <paulmiller@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Kyle Milka <kmilka@google.com>
Cr-Commit-Position: refs/heads/master@{#494231}
parent a93f4622
......@@ -32,7 +32,7 @@ CreateLowEntropyProvider() {
// Synchronous read of the client id is permitted as it is fast
// enough to have minimal impact on startup time, and is behind the
// webview-enable-finch flag.
android_webview::AwMetricsServiceClient::GetOrCreateClientId()));
android_webview::AwMetricsServiceClient::GetClientId()));
}
// Synchronous read of variations data is permitted as it is fast
......@@ -78,6 +78,8 @@ void AwFieldTrialCreator::SetUpFieldTrials() {
if (!AwMetricsServiceClient::CheckSDKVersionForMetrics())
return;
AwMetricsServiceClient::LoadOrCreateClientId();
DCHECK(!field_trial_list_);
// Set the FieldTrialList singleton.
field_trial_list_ =
......
......@@ -81,7 +81,7 @@ bool AwMetricsServiceClient::CheckSDKVersionForMetrics() {
base::android::SDK_VERSION_NOUGAT;
}
std::string AwMetricsServiceClient::GetOrCreateClientId() {
void AwMetricsServiceClient::LoadOrCreateClientId() {
// This function should only be called once at start up.
DCHECK_NE(g_client_id.Get().length(), GUID_SIZE);
......@@ -94,7 +94,7 @@ std::string AwMetricsServiceClient::GetOrCreateClientId() {
// Generate a 1-time GUID so metrics can still be collected
g_client_id.Get() = base::GenerateGUID();
return g_client_id.Get();
return;
}
const base::FilePath guid_file_path =
......@@ -104,7 +104,7 @@ std::string AwMetricsServiceClient::GetOrCreateClientId() {
if (base::ReadFileToStringWithMaxSize(guid_file_path, &g_client_id.Get(),
GUID_SIZE)) {
if (base::IsValidGUID(g_client_id.Get()))
return g_client_id.Get();
return;
LOG(ERROR) << "Overwriting invalid GUID";
}
......@@ -116,6 +116,12 @@ std::string AwMetricsServiceClient::GetOrCreateClientId() {
// to the next run, but we can still collect metrics with this 1-time GUID.
LOG(ERROR) << "Failed to write new GUID";
}
}
std::string AwMetricsServiceClient::GetClientId() {
// This function should only be called if LoadOrCreateClientId() was
// previously called.
DCHECK_EQ(g_client_id.Get().length(), GUID_SIZE);
return g_client_id.Get();
}
......@@ -139,8 +145,7 @@ void AwMetricsServiceClient::Initialize(
} else {
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(
base::IgnoreResult(&AwMetricsServiceClient::GetOrCreateClientId)),
base::Bind(&AwMetricsServiceClient::LoadOrCreateClientId),
base::Bind(&AwMetricsServiceClient::InitializeWithClientId,
base::Unretained(this)));
}
......
......@@ -48,7 +48,10 @@ class AwMetricsServiceClient : public metrics::MetricsServiceClient,
static bool CheckSDKVersionForMetrics();
// Retrieve the client ID or generate one if none exists.
static std::string GetOrCreateClientId();
static void LoadOrCreateClientId();
// Return the cached client id.
static std::string GetClientId();
void Initialize(PrefService* pref_service,
net::URLRequestContextGetter* request_context);
......
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