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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader.cc

Issue 2857063002: Add a way to send the resource percentage signal to the RC. (Closed)
Patch Set: Turn off other metrics which might require tab helpers when background loading 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/prerendering_loader.h" 5 #include "chrome/browser/android/offline_pages/prerendering_loader.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 load_start_time_ = base::TimeTicks::Now(); 81 load_start_time_ = base::TimeTicks::Now();
82 } 82 }
83 83
84 void PrerenderingLoader::AddLoadingSignal(const char* signal_name) { 84 void PrerenderingLoader::AddLoadingSignal(const char* signal_name) {
85 base::TimeTicks current_time = base::TimeTicks::Now(); 85 base::TimeTicks current_time = base::TimeTicks::Now();
86 base::TimeDelta delay_so_far = current_time - load_start_time_; 86 base::TimeDelta delay_so_far = current_time - load_start_time_;
87 double delay = delay_so_far.InMilliseconds(); 87 double delay = delay_so_far.InMilliseconds();
88 signal_data_.SetDouble(signal_name, delay); 88 signal_data_.SetDouble(signal_name, delay);
89 } 89 }
90 90
91 void PrerenderingLoader::AddResourceSignal(const ResourceDataType type,
Dmitry Titov 2017/05/18 02:28:10 It is not clear why these are called "Add*" when t
Pete Williamson 2017/05/24 01:01:50 Moved the content into ObserverResourceTracking ev
92 int64_t started_count,
93 int64_t completed_count) {
94 double percentage = 100 * static_cast<double>(completed_count) /
95 static_cast<double>(started_count);
96 // TODO(petewil): Use actual signal type instead of hardcoding name to image.
97 signal_data_.SetDouble("ImagePercentage", percentage);
98 signal_data_.SetDouble("StartedImages", started_count);
99 signal_data_.SetDouble("CompletedImages", completed_count);
100 }
101
91 bool PrerenderingLoader::LoadPage(const GURL& url, 102 bool PrerenderingLoader::LoadPage(const GURL& url,
92 const LoadPageCallback& load_done_callback, 103 const LoadPageCallback& load_done_callback,
93 const ProgressCallback& progress_callback) { 104 const ProgressCallback& progress_callback) {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
95 if (!IsIdle()) { 106 if (!IsIdle()) {
96 DVLOG(1) 107 DVLOG(1)
97 << "WARNING: Existing request in progress or waiting for StopLoading()"; 108 << "WARNING: Existing request in progress or waiting for StopLoading()";
98 return false; 109 return false;
99 } 110 }
100 111
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Add this signal to signal_data_. 203 // Add this signal to signal_data_.
193 AddLoadingSignal("Snapshotting"); 204 AddLoadingSignal("Snapshotting");
194 205
195 HandleLoadEvent(); 206 HandleLoadEvent();
196 } 207 }
197 208
198 bool PrerenderingLoader::IsLowbarMet() { 209 bool PrerenderingLoader::IsLowbarMet() {
199 return is_lowbar_met_; 210 return is_lowbar_met_;
200 } 211 }
201 212
213 void PrerenderingLoader::ObserveResourceTracking(const ResourceDataType type,
214 int64_t started_count,
215 int64_t completed_count) {
216 // Add the signal to extra data, and use for tracking.
217 if (type == ResourceDataType::IMAGE)
Dmitry Titov 2017/05/18 02:28:10 This conditional can go to AddResourceSignal where
Pete Williamson 2017/05/24 01:01:50 Kept this method, since it is the exposed interfac
218 AddResourceSignal(type, started_count, completed_count);
219 }
220
202 void PrerenderingLoader::HandleLoadEvent() { 221 void PrerenderingLoader::HandleLoadEvent() {
203 // If still loading, check if the load succeeded or not, then update 222 // If still loading, check if the load succeeded or not, then update
204 // the internal state (LOADED for success or IDLE for failure) and post 223 // the internal state (LOADED for success or IDLE for failure) and post
205 // callback. 224 // callback.
206 // Note: it is possible to receive a load event (e.g., if timeout-based) 225 // Note: it is possible to receive a load event (e.g., if timeout-based)
207 // after the request has completed via another path (e.g., canceled) so 226 // after the request has completed via another path (e.g., canceled) so
208 // the Loader may be idle at this point. 227 // the Loader may be idle at this point.
209 228
210 if (IsIdle() || IsLoaded()) 229 if (IsIdle() || IsLoaded())
211 return; 230 return;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (adapter_->IsActive()) { 296 if (adapter_->IsActive()) {
278 adapter_->DestroyActive(); 297 adapter_->DestroyActive();
279 } 298 }
280 snapshot_controller_.reset(nullptr); 299 snapshot_controller_.reset(nullptr);
281 session_contents_.reset(nullptr); 300 session_contents_.reset(nullptr);
282 state_ = State::IDLE; 301 state_ = State::IDLE;
283 is_lowbar_met_ = false; 302 is_lowbar_met_ = false;
284 } 303 }
285 304
286 } // namespace offline_pages 305 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698