Chromium Code Reviews| Index: third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| diff --git a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| index 495b7921db61a413966621c2baca434874f0e78d..a004bd14433dfab4411f463678df5845fb7dc693 100644 |
| --- a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| +++ b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| @@ -9,6 +9,8 @@ |
| #include "core/frame/Settings.h" |
| #include "core/page/Page.h" |
| #include "platform/geometry/DoubleRect.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebThread.h" |
| #include "public/platform/WebViewScheduler.h" |
| #include "web/DevToolsEmulator.h" |
| #include "web/WebLocalFrameImpl.h" |
| @@ -29,6 +31,7 @@ InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL |
| InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFrameImpl, Client* client) |
| : m_webLocalFrameImpl(webLocalFrameImpl) |
| + , m_virtualTimeEnabled(false) |
| , m_client(client) |
| { |
| } |
| @@ -93,18 +96,31 @@ void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, double throttli |
| m_client->setCPUThrottlingRate(throttlingRate); |
| } |
| -void InspectorEmulationAgent::setVirtualTimePolicy(ErrorString*, const String& in_policy) |
| +void InspectorEmulationAgent::setVirtualTimePolicy(ErrorString*, const String& in_policy, const Maybe<double>& in_virtualTimeBudgetSeconds) |
| { |
| if (protocol::Emulation::VirtualTimePolicyEnum::Advance == in_policy) { |
| - m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::ADVANCE); |
| } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == in_policy) { |
| - m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::PAUSE); |
| } else if (protocol::Emulation::VirtualTimePolicyEnum::PauseIfNetworkFetchesPending == in_policy) { |
| - m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); |
| } |
| + if (!m_virtualTimeEnabled) { |
| + m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); |
| + m_virtualTimeEnabled = true; |
|
dgozman
2016/08/01 16:03:31
Should we instead make enableVirtualTime() idempot
alex clarke (OOO till 29th)
2016/08/01 16:45:24
Actually it is idempotent already. We can remove t
|
| + } |
| + |
| + if (in_virtualTimeBudgetSeconds.isJust()) { |
|
dgozman
2016/08/01 16:03:31
What happens if client calls setVirtualTimePolicy
alex clarke (OOO till 29th)
2016/08/01 16:45:23
Canceling the previous timer seems like the best a
|
| + WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTaskRunner(); |
| + long long delayMillis = static_cast<long long>(in_virtualTimeBudgetSeconds.fromJust() * 1000.0); |
|
dgozman
2016/08/01 16:03:31
Let's make it milliseconds in protocol.
alex clarke (OOO till 29th)
2016/08/01 16:45:24
Done.
|
| + taskRunner->postDelayedTask(BLINK_FROM_HERE, WTF::bind(&InspectorEmulationAgent::virtualTimeBudgetExpired, wrapPersistent(this)), delayMillis); |
|
dgozman
2016/08/01 16:03:31
Can we use weak pointer here? If client detaches b
alex clarke (OOO till 29th)
2016/08/01 16:45:23
Good point. Using CancellableTaskFactory here doe
|
| + } |
| +} |
| + |
| +void InspectorEmulationAgent::virtualTimeBudgetExpired() |
| +{ |
| + m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::PAUSE); |
| + frontend()->virtualTimeBudgetExpired(); |
| } |
| DEFINE_TRACE(InspectorEmulationAgent) |