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

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: 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 unified diff | Download patch
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 InspectorBackendDispatchTask : public RefCounted<InspectorBackendDispatchT ask> {
46 WTF_MAKE_FAST_ALLOCATED; 48 WTF_MAKE_FAST_ALLOCATED;
47 public: 49 public:
48 InspectorBackendDispatchTask(InspectorController* inspectorController) 50 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.
49 : m_inspectorController(inspectorController) 51 : m_inspectorController(inspectorController), m_stopped(false)
50 , m_timer(this, &InspectorBackendDispatchTask::onTimer)
51 { 52 {
52 } 53 }
53 54
54 void dispatch(const String& message) 55 void dispatch(PassRefPtr<InspectorBackendDispatchTask> selfRef, const String & message)
55 { 56 {
57 ASSERT(!m_stopped);
56 m_messages.append(message); 58 m_messages.append(message);
57 if (!m_timer.isActive()) 59 schedule(selfRef);
58 m_timer.startOneShot(0);
59 } 60 }
60 61
61 void reset() 62 void stop()
62 { 63 {
63 m_messages.clear(); 64 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.
64 m_timer.stop();
65 } 65 }
66 66
67 void onTimer(Timer<InspectorBackendDispatchTask>*) 67 private:
68 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.
68 { 69 {
70 class TaskImpl : public WebKit::WebThread::Task {
71 public:
72 RefPtr<InspectorBackendDispatchTask> owner;
73 virtual void run()
74 {
75 owner->deliver(owner);
76 }
77 };
78 TaskImpl* taskImpl = new TaskImpl;
79 taskImpl->owner = selfRef;
80 WebKit::Platform::current()->currentThread()->postTask(taskImpl);
81 }
82
83 void deliver(PassRefPtr<InspectorBackendDispatchTask> selfRef)
84 {
85 if (m_stopped)
86 return;
69 if (!m_messages.isEmpty()) { 87 if (!m_messages.isEmpty()) {
70 // Dispatch can lead to the timer destruction -> schedule the next s hot first. 88 // Dispatch can lead to the timer destruction -> schedule the next s hot first.
71 m_timer.startOneShot(0); 89 schedule(selfRef);
72 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst()); 90 m_inspectorController->dispatchMessageFromFrontend(m_messages.takeFi rst());
73 } 91 }
74 } 92 }
75 93
76 private:
77 InspectorController* m_inspectorController; 94 InspectorController* m_inspectorController;
78 Timer<InspectorBackendDispatchTask> m_timer;
79 Deque<String> m_messages; 95 Deque<String> m_messages;
96 bool m_stopped;
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_dispatchQueue = adoptRef(new InspectorBackendDispatchTask(inspectorControl ler));
88 } 105 }
89 106
90 InspectorFrontendClientLocal::~InspectorFrontendClientLocal() 107 InspectorFrontendClientLocal::~InspectorFrontendClientLocal()
91 { 108 {
109 m_dispatchQueue->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_dispatchQueue->dispatch(m_dispatchQueue, message);
110 } 128 }
111 129
112 } // namespace WebCore 130 } // namespace WebCore
113 131
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698