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

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, fix unit test. 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 "components/offline_pages/core/background/request_coordinator.h"
8 #include "components/offline_pages/core/background/resource_data_type.h"
9 #include "content/public/common/resource_type.h"
RyanSturm 2017/05/10 18:30:13 resource_type.h is included in the header already.
Pete Williamson 2017/05/10 19:00:52 OK removed (My original thinking was that I should
10
11 namespace {
12 offline_pages::ResourceDataType ConvertResourceTypeToResourceDataType(
RyanSturm 2017/05/10 18:30:13 nit: A short method comment here would be good.
Pete Williamson 2017/05/10 19:00:52 Done.
13 content::ResourceType type) {
14 switch (type) {
15 case (content::RESOURCE_TYPE_MAIN_FRAME):
16 return offline_pages::ResourceDataType::TEXT_HTML;
17 case (content::RESOURCE_TYPE_SUB_FRAME):
18 return offline_pages::ResourceDataType::TEXT_HTML;
19 case (content::RESOURCE_TYPE_STYLESHEET):
20 return offline_pages::ResourceDataType::TEXT_CSS;
21 case (content::RESOURCE_TYPE_SCRIPT):
22 return offline_pages::ResourceDataType::TEXT_SCRIPT;
23 case (content::RESOURCE_TYPE_IMAGE):
24 return offline_pages::ResourceDataType::IMAGE;
25 case (content::RESOURCE_TYPE_FONT_RESOURCE):
26 return offline_pages::ResourceDataType::OTHER;
RyanSturm 2017/05/10 18:30:13 Can you group these by return value? e.g.: case (
Pete Williamson 2017/05/10 19:00:52 Done.
27 case (content::RESOURCE_TYPE_SUB_RESOURCE):
28 return offline_pages::ResourceDataType::OTHER;
29 case (content::RESOURCE_TYPE_OBJECT):
30 return offline_pages::ResourceDataType::OTHER;
31 case (content::RESOURCE_TYPE_MEDIA):
32 return offline_pages::ResourceDataType::MEDIA;
33 case (content::RESOURCE_TYPE_WORKER):
34 return offline_pages::ResourceDataType::OTHER;
35 case (content::RESOURCE_TYPE_SHARED_WORKER):
36 return offline_pages::ResourceDataType::OTHER;
37 case (content::RESOURCE_TYPE_PREFETCH):
38 return offline_pages::ResourceDataType::OTHER;
39 case (content::RESOURCE_TYPE_FAVICON):
40 return offline_pages::ResourceDataType::OTHER;
41 case (content::RESOURCE_TYPE_XHR):
42 return offline_pages::ResourceDataType::XHR;
43 case (content::RESOURCE_TYPE_PING):
44 return offline_pages::ResourceDataType::OTHER;
45 case (content::RESOURCE_TYPE_SERVICE_WORKER):
46 return offline_pages::ResourceDataType::OTHER;
47 case (content::RESOURCE_TYPE_CSP_REPORT):
48 return offline_pages::ResourceDataType::OTHER;
49 case (content::RESOURCE_TYPE_PLUGIN_RESOURCE):
50 return offline_pages::ResourceDataType::OTHER;
51 default:
52 return offline_pages::ResourceDataType::OTHER;
53 }
54 }
55 } // namespace
56
7 namespace page_load_metrics { 57 namespace page_load_metrics {
8 58
9 ResourceTrackingPageLoadMetricsObserver:: 59 ResourceTrackingPageLoadMetricsObserver::
10 ResourceTrackingPageLoadMetricsObserver() 60 ResourceTrackingPageLoadMetricsObserver(
11 : started_count_(0), completed_count_(0) {} 61 offline_pages::ResourceTrackerObserver* request_coordinator)
62 : started_count_(0),
63 completed_count_(0),
64 request_coordinator_(request_coordinator) {}
12 ResourceTrackingPageLoadMetricsObserver:: 65 ResourceTrackingPageLoadMetricsObserver::
13 ~ResourceTrackingPageLoadMetricsObserver() {} 66 ~ResourceTrackingPageLoadMetricsObserver() {}
14 67
15 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource( 68 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource(
16 const ExtraRequestStartInfo& extra_request_start_info) { 69 const ExtraRequestStartInfo& extra_request_start_info) {
17 // TODO(petewiL): Store this by type. 70 DVLOG(0) << "@@@@@@ type " << extra_request_start_info.resource_type << " "
RyanSturm 2017/05/10 18:30:13 Is this log statement needed here?
Pete Williamson 2017/05/10 19:00:52 Oops, I forgot to remove these. Gone now.
18 ++started_count_; 71 << __func__;
72 // TODO(petewiL): Store this by type. Until we do, only look at images.
73 if (extra_request_start_info.resource_type == content::RESOURCE_TYPE_IMAGE) {
74 ++started_count_;
75 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_,
76 completed_count_);
77 }
19 } 78 }
20 79
21 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource( 80 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource(
22 const ExtraRequestCompleteInfo& extra_request_complete_info) { 81 const ExtraRequestCompleteInfo& extra_request_complete_info) {
23 // TODO(petewil): Check to see if the type of the request changed. If it did, 82 // 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 83 // update the old and new types for the started type. Then update by type for
25 // the completed type. 84 // the completed type. Maybe we can just skip that, and count XHR as its own
26 ++completed_count_; 85 // type.
86 DVLOG(0) << "@@@@@@ type " << extra_request_complete_info.resource_type << " "
RyanSturm 2017/05/10 18:30:13 is this log needed? same below
Pete Williamson 2017/05/10 19:00:52 Done.
87 << __func__;
88 if (extra_request_complete_info.resource_type ==
89 content::RESOURCE_TYPE_IMAGE) {
90 DVLOG(0) << "@@@@@@ incremeting completed count " << __func__;
91 ++completed_count_;
92 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_,
93 completed_count_);
94 }
27 } 95 }
28 96
29 void ResourceTrackingPageLoadMetricsObserver::GetCountsForTypeForTesting( 97 void ResourceTrackingPageLoadMetricsObserver::GetCountsForTypeForTesting(
30 const content::ResourceType type, 98 const content::ResourceType type,
31 int64_t* started_count, 99 int64_t* started_count,
32 int64_t* completed_count) { 100 int64_t* completed_count) {
33 if (started_count != nullptr) 101 if (started_count != nullptr)
34 *started_count = started_count_; 102 *started_count = started_count_;
35 if (completed_count != nullptr) 103 if (completed_count != nullptr)
36 *completed_count = completed_count_; 104 *completed_count = completed_count_;
37 } 105 }
38 106
107 void ResourceTrackingPageLoadMetricsObserver::InformObservers(
108 const content::ResourceType type,
109 int64_t started_count,
110 int64_t completed_count) {
111 if (request_coordinator_) {
112 offline_pages::ResourceDataType converted_type =
113 ConvertResourceTypeToResourceDataType(type);
114 request_coordinator_->ObserveResourceTracking(converted_type, started_count,
115 completed_count);
116 }
117 }
118
39 } // namespace page_load_metrics 119 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698