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

Side by Side Diff: components/html_viewer/html_document.cc

Issue 1278673002: Add stats collection for telemetry startup.warm.blank_page test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cache and reuse a single mojo:tracing connection in mojo:html_viewer. Created 5 years, 4 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/html_viewer/html_document.h" 5 #include "components/html_viewer/html_document.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "components/devtools_service/public/cpp/switches.h" 15 #include "components/devtools_service/public/cpp/switches.h"
16 #include "components/html_viewer/blink_input_events_type_converters.h" 16 #include "components/html_viewer/blink_input_events_type_converters.h"
17 #include "components/html_viewer/blink_url_request_type_converters.h" 17 #include "components/html_viewer/blink_url_request_type_converters.h"
18 #include "components/html_viewer/devtools_agent_impl.h" 18 #include "components/html_viewer/devtools_agent_impl.h"
19 #include "components/html_viewer/geolocation_client_impl.h" 19 #include "components/html_viewer/geolocation_client_impl.h"
20 #include "components/html_viewer/global_state.h" 20 #include "components/html_viewer/global_state.h"
21 #include "components/html_viewer/media_factory.h" 21 #include "components/html_viewer/media_factory.h"
22 #include "components/html_viewer/stats_collection_controller.h"
22 #include "components/html_viewer/web_layer_tree_view_impl.h" 23 #include "components/html_viewer/web_layer_tree_view_impl.h"
23 #include "components/html_viewer/web_storage_namespace_impl.h" 24 #include "components/html_viewer/web_storage_namespace_impl.h"
24 #include "components/html_viewer/web_url_loader_impl.h" 25 #include "components/html_viewer/web_url_loader_impl.h"
25 #include "components/view_manager/public/cpp/view.h" 26 #include "components/view_manager/public/cpp/view.h"
26 #include "components/view_manager/public/cpp/view_manager.h" 27 #include "components/view_manager/public/cpp/view_manager.h"
27 #include "components/view_manager/public/cpp/view_property.h" 28 #include "components/view_manager/public/cpp/view_property.h"
28 #include "components/view_manager/public/interfaces/surfaces.mojom.h" 29 #include "components/view_manager/public/interfaces/surfaces.mojom.h"
29 #include "mojo/application/public/cpp/application_impl.h" 30 #include "mojo/application/public/cpp/application_impl.h"
30 #include "mojo/application/public/cpp/connect.h" 31 #include "mojo/application/public/cpp/connect.h"
31 #include "mojo/application/public/interfaces/shell.mojom.h" 32 #include "mojo/application/public/interfaces/shell.mojom.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 : html_document_app(html_document_app), 153 : html_document_app(html_document_app),
153 connection(connection), 154 connection(connection),
154 response(response.Pass()), 155 response(response.Pass()),
155 global_state(global_state), 156 global_state(global_state),
156 delete_callback(delete_callback) { 157 delete_callback(delete_callback) {
157 } 158 }
158 159
159 HTMLDocument::CreateParams::~CreateParams() { 160 HTMLDocument::CreateParams::~CreateParams() {
160 } 161 }
161 162
163 HTMLDocument::Observer::Observer(HTMLDocument* html_document)
164 : html_document_(html_document) {
sky 2015/08/12 23:54:36 nit: make sure you run git cl format.
msw 2015/08/14 23:20:34 Done.
165 html_document_->AddObserver(this);
166 }
167
168 HTMLDocument::Observer::~Observer() {
169 html_document_->RemoveObserver(this);
170 }
171
162 HTMLDocument::HTMLDocument(HTMLDocument::CreateParams* params) 172 HTMLDocument::HTMLDocument(HTMLDocument::CreateParams* params)
163 : app_refcount_(params->html_document_app->app_lifetime_helper() 173 : app_refcount_(params->html_document_app->app_lifetime_helper()
164 ->CreateAppRefCount()), 174 ->CreateAppRefCount()),
165 html_document_app_(params->html_document_app), 175 html_document_app_(params->html_document_app),
166 response_(params->response.Pass()), 176 response_(params->response.Pass()),
167 navigator_host_(params->connection->GetServiceProvider()), 177 navigator_host_(params->connection->GetServiceProvider()),
168 web_view_(nullptr), 178 web_view_(nullptr),
169 root_(nullptr), 179 root_(nullptr),
170 view_manager_client_factory_(params->html_document_app->shell(), this), 180 view_manager_client_factory_(params->html_document_app->shell(), this),
171 global_state_(params->global_state), 181 global_state_(params->global_state),
172 delete_callback_(params->delete_callback) { 182 delete_callback_(params->delete_callback),
183 stats_collection_controller_(nullptr) {
173 params->connection->AddService( 184 params->connection->AddService(
174 static_cast<InterfaceFactory<mojo::AxProvider>*>(this)); 185 static_cast<InterfaceFactory<mojo::AxProvider>*>(this));
175 params->connection->AddService(&view_manager_client_factory_); 186 params->connection->AddService(&view_manager_client_factory_);
176 187
177 if (global_state_->did_init()) 188 if (global_state_->did_init())
178 Load(response_.Pass()); 189 Load(response_.Pass());
179 } 190 }
180 191
181 void HTMLDocument::Destroy() { 192 void HTMLDocument::Destroy() {
182 // See comment in header for a description of lifetime. 193 // See comment in header for a description of lifetime.
183 if (root_) { 194 if (root_) {
184 // Deleting the ViewManager calls back to OnViewManagerDestroyed() and 195 // Deleting the ViewManager calls back to OnViewManagerDestroyed() and
185 // triggers deletion. 196 // triggers deletion.
186 delete root_->view_manager(); 197 delete root_->view_manager();
187 } else { 198 } else {
188 delete this; 199 delete this;
189 } 200 }
190 } 201 }
191 202
203 void HTMLDocument::AddObserver(HTMLDocument::Observer* observer) {
204 observers_.AddObserver(observer);
205 }
206
207 void HTMLDocument::RemoveObserver(HTMLDocument::Observer* observer) {
208 observers_.RemoveObserver(observer);
209 }
210
192 HTMLDocument::~HTMLDocument() { 211 HTMLDocument::~HTMLDocument() {
193 delete_callback_.Run(this); 212 delete_callback_.Run(this);
194 213
195 STLDeleteElements(&ax_providers_); 214 STLDeleteElements(&ax_providers_);
196 STLDeleteElements(&ax_provider_requests_); 215 STLDeleteElements(&ax_provider_requests_);
197 216
198 if (web_view_) 217 if (web_view_)
199 web_view_->close(); 218 web_view_->close();
200 if (root_) 219 if (root_)
201 root_->RemoveObserver(this); 220 root_->RemoveObserver(this);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 259
241 // TODO(yzshen): http://crbug.com/498986 Creating DevToolsAgentImpl instances 260 // TODO(yzshen): http://crbug.com/498986 Creating DevToolsAgentImpl instances
242 // causes html_viewer_apptests flakiness currently. Before we fix that we 261 // causes html_viewer_apptests flakiness currently. Before we fix that we
243 // cannot enable remote debugging (which is required by Telemetry tests) on 262 // cannot enable remote debugging (which is required by Telemetry tests) on
244 // the bots. 263 // the bots.
245 if (EnableRemoteDebugging()) { 264 if (EnableRemoteDebugging()) {
246 devtools_agent_.reset( 265 devtools_agent_.reset(
247 new DevToolsAgentImpl(main_frame, html_document_app_->shell())); 266 new DevToolsAgentImpl(main_frame, html_document_app_->shell()));
248 } 267 }
249 268
269 stats_collection_controller_ =
270 StatsCollectionController::Install(this, html_document_app_);
271
250 GURL url(response->url); 272 GURL url(response->url);
251 273
252 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData; 274 WebURLRequestExtraData* extra_data = new WebURLRequestExtraData;
253 extra_data->synthetic_response = response.Pass(); 275 extra_data->synthetic_response = response.Pass();
254 276
255 blink::WebURLRequest web_request; 277 blink::WebURLRequest web_request;
256 web_request.initialize(); 278 web_request.initialize();
257 web_request.setURL(url); 279 web_request.setURL(url);
258 web_request.setExtraData(extra_data); 280 web_request.setExtraData(extra_data);
259 281
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 413
392 void HTMLDocument::didAddMessageToConsole( 414 void HTMLDocument::didAddMessageToConsole(
393 const blink::WebConsoleMessage& message, 415 const blink::WebConsoleMessage& message,
394 const blink::WebString& source_name, 416 const blink::WebString& source_name,
395 unsigned source_line, 417 unsigned source_line,
396 const blink::WebString& stack_trace) { 418 const blink::WebString& stack_trace) {
397 VLOG(1) << "[" << source_name.utf8() << "(" << source_line << ")] " 419 VLOG(1) << "[" << source_name.utf8() << "(" << source_line << ")] "
398 << message.text.utf8(); 420 << message.text.utf8();
399 } 421 }
400 422
423 void HTMLDocument::didStartLoading(bool toDifferentDocument) {
424 // TODO(msw): Nix observer pattern, use stats_collection_controller_ directly?
425 FOR_EACH_OBSERVER(HTMLDocument::Observer, observers_, DidStartLoading());
426 }
427
428 void HTMLDocument::didStopLoading() {
429 // TODO(msw): Nix observer pattern, use stats_collection_controller_ directly?
430 FOR_EACH_OBSERVER(HTMLDocument::Observer, observers_, DidStopLoading());
431 }
432
433 void HTMLDocument::didHandleOnloadEvents(blink::WebLocalFrame* frame) {
434 if (stats_collection_controller_)
435 stats_collection_controller_->DidHandleOnloadEvents(base::Time::Now());
436 }
437
401 void HTMLDocument::didFinishLoad(blink::WebLocalFrame* frame) { 438 void HTMLDocument::didFinishLoad(blink::WebLocalFrame* frame) {
402 // TODO(msw): Notify AxProvider clients of updates on child frame loads. 439 // TODO(msw): Notify AxProvider clients of updates on child frame loads.
403 did_finish_load_ = true; 440 did_finish_load_ = true;
404 // Bind any pending AxProviderImpl interface requests. 441 // Bind any pending AxProviderImpl interface requests.
405 for (auto it : ax_provider_requests_) 442 for (auto it : ax_provider_requests_)
406 ax_providers_.insert(new AxProviderImpl(web_view_, it->Pass())); 443 ax_providers_.insert(new AxProviderImpl(web_view_, it->Pass()));
407 STLDeleteElements(&ax_provider_requests_); 444 STLDeleteElements(&ax_provider_requests_);
408 } 445 }
409 446
410 void HTMLDocument::didNavigateWithinPage( 447 void HTMLDocument::didNavigateWithinPage(
411 blink::WebLocalFrame* frame, 448 blink::WebLocalFrame* frame,
412 const blink::WebHistoryItem& history_item, 449 const blink::WebHistoryItem& history_item,
413 blink::WebHistoryCommitType commit_type) { 450 blink::WebHistoryCommitType commit_type) {
414 if (navigator_host_.get()) 451 if (navigator_host_.get())
415 navigator_host_->DidNavigateLocally(history_item.urlString().utf8()); 452 navigator_host_->DidNavigateLocally(history_item.urlString().utf8());
416 } 453 }
417 454
455 void HTMLDocument::didFirstVisuallyNonEmptyLayout(blink::WebLocalFrame* frame) {
456 if (stats_collection_controller_) {
457 stats_collection_controller_->DidFirstVisuallyNonEmptyLayout(
458 base::Time::Now());
459 }
460 }
461
418 blink::WebEncryptedMediaClient* HTMLDocument::encryptedMediaClient() { 462 blink::WebEncryptedMediaClient* HTMLDocument::encryptedMediaClient() {
419 return global_state_->media_factory()->GetEncryptedMediaClient(); 463 return global_state_->media_factory()->GetEncryptedMediaClient();
420 } 464 }
421 465
422 void HTMLDocument::OnViewBoundsChanged(View* view, 466 void HTMLDocument::OnViewBoundsChanged(View* view,
423 const Rect& old_bounds, 467 const Rect& old_bounds,
424 const Rect& new_bounds) { 468 const Rect& new_bounds) {
425 DCHECK_EQ(view, root_); 469 DCHECK_EQ(view, root_);
426 UpdateWebviewSizeFromViewSize(); 470 UpdateWebviewSizeFromViewSize();
427 } 471 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 512
469 void HTMLDocument::UpdateFocus() { 513 void HTMLDocument::UpdateFocus() {
470 if (!web_view_) 514 if (!web_view_)
471 return; 515 return;
472 bool is_focused = root_ && root_->HasFocus(); 516 bool is_focused = root_ && root_->HasFocus();
473 web_view_->setFocus(is_focused); 517 web_view_->setFocus(is_focused);
474 web_view_->setIsActive(is_focused); 518 web_view_->setIsActive(is_focused);
475 } 519 }
476 520
477 } // namespace html_viewer 521 } // namespace html_viewer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698