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

Side by Side Diff: chrome/browser/offline_pages/background_loader_offliner.cc

Issue 2903383003: Get network resource usage from ChromeResourceDispatcherHostDelegate (Closed)
Patch Set: CR feedback per FGorski Created 3 years, 6 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/offline_pages/background_loader_offliner.h" 5 #include "chrome/browser/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_functions.h" 9 #include "base/metrics/histogram_functions.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 std::unique_ptr<LoadTerminationListener> load_termination_listener) 99 std::unique_ptr<LoadTerminationListener> load_termination_listener)
100 : browser_context_(browser_context), 100 : browser_context_(browser_context),
101 offline_page_model_(offline_page_model), 101 offline_page_model_(offline_page_model),
102 policy_(policy), 102 policy_(policy),
103 load_termination_listener_(std::move(load_termination_listener)), 103 load_termination_listener_(std::move(load_termination_listener)),
104 save_state_(NONE), 104 save_state_(NONE),
105 page_load_state_(SUCCESS), 105 page_load_state_(SUCCESS),
106 network_bytes_(0LL), 106 network_bytes_(0LL),
107 is_low_bar_met_(false), 107 is_low_bar_met_(false),
108 did_snapshot_on_last_retry_(false), 108 did_snapshot_on_last_retry_(false),
109 started_count_(0LL),
110 completed_count_(0LL),
109 weak_ptr_factory_(this) { 111 weak_ptr_factory_(this) {
110 DCHECK(offline_page_model_); 112 DCHECK(offline_page_model_);
111 DCHECK(browser_context_); 113 DCHECK(browser_context_);
112 load_termination_listener_->set_offliner(this); 114 load_termination_listener_->set_offliner(this);
113 } 115 }
114 116
115 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} 117 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {}
116 118
117 // static 119 // static
118 BackgroundLoaderOffliner* BackgroundLoaderOffliner::FromWebContents( 120 BackgroundLoaderOffliner* BackgroundLoaderOffliner::FromWebContents(
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 RecordOffliningPreviewsUMA(pending_request_->client_id(), navigation_data); 343 RecordOffliningPreviewsUMA(pending_request_->client_id(), navigation_data);
342 } 344 }
343 345
344 void BackgroundLoaderOffliner::SetSnapshotControllerForTest( 346 void BackgroundLoaderOffliner::SetSnapshotControllerForTest(
345 std::unique_ptr<SnapshotController> controller) { 347 std::unique_ptr<SnapshotController> controller) {
346 snapshot_controller_ = std::move(controller); 348 snapshot_controller_ = std::move(controller);
347 } 349 }
348 void BackgroundLoaderOffliner::ObserveResourceLoading( 350 void BackgroundLoaderOffliner::ObserveResourceLoading(
349 ResourceLoadingObserver::ResourceDataType type, 351 ResourceLoadingObserver::ResourceDataType type,
350 bool started) { 352 bool started) {
351 // TODO(petewil) Not implemented yet. 353 // TODO(petewil): Use actual signal type instead of hardcoding name to
352 return; 354 // image.
355 // Add the signal to extra data, and use for tracking.
356 if (type == ResourceDataType::IMAGE) {
357 if (started) {
358 started_count_++;
359 signal_data_.SetDouble("StartedImages", started_count_);
360 } else {
361 completed_count_++;
362 signal_data_.SetDouble("CompletedImages", completed_count_);
363 }
364 }
353 } 365 }
354 366
355 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { 367 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) {
356 if (pending_request_ && save_state_ != SAVING) { 368 if (pending_request_ && save_state_ != SAVING) {
357 network_bytes_ += bytes; 369 network_bytes_ += bytes;
358 progress_callback_.Run(*pending_request_, network_bytes_); 370 progress_callback_.Run(*pending_request_, network_bytes_);
359 } 371 }
360 } 372 }
361 373
362 void BackgroundLoaderOffliner::StartSnapshot() { 374 void BackgroundLoaderOffliner::StartSnapshot() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 base::TimeDelta delay_so_far = current_time - load_start_time_; 528 base::TimeDelta delay_so_far = current_time - load_start_time_;
517 // We would prefer to use int64_t here, but JSON does not support that type. 529 // We would prefer to use int64_t here, but JSON does not support that type.
518 // Given the choice between int and double, we choose to implicitly convert to 530 // Given the choice between int and double, we choose to implicitly convert to
519 // a double since it maintains more precision (we can get a longer time in 531 // a double since it maintains more precision (we can get a longer time in
520 // milliseconds than we can with a 2 bit int, 53 bits vs 32). 532 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
521 double delay = delay_so_far.InMilliseconds(); 533 double delay = delay_so_far.InMilliseconds();
522 signal_data_.SetDouble(signal_name, delay); 534 signal_data_.SetDouble(signal_name, delay);
523 } 535 }
524 536
525 } // namespace offline_pages 537 } // namespace offline_pages
OLDNEW
« 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