Index: chrome/test/chromedriver/chrome/cpu_profile.cc |
diff --git a/chrome/test/chromedriver/chrome/cpu_profile.cc b/chrome/test/chromedriver/chrome/cpu_profile.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a003ca8f14d553562ddce60a14f59766e17cf7f |
--- /dev/null |
+++ b/chrome/test/chromedriver/chrome/cpu_profile.cc |
@@ -0,0 +1,74 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/test/chromedriver/chrome/cpu_profile.h" |
+ |
+#include "base/json/json_reader.h" |
+#include "base/logging.h" |
+#include "base/values.h" |
+#include "chrome/test/chromedriver/chrome/devtools_client.h" |
+ |
+CpuProfile::CpuProfile(DevToolsClient* client) |
+ : client_(client) { |
+ client_->AddListener(this); |
klm
2014/05/10 02:21:57
Why do we need to be a listener at all, if our OnE
|
+} |
+ |
+CpuProfile::~CpuProfile() {} |
+ |
+Status CpuProfile::InitProfileInternal() { |
+ base::DictionaryValue params; |
+ Status statusDebug = client_->SendCommand("Debugger.enable", params); |
+ Status statusProfiler = client_->SendCommand("Profiler.enable", params); |
+ |
+ if (statusDebug.IsError()) |
klm
2014/05/10 02:21:57
Please check the status right after sending the co
|
+ return statusDebug; |
+ else if (statusProfiler.IsError()) |
klm
2014/05/10 02:21:57
SendCommand("Debugger.disable") here, to try to cl
|
+ return statusProfiler; |
+ else |
+ return Status(kOk); |
+} |
+ |
+Status CpuProfile::StopProfileInternal() { |
+ base::DictionaryValue params; |
+ Status statusDebug = client_->SendCommand("Debugger.disable", params); |
+ Status statusProfiler = client_->SendCommand("Profiler.disable", params); |
+ |
+ if (statusDebug.IsError()) |
klm
2014/05/10 02:21:57
Same comments as in InitProfileInternal.
|
+ return statusDebug; |
+ else if (statusProfiler.IsError()) |
+ return statusProfiler; |
+ else |
+ return Status(kOk); |
+} |
+ |
+Status CpuProfile::StartProfile(scoped_ptr<base::Value>* result) { |
klm
2014/05/10 02:21:57
result is unused. Seems to be an artifact of how t
|
+ base::DictionaryValue params; |
+ Status statusInit = InitProfileInternal(); |
+ Status status = client_->SendCommand("Profiler.start", params); |
+ if (statusInit.IsError()) |
klm
2014/05/10 02:21:57
Call StopProfileInternal() here, to clean up?
|
+ return statusInit; |
+ |
+ return status; |
+ |
+} |
+ |
+Status CpuProfile::EndProfile(scoped_ptr<base::Value>* result) { |
+ base::DictionaryValue params; |
+ scoped_ptr<base::DictionaryValue> profileResult; |
+ Status status = client_->SendCommandAndGetResult( |
+ "Profiler.stop", params, &profileResult); |
+ Status disableProfileStatus = StopProfileInternal(); |
+ |
+ if (disableProfileStatus.IsError()) { |
+ return disableProfileStatus; |
+ } |
+ *result = profileResult.PassAs<base::Value>(); |
+ return status; |
+} |
+ |
+Status CpuProfile::OnEvent(DevToolsClient* client, |
+ const std::string& method, |
klm
2014/05/10 02:21:57
indentation
|
+ const base::DictionaryValue& params) { |
+ return Status(kOk); |
klm
2014/05/10 02:21:57
indentation
|
+} |