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

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

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: CR feedback per Dimich Created 3 years, 8 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"
11 #include "base/time/time.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "net/base/network_change_notifier.h" 16 #include "net/base/network_change_notifier.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 18
18 namespace { 19 namespace {
19 // Whether to report DomContentLoaded event to the snapshot controller. 20 // Whether to report DomContentLoaded event to the snapshot controller.
20 bool kConsiderDclForSnapshot = false; 21 bool kConsiderDclForSnapshot = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 snapshot_controller_(nullptr), 82 snapshot_controller_(nullptr),
82 browser_context_(browser_context), 83 browser_context_(browser_context),
83 is_lowbar_met_(false) { 84 is_lowbar_met_(false) {
84 adapter_.reset(new PrerenderAdapter(this)); 85 adapter_.reset(new PrerenderAdapter(this));
85 } 86 }
86 87
87 PrerenderingLoader::~PrerenderingLoader() { 88 PrerenderingLoader::~PrerenderingLoader() {
88 CancelPrerender(); 89 CancelPrerender();
89 } 90 }
90 91
92 void PrerenderingLoader::SetSnapshotStartTime() {
Dmitry Titov 2017/03/29 23:26:29 looks like nobody calls it.
Pete Williamson 2017/03/31 00:29:48 Oops, fixed. LoadPage now calls this instead of a
93 snapshot_start_time_ = base::TimeTicks::Now();
94 }
95
96 void PrerenderingLoader::AddLoadingSignal(const char* signal_name) {
97 std::string signal(signal_name);
98 signal += ": ";
99 base::TimeTicks current_time = base::TimeTicks::Now();
100 base::TimeDelta delay_so_far = current_time - snapshot_start_time_;
101 signal += std::to_string(delay_so_far.InMilliseconds());
102 signal_data_.push_back(signal);
103 }
104
91 bool PrerenderingLoader::LoadPage(const GURL& url, 105 bool PrerenderingLoader::LoadPage(const GURL& url,
92 const LoadPageCallback& load_done_callback, 106 const LoadPageCallback& load_done_callback,
93 const ProgressCallback& progress_callback) { 107 const ProgressCallback& progress_callback) {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
95 if (!IsIdle()) { 109 if (!IsIdle()) {
96 DVLOG(1) 110 DVLOG(1)
97 << "WARNING: Existing request in progress or waiting for StopLoading()"; 111 << "WARNING: Existing request in progress or waiting for StopLoading()";
98 return false; 112 return false;
99 } 113 }
100 114
115 // Add this signal to signal_data_.
116 AddLoadingSignal("StartLoading");
117
101 // Create a WebContents instance to define and hold a SessionStorageNamespace 118 // Create a WebContents instance to define and hold a SessionStorageNamespace
102 // for this load request. 119 // for this load request.
103 DCHECK(!session_contents_.get()); 120 DCHECK(!session_contents_.get());
104 std::unique_ptr<content::WebContents> new_web_contents( 121 std::unique_ptr<content::WebContents> new_web_contents(
105 content::WebContents::Create( 122 content::WebContents::Create(
106 content::WebContents::CreateParams(browser_context_))); 123 content::WebContents::CreateParams(browser_context_)));
107 content::SessionStorageNamespace* sessionStorageNamespace = 124 content::SessionStorageNamespace* sessionStorageNamespace =
108 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); 125 new_web_contents->GetController().GetDefaultSessionStorageNamespace();
109 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); 126 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size();
110 bool accepted = adapter_->StartPrerender( 127 bool accepted = adapter_->StartPrerender(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 adapter_ = std::move(prerender_adapter); 162 adapter_ = std::move(prerender_adapter);
146 } 163 }
147 164
148 void PrerenderingLoader::OnPrerenderStopLoading() { 165 void PrerenderingLoader::OnPrerenderStopLoading() {
149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
150 DCHECK(!IsIdle()); 167 DCHECK(!IsIdle());
151 DCHECK(adapter_->GetWebContents()); 168 DCHECK(adapter_->GetWebContents());
152 // Inform SnapshotController of OnLoad event so it can determine 169 // Inform SnapshotController of OnLoad event so it can determine
153 // when to consider it really LOADED. 170 // when to consider it really LOADED.
154 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); 171 snapshot_controller_->DocumentOnLoadCompletedInMainFrame();
172
173 // Add this signal to signal_data_.
174 AddLoadingSignal("OnLoad");
155 } 175 }
156 176
157 void PrerenderingLoader::OnPrerenderDomContentLoaded() { 177 void PrerenderingLoader::OnPrerenderDomContentLoaded() {
158 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
159 DCHECK(!IsIdle()); 179 DCHECK(!IsIdle());
160 if (!adapter_->GetWebContents()) { 180 if (!adapter_->GetWebContents()) {
161 // Without a WebContents object at this point, we are done. 181 // Without a WebContents object at this point, we are done.
162 HandleLoadingStopped(); 182 HandleLoadingStopped();
163 } else { 183 } else {
164 is_lowbar_met_ = true; 184 is_lowbar_met_ = true;
165 if (kConsiderDclForSnapshot) { 185 if (kConsiderDclForSnapshot) {
166 // Inform SnapshotController of DomContentLoaded event so it can 186 // Inform SnapshotController of DomContentLoaded event so it can
167 // determine when to consider it really LOADED (e.g., some multiple 187 // determine when to consider it really LOADED (e.g., some multiple
168 // second delay from this event). 188 // second delay from this event).
169 snapshot_controller_->DocumentAvailableInMainFrame(); 189 snapshot_controller_->DocumentAvailableInMainFrame();
170 } 190 }
191
192 // Add this signal to signal_data_.
193 AddLoadingSignal("OnDomContentLoaded");
171 } 194 }
172 } 195 }
173 196
174 void PrerenderingLoader::OnPrerenderStop() { 197 void PrerenderingLoader::OnPrerenderStop() {
175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
176 HandleLoadingStopped(); 199 HandleLoadingStopped();
177 } 200 }
178 201
179 void PrerenderingLoader::OnPrerenderNetworkBytesChanged(int64_t bytes) { 202 void PrerenderingLoader::OnPrerenderNetworkBytesChanged(int64_t bytes) {
180 if (state_ == State::LOADING) 203 if (state_ == State::LOADING)
181 progress_callback_.Run(bytes); 204 progress_callback_.Run(bytes);
182 } 205 }
183 206
184 void PrerenderingLoader::StartSnapshot() { 207 void PrerenderingLoader::StartSnapshot() {
185 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
209
210 // Add this signal to signal_data_.
211 AddLoadingSignal("Snapshotting");
212
186 HandleLoadEvent(); 213 HandleLoadEvent();
187 } 214 }
188 215
189 bool PrerenderingLoader::IsLowbarMet() { 216 bool PrerenderingLoader::IsLowbarMet() {
190 return is_lowbar_met_; 217 return is_lowbar_met_;
191 } 218 }
192 219
193 void PrerenderingLoader::HandleLoadEvent() { 220 void PrerenderingLoader::HandleLoadEvent() {
194 // If still loading, check if the load succeeded or not, then update 221 // If still loading, check if the load succeeded or not, then update
195 // the internal state (LOADED for success or IDLE for failure) and post 222 // the internal state (LOADED for success or IDLE for failure) and post
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (adapter_->IsActive()) { 295 if (adapter_->IsActive()) {
269 adapter_->DestroyActive(); 296 adapter_->DestroyActive();
270 } 297 }
271 snapshot_controller_.reset(nullptr); 298 snapshot_controller_.reset(nullptr);
272 session_contents_.reset(nullptr); 299 session_contents_.reset(nullptr);
273 state_ = State::IDLE; 300 state_ = State::IDLE;
274 is_lowbar_met_ = false; 301 is_lowbar_met_ = false;
275 } 302 }
276 303
277 } // namespace offline_pages 304 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698