Index: chrome/browser/offline_pages/background_loader_offliner.cc |
diff --git a/chrome/browser/offline_pages/background_loader_offliner.cc b/chrome/browser/offline_pages/background_loader_offliner.cc |
index 6cc5f3d0fd5de7c4d71000927dc4948a3f6a4bcc..0b7d3143e5db42b33595b9b5bbcac9f6ee7857fe 100644 |
--- a/chrome/browser/offline_pages/background_loader_offliner.cc |
+++ b/chrome/browser/offline_pages/background_loader_offliner.cc |
@@ -12,6 +12,8 @@ |
#include "base/time/time.h" |
#include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
#include "chrome/browser/android/offline_pages/offliner_helper.h" |
+#include "chrome/browser/offline_pages/offliner_user_data.h" |
+#include "chrome/browser/page_load_metrics/page_load_metrics_initialize.h" |
#include "chrome/browser/profiles/profile.h" |
#include "components/offline_pages/core/background/offliner_policy.h" |
#include "components/offline_pages/core/background/save_page_request.h" |
@@ -33,28 +35,6 @@ const char kContentTransferEncodingBinary[] = |
"Content-Transfer-Encoding: binary"; |
const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1"; |
-class OfflinerData : public content::WebContentsUserData<OfflinerData> { |
- public: |
- static void AddToWebContents(content::WebContents* webcontents, |
- BackgroundLoaderOffliner* offliner) { |
- DCHECK(offliner); |
- webcontents->SetUserData(UserDataKey(), std::unique_ptr<OfflinerData>( |
- new OfflinerData(offliner))); |
- } |
- |
- explicit OfflinerData(BackgroundLoaderOffliner* offliner) { |
- offliner_ = offliner; |
- } |
- BackgroundLoaderOffliner* offliner() { return offliner_; } |
- |
- private: |
- // The offliner that the WebContents is attached to. The offliner owns the |
- // Delegate which owns the WebContents that this data is attached to. |
- // Therefore, its lifetime should exceed that of the WebContents, so this |
- // should always be non-null. |
- BackgroundLoaderOffliner* offliner_; |
-}; |
- |
std::string AddHistogramSuffix(const ClientId& client_id, |
const char* histogram_name) { |
if (client_id.name_space.empty()) { |
@@ -105,9 +85,12 @@ BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} |
// static |
BackgroundLoaderOffliner* BackgroundLoaderOffliner::FromWebContents( |
content::WebContents* contents) { |
- OfflinerData* data = OfflinerData::FromWebContents(contents); |
- if (data) |
- return data->offliner(); |
+ Offliner* offliner = OfflinerUserData::OfflinerFromWebContents(contents); |
+ |
+ // Today we only have one kind of offliner that uses OfflinerUserData. If we |
+ // add other types, revisit this cast. |
+ if (offliner) |
+ return static_cast<BackgroundLoaderOffliner*>(offliner); |
return nullptr; |
} |
@@ -238,6 +221,19 @@ bool BackgroundLoaderOffliner::HandleTimeout(int64_t request_id) { |
return false; |
} |
+void BackgroundLoaderOffliner::ObserveResourceTracking( |
+ const Offliner::ResourceDataType type, |
+ int64_t started_count, |
+ int64_t completed_count) { |
+ // Add the signal to extra data, and use for tracking. |
+ if (type == ResourceDataType::IMAGE) { |
+ // TODO(petewil): Use actual signal type instead of hardcoding name to |
+ // image. |
+ signal_data_.SetDouble("StartedImages", started_count); |
+ signal_data_.SetDouble("CompletedImages", completed_count); |
+ } |
+} |
+ |
void BackgroundLoaderOffliner::MarkLoadStartTime() { |
load_start_time_ = base::TimeTicks::Now(); |
} |
@@ -465,7 +461,12 @@ void BackgroundLoaderOffliner::ResetLoader() { |
void BackgroundLoaderOffliner::AttachObservers() { |
content::WebContents* contents = loader_->web_contents(); |
content::WebContentsObserver::Observe(contents); |
- OfflinerData::AddToWebContents(contents, this); |
+ OfflinerUserData::AddToWebContents(contents, this); |
+ |
+ // Attach the metrics observers to the web contents so we can get resoure |
+ // loading signals. |
+ chrome::InitializePageLoadMetricsForWebContents( |
+ contents, true /* background loading */); |
} |
void BackgroundLoaderOffliner::OnApplicationStateChange( |
@@ -494,5 +495,3 @@ void BackgroundLoaderOffliner::AddLoadingSignal(const char* signal_name) { |
} |
} // namespace offline_pages |
- |
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); |