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

Side by Side Diff: chrome/browser/android/offline_pages/background_loader_offliner.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/offline_pages/background_loader_offliner.h" 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (save_state_ == NONE) { 231 if (save_state_ == NONE) {
232 did_snapshot_on_last_retry_ = true; 232 did_snapshot_on_last_retry_ = true;
233 StartSnapshot(); 233 StartSnapshot();
234 } 234 }
235 return true; 235 return true;
236 } 236 }
237 } 237 }
238 return false; 238 return false;
239 } 239 }
240 240
241 void BackgroundLoaderOffliner::ObserveResourceTracking(
242 const ResourceDataType type,
243 int64_t started_count,
244 int64_t completed_count) {
245 // Add the signal to extra data, and use for tracking.
246 if (type == ResourceDataType::IMAGE)
247 AddResourceSignal(type, started_count, completed_count);
248 }
249
241 void BackgroundLoaderOffliner::MarkLoadStartTime() { 250 void BackgroundLoaderOffliner::MarkLoadStartTime() {
242 load_start_time_ = base::TimeTicks::Now(); 251 load_start_time_ = base::TimeTicks::Now();
243 } 252 }
244 253
245 void BackgroundLoaderOffliner::DocumentAvailableInMainFrame() { 254 void BackgroundLoaderOffliner::DocumentAvailableInMainFrame() {
246 snapshot_controller_->DocumentAvailableInMainFrame(); 255 snapshot_controller_->DocumentAvailableInMainFrame();
247 is_low_bar_met_ = true; 256 is_low_bar_met_ = true;
248 257
249 // Add this signal to signal_data_. 258 // Add this signal to signal_data_.
250 AddLoadingSignal("DocumentAvailableInMainFrame"); 259 AddLoadingSignal("DocumentAvailableInMainFrame");
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 base::TimeTicks current_time = base::TimeTicks::Now(); 495 base::TimeTicks current_time = base::TimeTicks::Now();
487 base::TimeDelta delay_so_far = current_time - load_start_time_; 496 base::TimeDelta delay_so_far = current_time - load_start_time_;
488 // We would prefer to use int64_t here, but JSON does not support that type. 497 // We would prefer to use int64_t here, but JSON does not support that type.
489 // Given the choice between int and double, we choose to implicitly convert to 498 // Given the choice between int and double, we choose to implicitly convert to
490 // a double since it maintains more precision (we can get a longer time in 499 // a double since it maintains more precision (we can get a longer time in
491 // milliseconds than we can with a 2 bit int, 53 bits vs 32). 500 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
492 double delay = delay_so_far.InMilliseconds(); 501 double delay = delay_so_far.InMilliseconds();
493 signal_data_.SetDouble(signal_name, delay); 502 signal_data_.SetDouble(signal_name, delay);
494 } 503 }
495 504
505 void BackgroundLoaderOffliner::AddResourceSignal(const ResourceDataType type,
506 int64_t started_count,
507 int64_t completed_count) {
508 double percentage = 100.0 * static_cast<double>(completed_count) /
509 static_cast<double>(started_count);
510 // TODO(petewil): Use actual signal type instead of hardcoding name to image.
511 signal_data_.SetDouble("ImagePercentage", percentage);
512 signal_data_.SetDouble("StartedImages", started_count);
513 signal_data_.SetDouble("CompletedImages", completed_count);
514 }
515
496 } // namespace offline_pages 516 } // namespace offline_pages
497 517
498 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 518 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698