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

Unified Diff: chrome/browser/offline_pages/background_loader_offliner.cc

Issue 2857063002: Add a way to send the resource percentage signal to the RC. (Closed)
Patch Set: Move OfflinerUserData to its new home in chrome/browser/offline_pages 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 side-by-side diff with in-line comments
Download patch
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..2fbded36be60c571becc27c22e336c430ac62319 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);
chili 2017/05/17 18:00:07 just out of curiosity, what would happen if you do
Pete Williamson 2017/05/24 01:01:50 You get a nullptr with a C++ type "BackgroundLoade
return nullptr;
}
@@ -238,6 +221,15 @@ bool BackgroundLoaderOffliner::HandleTimeout(int64_t request_id) {
return false;
}
+void BackgroundLoaderOffliner::ObserveResourceTracking(
+ const ResourceDataType type,
+ int64_t started_count,
+ int64_t completed_count) {
+ // Add the signal to extra data, and use for tracking.
+ if (type == ResourceDataType::IMAGE)
+ AddResourceSignal(type, started_count, completed_count);
+}
+
void BackgroundLoaderOffliner::MarkLoadStartTime() {
load_start_time_ = base::TimeTicks::Now();
}
@@ -465,7 +457,11 @@ 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);
chili 2017/05/17 18:00:07 Do we want ALL the metrics observers? Assuming the
Charlie Harrison 2017/05/17 18:30:31 +1 can you explain the consequences of this change
RyanSturm 2017/05/17 18:36:58 I believe the navigation should be entirely in the
RyanSturm 2017/05/17 18:47:54 1 more thing. Is the background offliner a replace
Pete Williamson 2017/05/17 19:50:07 Chili: We do want to use several metrics observers
RyanSturm 2017/05/17 19:54:32 WRT to point 2. My question was a little more sub
Charlie Harrison 2017/05/17 19:59:07 Most observers don't want to be notified of preren
Pete Williamson 2017/05/17 20:04:57 OK, let me clarify a bit and see if that helps: To
Pete Williamson 2017/05/17 20:09:08 CHarrison: Ah, I didn't realize that some observer
Charlie Harrison 2017/05/17 20:14:30 Yeah I think it makes sense to align as closely wi
Pete Williamson 2017/05/17 22:01:15 CSHarrison: Done.
Pete Williamson 2017/05/24 01:01:50 We only want the ones we use, and InitializePLMFWC
}
void BackgroundLoaderOffliner::OnApplicationStateChange(
@@ -493,6 +489,15 @@ void BackgroundLoaderOffliner::AddLoadingSignal(const char* signal_name) {
signal_data_.SetDouble(signal_name, delay);
}
-} // namespace offline_pages
+void BackgroundLoaderOffliner::AddResourceSignal(const ResourceDataType type,
+ int64_t started_count,
+ int64_t completed_count) {
+ double percentage = 100.0 * static_cast<double>(completed_count) /
+ static_cast<double>(started_count);
+ // TODO(petewil): Use actual signal type instead of hardcoding name to image.
+ signal_data_.SetDouble("ImagePercentage", percentage);
+ signal_data_.SetDouble("StartedImages", started_count);
+ signal_data_.SetDouble("CompletedImages", completed_count);
+}
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
+} // namespace offline_pages
« no previous file with comments | « chrome/browser/offline_pages/background_loader_offliner.h ('k') | chrome/browser/offline_pages/offliner_user_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698