Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 InspectorBackendDispatchTask { |
| 46 WTF_MAKE_FAST_ALLOCATED; | 48 WTF_MAKE_FAST_ALLOCATED; |
| 47 public: | 49 public: |
| 48 InspectorBackendDispatchTask(InspectorController* inspectorController) | 50 InspectorBackendDispatchTask(InspectorController* inspectorController) |
| 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 { |
| 56 m_messages.append(message); | 57 m_messages.append(message); |
| 57 if (!m_timer.isActive()) | 58 schedule(); |
| 58 m_timer.startOneShot(0); | |
| 59 } | 59 } |
| 60 | 60 |
| 61 void reset() | 61 void reset() |
| 62 { | 62 { |
| 63 m_messages.clear(); | 63 m_messages.clear(); |
| 64 m_timer.stop(); | |
| 65 } | 64 } |
| 66 | 65 |
| 67 void onTimer(Timer<InspectorBackendDispatchTask>*) | 66 private: |
| 67 void schedule() | |
| 68 { | |
| 69 class TaskImpl : public WebKit::WebThread::Task { | |
| 70 public: | |
| 71 InspectorBackendDispatchTask* owner; | |
| 72 virtual void run() | |
| 73 { | |
| 74 owner->onTimer(); | |
|
aandrey
2013/07/05 09:31:56
can this execute after owner is destructed?
Peter.Rybin
2013/07/10 21:24:25
I guess the old implementation didn't care about i
| |
| 75 } | |
| 76 }; | |
| 77 TaskImpl* taskImpl = new TaskImpl; | |
| 78 taskImpl->owner = this; | |
| 79 WebKit::Platform::current()->currentThread()->postDelayedTask(taskImpl, 0); | |
|
yurys
2013/07/08 11:13:04
Does it guarantee the sequence of execution for th
Peter.Rybin
2013/07/08 12:23:38
You mean order of execution? I am not sure.
But an
yurys
2013/07/08 13:16:11
You are right. But if the order of execution is gu
| |
| 80 } | |
| 81 | |
| 82 void onTimer() | |
| 68 { | 83 { |
| 69 if (!m_messages.isEmpty()) { | 84 if (!m_messages.isEmpty()) { |
| 70 // Dispatch can lead to the timer destruction -> schedule the next s hot first. | 85 // Dispatch can lead to the timer destruction -> schedule the next s hot first. |
| 71 m_timer.startOneShot(0); | 86 schedule(); |
| 72 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst()); | 87 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst()); |
| 73 } | 88 } |
| 74 } | 89 } |
| 75 | 90 |
| 76 private: | |
| 77 InspectorController* m_inspectorController; | 91 InspectorController* m_inspectorController; |
| 78 Timer<InspectorBackendDispatchTask> m_timer; | |
| 79 Deque<String> m_messages; | 92 Deque<String> m_messages; |
| 80 }; | 93 }; |
| 81 | 94 |
| 82 InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage) | 95 InspectorFrontendClientLocal::InspectorFrontendClientLocal(InspectorController* inspectorController, Page* frontendPage) |
| 83 : m_inspectorController(inspectorController) | 96 : m_inspectorController(inspectorController) |
| 84 , m_frontendPage(frontendPage) | 97 , m_frontendPage(frontendPage) |
| 85 { | 98 { |
| 86 m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true); | 99 m_frontendPage->settings()->setAllowFileAccessFromFileURLs(true); |
| 87 m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorControll er)); | 100 m_dispatchTask = adoptPtr(new InspectorBackendDispatchTask(inspectorControll er)); |
| 88 } | 101 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 104 ScriptGlobalObject::set(frontendScriptState, "InspectorFrontendHost", m_fron tendHost.get()); | 117 ScriptGlobalObject::set(frontendScriptState, "InspectorFrontendHost", m_fron tendHost.get()); |
| 105 } | 118 } |
| 106 | 119 |
| 107 void InspectorFrontendClientLocal::sendMessageToBackend(const String& message) | 120 void InspectorFrontendClientLocal::sendMessageToBackend(const String& message) |
| 108 { | 121 { |
| 109 m_dispatchTask->dispatch(message); | 122 m_dispatchTask->dispatch(message); |
| 110 } | 123 } |
| 111 | 124 |
| 112 } // namespace WebCore | 125 } // namespace WebCore |
| 113 | 126 |
| OLD | NEW |