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

Side by Side 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: rebase 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 unified diff | Download patch
« no previous file with comments | « Source/core/testing/InspectorFrontendClientLocal.h ('k') | Source/web/WebDevToolsAgentImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "InspectorFrontendClientLocal.h" 32 #include "InspectorFrontendClientLocal.h"
33 33
34 #include "bindings/v8/ScriptObject.h" 34 #include "bindings/v8/ScriptObject.h"
35 #include "core/inspector/InspectorController.h" 35 #include "core/inspector/InspectorController.h"
36 #include "core/inspector/InspectorFrontendHost.h" 36 #include "core/inspector/InspectorFrontendHost.h"
37 #include "core/page/Page.h" 37 #include "core/page/Page.h"
38 #include "core/page/Settings.h" 38 #include "core/page/Settings.h"
39 #include "core/platform/Timer.h" 39 #include "core/platform/Timer.h"
40 #include "public/platform/Platform.h"
41 #include "public/platform/WebThread.h"
40 #include <wtf/Deque.h> 42 #include <wtf/Deque.h>
41 #include <wtf/text/WTFString.h> 43 #include <wtf/text/WTFString.h>
42 44
43 namespace WebCore { 45 namespace WebCore {
44 46
45 class InspectorBackendDispatchTask { 47 class InspectorBackendMessageQueue : public RefCounted<InspectorBackendMessageQu eue> {
46 WTF_MAKE_FAST_ALLOCATED; 48 WTF_MAKE_FAST_ALLOCATED;
47 public: 49 public:
48 InspectorBackendDispatchTask(InspectorController* inspectorController) 50 explicit InspectorBackendMessageQueue(InspectorController* inspectorControll er)
49 : m_inspectorController(inspectorController) 51 : m_inspectorController(inspectorController)
50 , m_timer(this, &InspectorBackendDispatchTask::onTimer)
51 { 52 {
52 } 53 }
53 54
54 void dispatch(const String& message) 55 void dispatch(const String& message)
55 { 56 {
57 ASSERT(m_inspectorController);
56 m_messages.append(message); 58 m_messages.append(message);
57 if (!m_timer.isActive()) 59 schedule();
58 m_timer.startOneShot(0);
59 } 60 }
60 61
61 void reset() 62 void stop()
62 { 63 {
64 m_inspectorController = 0;
63 m_messages.clear(); 65 m_messages.clear();
64 m_timer.stop();
65 } 66 }
66 67
67 void onTimer(Timer<InspectorBackendDispatchTask>*) 68 private:
69 void schedule()
68 { 70 {
71 class TaskImpl : public WebKit::WebThread::Task {
72 public:
73 RefPtr<InspectorBackendMessageQueue> owner;
74 virtual void run()
75 {
76 owner->deliver();
77 }
78 };
79 TaskImpl* taskImpl = new TaskImpl;
80 taskImpl->owner = this;
81 WebKit::Platform::current()->currentThread()->postTask(taskImpl);
82 }
83
84 void deliver()
85 {
86 if (!m_inspectorController)
87 return;
69 if (!m_messages.isEmpty()) { 88 if (!m_messages.isEmpty()) {
70 // Dispatch can lead to the timer destruction -> schedule the next s hot first. 89 // Dispatch can lead to the timer destruction -> schedule the next s hot first.
71 m_timer.startOneShot(0); 90 schedule();
72 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst()); 91 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst());
73 } 92 }
74 } 93 }
75 94
76 private:
77 InspectorController* m_inspectorController; 95 InspectorController* m_inspectorController;
78 Timer<InspectorBackendDispatchTask> m_timer;
79 Deque<String> m_messages; 96 Deque<String> m_messages;
80 }; 97 };
81 98
82 InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage) 99 InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage)
83 : m_inspectorController(inspectorController) 100 : m_inspectorController(inspectorController)
84 , m_frontendPage(frontendPage) 101 , m_frontendPage(frontendPage)
85 { 102 {
86 m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true); 103 m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true);
87 m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorControll er)); 104 m_messageQueue = adoptRef(new InspectorBackendMessageQueue(inspectorControll er));
88 } 105 }
89 106
90 InspectorFrontendClientLocal::~InspectorFrontendClientLocal() 107 InspectorFrontendClientLocal::~InspectorFrontendClientLocal()
91 { 108 {
109 m_messageQueue->stop();
92 if (m_frontendHost) 110 if (m_frontendHost)
93 m_frontendHost->disconnectClient(); 111 m_frontendHost->disconnectClient();
94 m_frontendPage = 0; 112 m_frontendPage = 0;
95 m_inspectorController = 0; 113 m_inspectorController = 0;
96 } 114 }
97 115
98 void InspectorFrontendClientLocal::windowObjectCleared() 116 void InspectorFrontendClientLocal::windowObjectCleared()
99 { 117 {
100 if (m_frontendHost) 118 if (m_frontendHost)
101 m_frontendHost->disconnectClient(); 119 m_frontendHost->disconnectClient();
102 ScriptState* frontendScriptState = mainWorldScriptState(m_frontendPage->main Frame()); 120 ScriptState* frontendScriptState = mainWorldScriptState(m_frontendPage->main Frame());
103 m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage); 121 m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage);
104 ScriptGlobalObject::set(frontendScriptState, "InspectorFrontendHost", m_fron tendHost.get()); 122 ScriptGlobalObject::set(frontendScriptState, "InspectorFrontendHost", m_fron tendHost.get());
105 } 123 }
106 124
107 void InspectorFrontendClientLocal::sendMessageToBackend(const String& message) 125 void InspectorFrontendClientLocal::sendMessageToBackend(const String& message)
108 { 126 {
109 m_dispatchTask->dispatch(message); 127 m_messageQueue->dispatch(message);
110 } 128 }
111 129
112 } // namespace WebCore 130 } // namespace WebCore
113 131
OLDNEW
« no previous file with comments | « Source/core/testing/InspectorFrontendClientLocal.h ('k') | Source/web/WebDevToolsAgentImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698