OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iostream> | 5 #include <iostream> |
6 #include <memory> | 6 #include <memory> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 << "Expected an integer value for --virtual-time-budget="; | 156 << "Expected an integer value for --virtual-time-budget="; |
157 devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy( | 157 devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy( |
158 emulation::SetVirtualTimePolicyParams::Builder() | 158 emulation::SetVirtualTimePolicyParams::Builder() |
159 .SetPolicy(emulation::VirtualTimePolicy:: | 159 .SetPolicy(emulation::VirtualTimePolicy:: |
160 PAUSE_IF_NETWORK_FETCHES_PENDING) | 160 PAUSE_IF_NETWORK_FETCHES_PENDING) |
161 .SetBudget(budget_ms) | 161 .SetBudget(budget_ms) |
162 .Build()); | 162 .Build()); |
163 } else { | 163 } else { |
164 PollReadyState(); | 164 PollReadyState(); |
165 } | 165 } |
166 | |
167 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTimeout)) { | |
168 std::string timeout_ms_ascii = | |
169 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
170 switches::kTimeout); | |
171 int timeout_ms; | |
172 CHECK(base::StringToInt(timeout_ms_ascii, &timeout_ms)) | |
173 << "Expected an integer value for --timeout="; | |
174 browser_->BrowserMainThread()->PostDelayedTask( | |
175 FROM_HERE, | |
176 base::Bind(&HeadlessShell::FetchTimeout, base::Unretained(this)), | |
Sami
2016/11/23 18:11:32
Should we use a weak pointer here? Nothing seems t
alex clarke (OOO till 29th)
2016/11/24 12:05:04
Done.
| |
177 base::TimeDelta::FromMilliseconds(timeout_ms)); | |
178 } | |
179 | |
166 // TODO(skyostil): Implement more features to demonstrate the devtools API. | 180 // TODO(skyostil): Implement more features to demonstrate the devtools API. |
167 } | 181 } |
168 | 182 |
183 void FetchTimeout() { | |
184 LOG(INFO) << "Timeout."; | |
185 web_contents_->Stop(); | |
186 } | |
187 | |
169 void OnTargetCrashed(const inspector::TargetCrashedParams& params) override { | 188 void OnTargetCrashed(const inspector::TargetCrashedParams& params) override { |
170 LOG(ERROR) << "Abnormal renderer termination."; | 189 LOG(ERROR) << "Abnormal renderer termination."; |
171 // NB this never gets called if remote debugging is enabled. | 190 // NB this never gets called if remote debugging is enabled. |
172 Shutdown(); | 191 Shutdown(); |
173 } | 192 } |
174 | 193 |
175 void PollReadyState() { | 194 void PollReadyState() { |
176 // We need to check the current location in addition to the ready state to | 195 // We need to check the current location in addition to the ready state to |
177 // be sure the expected page is ready. | 196 // be sure the expected page is ready. |
178 devtools_client_->GetRuntime()->Evaluate( | 197 devtools_client_->GetRuntime()->Evaluate( |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 } | 461 } |
443 builder.SetWindowSize(parsed_window_size); | 462 builder.SetWindowSize(parsed_window_size); |
444 } | 463 } |
445 | 464 |
446 return HeadlessBrowserMain( | 465 return HeadlessBrowserMain( |
447 builder.Build(), | 466 builder.Build(), |
448 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 467 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
449 } | 468 } |
450 | 469 |
451 } // namespace headless | 470 } // namespace headless |
OLD | NEW |