Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1609)

Unified Diff: Source/core/testing/InspectorFrontendClientLocal.cpp

Issue 18729002: Enable message delivering in inspector-protocol tests when on pause (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: follow codereview Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/testing/InspectorFrontendClientLocal.cpp
diff --git a/Source/core/testing/InspectorFrontendClientLocal.cpp b/Source/core/testing/InspectorFrontendClientLocal.cpp
index decd7d00020b63b0971707d9aa752e4624479d9c..2c8fded87397b3f955bf647eaf7aa3fb26d5b370 100644
--- a/Source/core/testing/InspectorFrontendClientLocal.cpp
+++ b/Source/core/testing/InspectorFrontendClientLocal.cpp
@@ -37,46 +37,63 @@
#include "core/page/Page.h"
#include "core/page/Settings.h"
#include "core/platform/Timer.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebThread.h"
#include <wtf/Deque.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
-class InspectorBackendDispatchTask {
+class InspectorBackendDispatchTask : public RefCounted<InspectorBackendDispatchTask> {
WTF_MAKE_FAST_ALLOCATED;
public:
InspectorBackendDispatchTask(InspectorController* inspectorController)
yurys 2013/07/16 06:56:18 While you're here, pleas mark this constructor as
Peter.Rybin 2013/07/16 11:34:31 Done.
- : m_inspectorController(inspectorController)
- , m_timer(this, &InspectorBackendDispatchTask::onTimer)
+ : m_inspectorController(inspectorController), m_stopped(false)
{
}
- void dispatch(const String& message)
+ void dispatch(PassRefPtr<InspectorBackendDispatchTask> selfRef, const String& message)
{
+ ASSERT(!m_stopped);
m_messages.append(message);
- if (!m_timer.isActive())
- m_timer.startOneShot(0);
+ schedule(selfRef);
}
- void reset()
+ void stop()
{
m_messages.clear();
yurys 2013/07/16 06:56:18 m_stopped = true is missing also I'd rather set m_
Peter.Rybin 2013/07/16 11:34:31 Done.
- m_timer.stop();
}
- void onTimer(Timer<InspectorBackendDispatchTask>*)
+private:
+ void schedule(PassRefPtr<InspectorBackendDispatchTask> selfRef)
yurys 2013/07/16 06:56:18 Why not use this and get rid of selfRef parameter?
Peter.Rybin 2013/07/16 09:59:02 I'm not sure if it's fine to convert raw this to R
yurys 2013/07/16 10:15:55 That's absolutely fine to assign raw pointer to Re
Peter.Rybin 2013/07/16 11:34:31 Done.
{
+ class TaskImpl : public WebKit::WebThread::Task {
+ public:
+ RefPtr<InspectorBackendDispatchTask> owner;
+ virtual void run()
+ {
+ owner->deliver(owner);
+ }
+ };
+ TaskImpl* taskImpl = new TaskImpl;
+ taskImpl->owner = selfRef;
+ WebKit::Platform::current()->currentThread()->postTask(taskImpl);
+ }
+
+ void deliver(PassRefPtr<InspectorBackendDispatchTask> selfRef)
+ {
+ if (m_stopped)
+ return;
if (!m_messages.isEmpty()) {
// Dispatch can lead to the timer destruction -> schedule the next shot first.
- m_timer.startOneShot(0);
+ schedule(selfRef);
m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFirst());
}
}
-private:
InspectorController* m_inspectorController;
- Timer<InspectorBackendDispatchTask> m_timer;
Deque<String> m_messages;
+ bool m_stopped;
};
InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage)
@@ -84,11 +101,12 @@ InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController*
, m_frontendPage(frontendPage)
{
m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true);
- m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorController));
+ m_dispatchQueue = adoptRef(new InspectorBackendDispatchTask(inspectorController));
}
InspectorFrontendClientLocal::~InspectorFrontendClientLocal()
{
+ m_dispatchQueue->stop();
if (m_frontendHost)
m_frontendHost->disconnectClient();
m_frontendPage = 0;
@@ -106,7 +124,7 @@ void InspectorFrontendClientLocal::windowObjectCleared()
void InspectorFrontendClientLocal::sendMessageToBackend(const String& message)
{
- m_dispatchTask->dispatch(message);
+ m_dispatchQueue->dispatch(m_dispatchQueue, message);
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698