[dart/flutter_runner] Copy package.resolved_url for TRACE_DURATION

Ensure that the string data backing package.resolved_url is not modified
or moved by making a copy to pass as the argument value for
TRACE_DURATION.

PT-169 #comment

Change-Id: I1ef6ab9b1ecf350e82134d1d616a841611ac19c6

Ported from Topaz tree.
This commit is contained in:
Chris Bracken
2019-06-28 16:09:52 -07:00
parent 9dc7ebcdf4
commit c58d26f718
2 changed files with 16 additions and 2 deletions

View File

@@ -189,7 +189,14 @@ void DartRunner::StartComponent(
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
TRACE_EVENT1("dart", "StartComponent", "url", package.resolved_url.c_str());
// TRACE_DURATION currently requires that the string data does not change
// in the traced scope. Since |package| gets moved in the construction of
// |thread| below, we cannot ensure that |package.resolved_url| does not
// move or change, so we make a copy to pass to TRACE_DURATION.
// TODO(PT-169): Remove this copy when TRACE_DURATION reads string arguments
// eagerly.
std::string url_copy = package.resolved_url;
TRACE_EVENT1("dart", "StartComponent", "url", url_copy.c_str());
std::thread thread(RunApplication, this, std::move(package),
std::move(startup_info), context_->svc(),
std::move(controller));

View File

@@ -137,7 +137,14 @@ void Runner::StartComponent(
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
TRACE_EVENT0("flutter", "StartComponent");
// TRACE_DURATION currently requires that the string data does not change
// in the traced scope. Since |package| gets moved in the Application::Create
// call below, we cannot ensure that |package.resolved_url| does not move or
// change, so we make a copy to pass to TRACE_DURATION.
// TODO(PT-169): Remove this copy when TRACE_DURATION reads string arguments
// eagerly.
std::string url_copy = package.resolved_url;
TRACE_EVENT1("flutter", "StartComponent", "url", url_copy.c_str());
// Notes on application termination: Application typically terminate on the
// thread on which they were created. This usually means the thread was
// specifically created to host the application. But we want to ensure that