Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | |
| 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::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::ResourceDataType::TEXT_HTML; | |
| 21 case (content::RESOURCE_TYPE_STYLESHEET): | |
| 22 return offline_pages::ResourceDataType::TEXT_CSS; | |
| 23 case (content::RESOURCE_TYPE_SCRIPT): | |
| 24 return offline_pages::ResourceDataType::TEXT_SCRIPT; | |
| 25 case (content::RESOURCE_TYPE_IMAGE): | |
| 26 return offline_pages::ResourceDataType::IMAGE; | |
| 27 case (content::RESOURCE_TYPE_MEDIA): | |
| 28 return offline_pages::ResourceDataType::MEDIA; | |
| 29 case (content::RESOURCE_TYPE_XHR): | |
| 30 return offline_pages::ResourceDataType::XHR; | |
| 31 default: | |
| 32 return offline_pages::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 offline_pages::ResourceTrackerObserver* request_coordinator) |
| 42 : started_count_(0), | |
| 43 completed_count_(0), | |
| 44 request_coordinator_(request_coordinator) {} | |
| 12 ResourceTrackingPageLoadMetricsObserver:: | 45 ResourceTrackingPageLoadMetricsObserver:: |
| 13 ~ResourceTrackingPageLoadMetricsObserver() {} | 46 ~ResourceTrackingPageLoadMetricsObserver() {} |
| 14 | 47 |
| 15 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource( | 48 void ResourceTrackingPageLoadMetricsObserver::OnStartedResource( |
| 16 const ExtraRequestStartInfo& extra_request_start_info) { | 49 const ExtraRequestStartInfo& extra_request_start_info) { |
| 17 // TODO(petewiL): Store this by type. | 50 // TODO(petewiL): Store this by type. Until we do, only look at images. |
|
RyanSturm
2017/05/10 19:45:35
nit: s/petewiL/petewil/ (capitalized L) unless thi
Pete Williamson
2017/05/10 21:07:14
Done.
| |
| 18 ++started_count_; | 51 if (extra_request_start_info.resource_type == content::RESOURCE_TYPE_IMAGE) { |
|
RyanSturm
2017/05/10 19:45:35
Just a thought, you might want to convert the type
Pete Williamson
2017/05/10 21:07:14
I'd like to change it later with the next changeli
| |
| 52 ++started_count_; | |
| 53 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_, | |
| 54 completed_count_); | |
| 55 } | |
| 19 } | 56 } |
| 20 | 57 |
| 21 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource( | 58 void ResourceTrackingPageLoadMetricsObserver::OnLoadedResource( |
| 22 const ExtraRequestCompleteInfo& extra_request_complete_info) { | 59 const ExtraRequestCompleteInfo& extra_request_complete_info) { |
| 23 // TODO(petewil): Check to see if the type of the request changed. If it did, | 60 // 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 | 61 // update the old and new types for the started type. Then update by type for |
| 25 // the completed type. | 62 // the completed type. Maybe we can just skip that, and count XHR as its own |
| 26 ++completed_count_; | 63 // type. |
| 64 if (extra_request_complete_info.resource_type == | |
| 65 content::RESOURCE_TYPE_IMAGE) { | |
| 66 ++completed_count_; | |
| 67 InformObservers(content::ResourceType::RESOURCE_TYPE_IMAGE, started_count_, | |
| 68 completed_count_); | |
| 69 } | |
| 27 } | 70 } |
| 28 | 71 |
| 29 void ResourceTrackingPageLoadMetricsObserver::GetCountsForTypeForTesting( | 72 void ResourceTrackingPageLoadMetricsObserver::InformObservers( |
| 30 const content::ResourceType type, | 73 const content::ResourceType type, |
| 31 int64_t* started_count, | 74 int64_t started_count, |
| 32 int64_t* completed_count) { | 75 int64_t completed_count) { |
| 33 if (started_count != nullptr) | 76 if (request_coordinator_) { |
| 34 *started_count = started_count_; | 77 offline_pages::ResourceDataType converted_type = |
| 35 if (completed_count != nullptr) | 78 ConvertResourceTypeToResourceDataType(type); |
| 36 *completed_count = completed_count_; | 79 request_coordinator_->ObserveResourceTracking(converted_type, started_count, |
| 80 completed_count); | |
| 81 } | |
| 37 } | 82 } |
| 38 | 83 |
| 39 } // namespace page_load_metrics | 84 } // namespace page_load_metrics |
| OLD | NEW |