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

Side by Side Diff: chrome/browser/page_load_metrics/observers/resource_tracking_page_load_metrics_observer.cc

Issue 2857063002: Add a way to send the resource percentage signal to the RC. (Closed)
Patch Set: Turn off other metrics which might require tab helpers when background loading Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/page_load_metrics/observers/resource_tracking_page_load _metrics_observer.h" 5 #include "chrome/browser/page_load_metrics/observers/resource_tracking_page_load _metrics_observer.h"
6 6
7 #include "chrome/browser/offline_pages/offliner_user_data.h"
8 #include "components/offline_pages/core/background/request_coordinator.h"
9 #include "components/offline_pages/core/background/resource_data_type.h"
10
11 namespace {
12
13 // Since the content::ResourceType type is not generally available everywhere
14 // in chrome, we translate it to a type that can be used from code in the
15 // components subtree.
16 offline_pages::ResourceDataType ConvertResourceTypeToResourceDataType(
17 content::ResourceType type) {
18 switch (type) {
19 case (content::RESOURCE_TYPE_MAIN_FRAME):
20 case (content::RESOURCE_TYPE_SUB_FRAME):
21 return offline_pages::ResourceDataType::TEXT_HTML;
22 case (content::RESOURCE_TYPE_STYLESHEET):
23 return offline_pages::ResourceDataType::TEXT_CSS;
24 case (content::RESOURCE_TYPE_SCRIPT):
25 return offline_pages::ResourceDataType::TEXT_SCRIPT;
26 case (content::RESOURCE_TYPE_IMAGE):
27 return offline_pages::ResourceDataType::IMAGE;
28 case (content::RESOURCE_TYPE_MEDIA):
29 return offline_pages::ResourceDataType::MEDIA;
30 case (content::RESOURCE_TYPE_XHR):
31 return offline_pages::ResourceDataType::XHR;
32 default:
33 return offline_pages::ResourceDataType::OTHER;
34 }
35 }
36 } // namespace
37
7 namespace page_load_metrics { 38 namespace page_load_metrics {
8 39
9 ResourceTrackingPageLoadMetricsObserver:: 40 ResourceTrackingPageLoadMetricsObserver::
10 ResourceTrackingPageLoadMetricsObserver() 41 ResourceTrackingPageLoadMetricsObserver(
11 : started_count_(0), completed_count_(0) {} 42 offline_pages::ResourceTrackerObserver* request_coordinator)
43 : started_count_(0),
44 completed_count_(0),
45 request_coordinator_(request_coordinator) {}
12 ResourceTrackingPageLoadMetricsObserver:: 46 ResourceTrackingPageLoadMetricsObserver::
13 ~ResourceTrackingPageLoadMetricsObserver() {} 47 ~ResourceTrackingPageLoadMetricsObserver() {}
14 48
15 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource( 49 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource(
16 const ExtraRequestStartInfo& extra_request_start_info) { 50 const ExtraRequestStartInfo& extra_request_start_info) {
17 // TODO(petewiL): Store this by type. 51 // TODO(petewil): Store this by type. Until we do, only look at images.
18 ++started_count_; 52 if (extra_request_start_info.resource_type == content::RESOURCE_TYPE_IMAGE) {
53 ++started_count_;
54 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_,
55 completed_count_);
56 }
19 } 57 }
20 58
21 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource( 59 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource(
22 const ExtraRequestCompleteInfo& extra_request_complete_info) { 60 const ExtraRequestCompleteInfo& extra_request_complete_info) {
23 // TODO(petewil): Check to see if the type of the request changed. If it did, 61 // TODO(petewil): Check to see if the type of the request changed. If it did,
24 // update the old and new types for the started type. Then update by type for 62 // update the old and new types for the started type. Then update by type for
25 // the completed type. 63 // the completed type. Maybe we can just skip that, and count XHR as its own
26 ++completed_count_; 64 // type.
65 if (extra_request_complete_info.resource_type ==
66 content::RESOURCE_TYPE_IMAGE) {
67 ++completed_count_;
68 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_,
Dmitry Titov 2017/05/18 02:28:10 The started_count_ and completed_count_ may not be
Pete Williamson 2017/05/24 01:01:50 Done.
69 completed_count_);
70 }
27 } 71 }
28 72
29 void ResourceTrackingPageLoadMetricsObserver::GetCountsForTypeForTesting( 73 PageLoadMetricsObserver::ObservePolicy
74 ResourceTrackingPageLoadMetricsObserver::OnCommit(
75 content::NavigationHandle* navigation_handle) {
76 if (navigation_handle == nullptr)
Bryan McQuade 2017/05/23 05:00:01 nav handle should never be null here - have you en
Pete Williamson 2017/05/24 01:01:50 Never encountered it, just programming defensively
77 return PageLoadMetricsObserver::STOP_OBSERVING;
78
79 offline_pages::Offliner* offliner =
Dmitry Titov 2017/05/18 02:28:10 Instead of passing a RequestCoordinator to constru
Pete Williamson 2017/05/24 01:01:50 Done.
80 offline_pages::OfflinerUserData::OfflinerFromWebContents(
81 navigation_handle->GetWebContents());
82 if (offliner)
83 return PageLoadMetricsObserver::CONTINUE_OBSERVING;
84
85 return PageLoadMetricsObserver::STOP_OBSERVING;
86 }
87
88 void ResourceTrackingPageLoadMetricsObserver::InformObservers(
30 const content::ResourceType type, 89 const content::ResourceType type,
31 int64_t* started_count, 90 int64_t started_count,
32 int64_t* completed_count) { 91 int64_t completed_count) {
33 if (started_count != nullptr) 92 if (request_coordinator_) {
34 *started_count = started_count_; 93 offline_pages::ResourceDataType converted_type =
35 if (completed_count != nullptr) 94 ConvertResourceTypeToResourceDataType(type);
36 *completed_count = completed_count_; 95 request_coordinator_->ObserveResourceTracking(converted_type, started_count,
96 completed_count);
97 }
37 } 98 }
38 99
39 } // namespace page_load_metrics 100 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698