[inspector] migrate Schema, Console, Profiler to new style

BUG=none
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2473563002
Cr-Commit-Position: refs/heads/master@{#40688}
This commit is contained in:
kozyatinskiy 2016-11-01 17:21:31 -07:00 committed by Commit bot
parent d5055bc932
commit 8c08d423f3
9 changed files with 49 additions and 53 deletions

View File

@ -26,28 +26,29 @@ V8ConsoleAgentImpl::V8ConsoleAgentImpl(
V8ConsoleAgentImpl::~V8ConsoleAgentImpl() {}
void V8ConsoleAgentImpl::enable(ErrorString* errorString) {
if (m_enabled) return;
Response V8ConsoleAgentImpl::enable() {
if (m_enabled) return Response::OK();
m_state->setBoolean(ConsoleAgentState::consoleEnabled, true);
m_enabled = true;
m_session->inspector()->enableStackCapturingIfNeeded();
reportAllMessages();
return Response::OK();
}
void V8ConsoleAgentImpl::disable(ErrorString* errorString) {
if (!m_enabled) return;
Response V8ConsoleAgentImpl::disable() {
if (!m_enabled) return Response::OK();
m_session->inspector()->disableStackCapturingIfNeeded();
m_state->setBoolean(ConsoleAgentState::consoleEnabled, false);
m_enabled = false;
return Response::OK();
}
void V8ConsoleAgentImpl::clearMessages(ErrorString* errorString) {}
Response V8ConsoleAgentImpl::clearMessages() { return Response::OK(); }
void V8ConsoleAgentImpl::restore() {
if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled, false))
return;
ErrorString ignored;
enable(&ignored);
enable();
}
void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) {

View File

@ -14,7 +14,7 @@ namespace v8_inspector {
class V8ConsoleMessage;
class V8InspectorSessionImpl;
using protocol::ErrorString;
using protocol::Response;
class V8ConsoleAgentImpl : public protocol::Console::Backend {
public:
@ -22,9 +22,9 @@ class V8ConsoleAgentImpl : public protocol::Console::Backend {
protocol::DictionaryValue* state);
~V8ConsoleAgentImpl() override;
void enable(ErrorString*) override;
void disable(ErrorString*) override;
void clearMessages(ErrorString*) override;
Response enable() override;
Response disable() override;
Response clearMessages() override;
void restore();
void messageAdded(V8ConsoleMessage*);

View File

@ -105,8 +105,8 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
V8InspectorSessionImpl::~V8InspectorSessionImpl() {
ErrorString errorString;
m_consoleAgent->disable(&errorString);
m_profilerAgent->disable(&errorString);
m_consoleAgent->disable();
m_profilerAgent->disable();
m_heapProfilerAgent->disable(&errorString);
m_debuggerAgent->disable(&errorString);
m_runtimeAgent->disable(&errorString);

View File

@ -201,34 +201,34 @@ void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) {
resolvedTitle);
}
void V8ProfilerAgentImpl::enable(ErrorString*) {
if (m_enabled) return;
Response V8ProfilerAgentImpl::enable() {
if (m_enabled) return Response::OK();
m_enabled = true;
DCHECK(!m_profiler);
m_profiler = v8::CpuProfiler::New(m_isolate);
m_state->setBoolean(ProfilerAgentState::profilerEnabled, true);
return Response::OK();
}
void V8ProfilerAgentImpl::disable(ErrorString* errorString) {
if (!m_enabled) return;
Response V8ProfilerAgentImpl::disable() {
if (!m_enabled) return Response::OK();
for (size_t i = m_startedProfiles.size(); i > 0; --i)
stopProfiling(m_startedProfiles[i - 1].m_id, false);
m_startedProfiles.clear();
stop(nullptr, nullptr);
stop(nullptr);
m_profiler->Dispose();
m_profiler = nullptr;
m_enabled = false;
m_state->setBoolean(ProfilerAgentState::profilerEnabled, false);
return Response::OK();
}
void V8ProfilerAgentImpl::setSamplingInterval(ErrorString* error,
int interval) {
if (m_recordingCPUProfile) {
*error = "Cannot change sampling interval when profiling.";
return;
}
Response V8ProfilerAgentImpl::setSamplingInterval(int interval) {
if (m_recordingCPUProfile)
return Response::Error("Cannot change sampling interval when profiling.");
m_state->setInteger(ProfilerAgentState::samplingInterval, interval);
m_profiler->SetSamplingInterval(interval);
return Response::OK();
}
void V8ProfilerAgentImpl::restore() {
@ -243,39 +243,34 @@ void V8ProfilerAgentImpl::restore() {
if (interval) m_profiler->SetSamplingInterval(interval);
if (m_state->booleanProperty(ProfilerAgentState::userInitiatedProfiling,
false)) {
ErrorString error;
start(&error);
start();
}
}
void V8ProfilerAgentImpl::start(ErrorString* error) {
if (m_recordingCPUProfile) return;
if (!m_enabled) {
*error = "Profiler is not enabled";
return;
}
Response V8ProfilerAgentImpl::start() {
if (m_recordingCPUProfile) return Response::OK();
if (!m_enabled) return Response::Error("Profiler is not enabled");
m_recordingCPUProfile = true;
m_frontendInitiatedProfileId = nextProfileId();
startProfiling(m_frontendInitiatedProfileId);
m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, true);
return Response::OK();
}
void V8ProfilerAgentImpl::stop(
ErrorString* errorString,
Response V8ProfilerAgentImpl::stop(
std::unique_ptr<protocol::Profiler::Profile>* profile) {
if (!m_recordingCPUProfile) {
if (errorString) *errorString = "No recording profiles found";
return;
}
if (!m_recordingCPUProfile)
return Response::Error("No recording profiles found");
m_recordingCPUProfile = false;
std::unique_ptr<protocol::Profiler::Profile> cpuProfile =
stopProfiling(m_frontendInitiatedProfileId, !!profile);
if (profile) {
*profile = std::move(cpuProfile);
if (!profile->get() && errorString) *errorString = "Profile is not found";
if (!profile->get()) return Response::Error("Profile is not found");
}
m_frontendInitiatedProfileId = String16();
m_state->setBoolean(ProfilerAgentState::userInitiatedProfiling, false);
return Response::OK();
}
String16 V8ProfilerAgentImpl::nextProfileId() {

View File

@ -20,7 +20,7 @@ namespace v8_inspector {
class V8InspectorSessionImpl;
using protocol::ErrorString;
using protocol::Response;
class V8ProfilerAgentImpl : public protocol::Profiler::Backend {
public:
@ -31,12 +31,11 @@ class V8ProfilerAgentImpl : public protocol::Profiler::Backend {
bool enabled() const { return m_enabled; }
void restore();
void enable(ErrorString*) override;
void disable(ErrorString*) override;
void setSamplingInterval(ErrorString*, int) override;
void start(ErrorString*) override;
void stop(ErrorString*,
std::unique_ptr<protocol::Profiler::Profile>*) override;
Response enable() override;
Response disable() override;
Response setSamplingInterval(int) override;
Response start() override;
Response stop(std::unique_ptr<protocol::Profiler::Profile>*) override;
void consoleProfile(const String16& title);
void consoleProfileEnd(const String16& title);

View File

@ -16,14 +16,14 @@ V8SchemaAgentImpl::V8SchemaAgentImpl(V8InspectorSessionImpl* session,
V8SchemaAgentImpl::~V8SchemaAgentImpl() {}
void V8SchemaAgentImpl::getDomains(
ErrorString*,
Response V8SchemaAgentImpl::getDomains(
std::unique_ptr<protocol::Array<protocol::Schema::Domain>>* result) {
std::vector<std::unique_ptr<protocol::Schema::Domain>> domains =
m_session->supportedDomainsImpl();
*result = protocol::Array<protocol::Schema::Domain>::create();
for (size_t i = 0; i < domains.size(); ++i)
(*result)->addItem(std::move(domains[i]));
return Response::OK();
}
} // namespace v8_inspector

View File

@ -13,7 +13,7 @@ namespace v8_inspector {
class V8InspectorSessionImpl;
using protocol::ErrorString;
using protocol::Response;
class V8SchemaAgentImpl : public protocol::Schema::Backend {
public:
@ -21,8 +21,7 @@ class V8SchemaAgentImpl : public protocol::Schema::Backend {
protocol::DictionaryValue* state);
~V8SchemaAgentImpl() override;
void getDomains(
ErrorString*,
Response getDomains(
std::unique_ptr<protocol::Array<protocol::Schema::Domain>>*) override;
private:

View File

@ -330,7 +330,7 @@ def resolve_type(protocol, prop):
def new_style(domain):
domains = []
domains = [ "Schema", "Console", "Profiler" ]
return domain["domain"] in domains

View File

@ -13,4 +13,6 @@ description.
Local modifications:
- This only includes the lib/ and templates/ directories, scripts, build
and the LICENSE files.
and the LICENSE files.
- New style domains [ "Schema", "Console", "Profiler" ] are added in
CodeGenerator.py.