-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix threading-related crash in Cobalt telemetry.
The Chromium metrics libraries require any calls to their public APIs to be invoked on the same thread in which they were created. Similarly, H5vcc JS callback need to be invoked on the V8 thread. This was being violated as the H5vcc callbacks were being invoked by a non-V* thread and H5vccMetrics was trying to call metrics APIs from a V8 thread. The fix is to store the task runners for the CobaltMetricsServicesManager and H5vccMetrics instances and use those to run any tasks that must be run in the targeted thread. This approach required a slight refactoring to allow the top level CobaltMetricsServicesManager to provide its own public API to interact with the underlying metrics client on a targeted thread. I also found this approach allowed me to just pass around a RepeatingCallback for the upload handler and remove the abstract class that was being used before (CobaltH5vccMetricsUploaderCallback). b/280094891 Change-Id: I8243b27a1853c65ac9d4fe11adc95a7f4da9ed51
- Loading branch information
Showing
16 changed files
with
285 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
cobalt/browser/metrics/cobalt_h5vcc_metrics_uploader_callback.cc
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
cobalt/browser/metrics/cobalt_h5vcc_metrics_uploader_callback.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2023 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "cobalt/browser/metrics/cobalt_metrics_services_manager.h" | ||
|
||
#include <memory> | ||
|
||
#include "cobalt/browser/metrics/cobalt_metrics_service_client.h" | ||
#include "cobalt/browser/metrics/cobalt_metrics_services_manager_client.h" | ||
#include "components/metrics_services_manager/metrics_services_manager.h" | ||
|
||
namespace cobalt { | ||
namespace browser { | ||
namespace metrics { | ||
|
||
CobaltMetricsServicesManager* CobaltMetricsServicesManager::instance_ = nullptr; | ||
|
||
CobaltMetricsServicesManager::CobaltMetricsServicesManager() | ||
: task_runner_(base::ThreadTaskRunnerHandle::Get()), | ||
metrics_services_manager::MetricsServicesManager( | ||
std::make_unique<CobaltMetricsServicesManagerClient>()) {} | ||
|
||
|
||
// Static Singleton getter for metrics services manager. | ||
CobaltMetricsServicesManager* CobaltMetricsServicesManager::GetInstance() { | ||
if (instance_ == nullptr) { | ||
instance_ = new CobaltMetricsServicesManager(); | ||
} | ||
return instance_; | ||
} | ||
|
||
void CobaltMetricsServicesManager::DeleteInstance() { delete instance_; } | ||
|
||
void CobaltMetricsServicesManager::SetOnUploadHandler( | ||
const CobaltMetricsUploaderCallback* uploader_callback) { | ||
instance_->task_runner_->PostTask( | ||
FROM_HERE, | ||
base::Bind(&CobaltMetricsServicesManager::SetOnUploadHandlerInternal, | ||
base::Unretained(instance_), uploader_callback)); | ||
} | ||
|
||
void CobaltMetricsServicesManager::SetOnUploadHandlerInternal( | ||
const CobaltMetricsUploaderCallback* uploader_callback) { | ||
CobaltMetricsServiceClient* client = | ||
static_cast<CobaltMetricsServiceClient*>(GetMetricsServiceClient()); | ||
DCHECK(client); | ||
client->SetOnUploadHandler(uploader_callback); | ||
} | ||
|
||
void CobaltMetricsServicesManager::ToggleMetricsEnabled(bool is_enabled) { | ||
instance_->task_runner_->PostTask( | ||
FROM_HERE, | ||
base::Bind(&CobaltMetricsServicesManager::ToggleMetricsEnabledInternal, | ||
base::Unretained(instance_), is_enabled)); | ||
} | ||
void CobaltMetricsServicesManager::ToggleMetricsEnabledInternal( | ||
bool is_enabled) { | ||
CobaltMetricsServicesManagerClient* client = | ||
static_cast<CobaltMetricsServicesManagerClient*>( | ||
GetMetricsServicesManagerClient()); | ||
DCHECK(client); | ||
client->GetEnabledStateProvider()->SetConsentGiven(is_enabled); | ||
client->GetEnabledStateProvider()->SetReportingEnabled(is_enabled); | ||
UpdateUploadPermissions(is_enabled); | ||
} | ||
|
||
void CobaltMetricsServicesManager::SetUploadInterval( | ||
uint32_t interval_seconds) { | ||
instance_->task_runner_->PostTask( | ||
FROM_HERE, | ||
base::Bind(&CobaltMetricsServicesManager::SetUploadIntervalInternal, | ||
base::Unretained(instance_), interval_seconds)); | ||
} | ||
|
||
void CobaltMetricsServicesManager::SetUploadIntervalInternal( | ||
uint32_t interval_seconds) { | ||
browser::metrics::CobaltMetricsServiceClient* client = | ||
static_cast<browser::metrics::CobaltMetricsServiceClient*>( | ||
GetMetricsServiceClient()); | ||
DCHECK(client); | ||
client->SetUploadInterval(interval_seconds); | ||
} | ||
|
||
|
||
} // namespace metrics | ||
} // namespace browser | ||
} // namespace cobalt |
Oops, something went wrong.