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

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: CR Feedback per Dimich, BMcQuade, and CSHarrison 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/offliner.h"
9
10 namespace {
11
12 // Since the content::ResourceType type is not generally available everywhere
13 // in chrome, we translate it to a type that can be used from code in the
14 // components subtree.
15 offline_pages::Offliner::ResourceDataType ConvertResourceTypeToResourceDataType(
16 content::ResourceType type) {
17 switch (type) {
18 case (content::RESOURCE_TYPE_MAIN_FRAME):
19 case (content::RESOURCE_TYPE_SUB_FRAME):
20 return offline_pages::Offliner::ResourceDataType::TEXT_HTML;
21 case (content::RESOURCE_TYPE_STYLESHEET):
22 return offline_pages::Offliner::ResourceDataType::TEXT_CSS;
23 case (content::RESOURCE_TYPE_SCRIPT):
24 return offline_pages::Offliner::ResourceDataType::TEXT_SCRIPT;
25 case (content::RESOURCE_TYPE_IMAGE):
26 return offline_pages::Offliner::ResourceDataType::IMAGE;
27 case (content::RESOURCE_TYPE_MEDIA):
28 return offline_pages::Offliner::ResourceDataType::MEDIA;
29 case (content::RESOURCE_TYPE_XHR):
30 return offline_pages::Offliner::ResourceDataType::XHR;
31 default:
32 return offline_pages::Offliner::ResourceDataType::OTHER;
33 }
34 }
35 } // namespace
36
7 namespace page_load_metrics { 37 namespace page_load_metrics {
8 38
9 ResourceTrackingPageLoadMetricsObserver:: 39 ResourceTrackingPageLoadMetricsObserver::
10 ResourceTrackingPageLoadMetricsObserver() 40 ResourceTrackingPageLoadMetricsObserver()
11 : started_count_(0), completed_count_(0) {} 41 : started_count_(0), completed_count_(0) {}
12 ResourceTrackingPageLoadMetricsObserver:: 42 ResourceTrackingPageLoadMetricsObserver::
13 ~ResourceTrackingPageLoadMetricsObserver() {} 43 ~ResourceTrackingPageLoadMetricsObserver() {}
14 44
15 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource( 45 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource(
16 const ExtraRequestStartInfo& extra_request_start_info) { 46 const ExtraRequestStartInfo& extra_request_start_info) {
17 // TODO(petewiL): Store this by type. 47 // TODO(petewil): Store this by type. Until we do, only look at images.
Dmitry Titov 2017/05/24 23:09:34 Why limit to images here? This looks like a genera
18 ++started_count_; 48 if (extra_request_start_info.resource_type == content::RESOURCE_TYPE_IMAGE) {
Dmitry Titov 2017/05/24 23:09:34 Between next 3 lines, content::RESOURCE_TYPE_IMAGE
49 ++started_count_;
50 InformClient(content::ResourceType::RESOURCE_TYPE_IMAGE);
51 }
19 } 52 }
20 53
21 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource( 54 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource(
22 const ExtraRequestCompleteInfo& extra_request_complete_info) { 55 const ExtraRequestCompleteInfo& extra_request_complete_info) {
23 // TODO(petewil): Check to see if the type of the request changed. If it did, 56 // 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 57 // update the old and new types for the started type. Then update by type for
25 // the completed type. 58 // the completed type. Maybe we can just skip that, and count XHR as its own
26 ++completed_count_; 59 // type.
60 if (extra_request_complete_info.resource_type ==
61 content::RESOURCE_TYPE_IMAGE) {
Dmitry Titov 2017/05/24 23:09:35 formatting. git cl format this CL please.
62 ++completed_count_;
63 InformClient(content::ResourceType::RESOURCE_TYPE_IMAGE);
64 }
27 } 65 }
28 66
29 void ResourceTrackingPageLoadMetricsObserver::GetCountsForTypeForTesting( 67 PageLoadMetricsObserver::ObservePolicy
30 const content::ResourceType type, 68 ResourceTrackingPageLoadMetricsObserver::OnCommit(
31 int64_t* started_count, 69 content::NavigationHandle* navigation_handle) {
32 int64_t* completed_count) { 70 DCHECK(navigation_handle != nullptr);
33 if (started_count != nullptr) 71
34 *started_count = started_count_; 72 offline_pages::Offliner* offliner =
35 if (completed_count != nullptr) 73 offline_pages::OfflinerUserData::OfflinerFromWebContents(
36 *completed_count = completed_count_; 74 navigation_handle->GetWebContents());
75 if (offliner) {
76 offliner_ = offliner;
77 return PageLoadMetricsObserver::CONTINUE_OBSERVING;
78 }
79
80 return PageLoadMetricsObserver::STOP_OBSERVING;
81 }
82
83 void ResourceTrackingPageLoadMetricsObserver::InformClient(
84 const content::ResourceType type) {
85 if (offliner_) {
86 // TODO: Also rename ResourceTrackerObserver -> ResourceTrackerClient
87 offline_pages::Offliner::ResourceDataType converted_type =
88 ConvertResourceTypeToResourceDataType(type);
89 offliner_->ObserveResourceTracking(converted_type, started_count_,
90 completed_count_);
91 }
37 } 92 }
38 93
39 } // namespace page_load_metrics 94 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698