2013-12-17 23:04:35 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-10-18 00:45:49 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/trace_subscriber.h"
|
|
|
|
#include "include/cef_trace.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "base/debug/trace_event.h"
|
|
|
|
#include "content/public/browser/tracing_controller.h"
|
|
|
|
|
|
|
|
using content::TracingController;
|
2012-10-18 00:45:49 +02:00
|
|
|
|
|
|
|
CefTraceSubscriber::CefTraceSubscriber()
|
2013-12-17 23:04:35 +01:00
|
|
|
: collecting_trace_data_(false),
|
|
|
|
weak_factory_(this) {
|
2012-10-18 00:45:49 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefTraceSubscriber::~CefTraceSubscriber() {
|
|
|
|
CEF_REQUIRE_UIT();
|
2013-12-17 23:04:35 +01:00
|
|
|
if (collecting_trace_data_) {
|
|
|
|
TracingController::GetInstance()->DisableRecording(
|
|
|
|
base::FilePath(),
|
|
|
|
TracingController::TracingFileResultCallback());
|
|
|
|
}
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
bool CefTraceSubscriber::BeginTracing(
|
|
|
|
const std::string& categories,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2012-10-18 00:45:49 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (collecting_trace_data_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
collecting_trace_data_ = true;
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
TracingController::EnableRecordingDoneCallback done_callback;
|
|
|
|
if (callback.get())
|
|
|
|
done_callback = base::Bind(&CefCompletionCallback::OnComplete, callback);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
TracingController::GetInstance()->EnableRecording(
|
2014-02-05 21:35:45 +01:00
|
|
|
categories, TracingController::DEFAULT_OPTIONS, done_callback);
|
2013-12-17 23:04:35 +01:00
|
|
|
return true;
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
bool CefTraceSubscriber::EndTracing(
|
2013-12-17 23:04:35 +01:00
|
|
|
const base::FilePath& tracing_file,
|
|
|
|
CefRefPtr<CefEndTracingCallback> callback) {
|
2012-10-18 00:45:49 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (!collecting_trace_data_)
|
|
|
|
return false;
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
TracingController::TracingFileResultCallback result_callback;
|
|
|
|
if (callback.get()) {
|
|
|
|
result_callback =
|
|
|
|
base::Bind(&CefTraceSubscriber::OnTracingFileResult,
|
|
|
|
weak_factory_.GetWeakPtr(), callback);
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
TracingController::GetInstance()->DisableRecording(
|
|
|
|
tracing_file, result_callback);
|
|
|
|
return true;
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
void CefTraceSubscriber::OnTracingFileResult(
|
|
|
|
CefRefPtr<CefEndTracingCallback> callback,
|
|
|
|
const base::FilePath& tracing_file) {
|
2012-10-18 00:45:49 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
collecting_trace_data_ = false;
|
2013-04-16 00:16:01 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
callback->OnEndTracingComplete(tracing_file.value());
|
2013-04-16 00:16:01 +02:00
|
|
|
}
|