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

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: Dimich CR fixes Created 3 years, 9 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 bool PrerenderingLoader::LoadPage(const GURL& url, 92 bool PrerenderingLoader::LoadPage(const GURL& url,
92 const LoadPageCallback& load_done_callback, 93 const LoadPageCallback& load_done_callback,
93 const ProgressCallback& progress_callback) { 94 const ProgressCallback& progress_callback) {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
95 if (!IsIdle()) { 96 if (!IsIdle()) {
96 DVLOG(1) 97 DVLOG(1)
97 << "WARNING: Existing request in progress or waiting for StopLoading()"; 98 << "WARNING: Existing request in progress or waiting for StopLoading()";
98 return false; 99 return false;
99 } 100 }
100 101
102 // Add this signal to signal_data_.
fgorski 2017/03/20 20:43:24 Consider extracting a method accepting signal name
Pete Williamson 2017/03/20 21:43:52 Added a new method for this.
103 std::string signal("StartLoading: ");
104 signal += std::to_string(base::Time::Now().ToJavaTime());
fgorski 2017/03/20 20:43:24 Why use java time? Please document that somehow.
Pete Williamson 2017/03/20 21:43:52 What we need is time in milliseconds. There are t
105 signal_data_.push_back(signal);
106
101 // Create a WebContents instance to define and hold a SessionStorageNamespace 107 // Create a WebContents instance to define and hold a SessionStorageNamespace
102 // for this load request. 108 // for this load request.
103 DCHECK(!session_contents_.get()); 109 DCHECK(!session_contents_.get());
104 std::unique_ptr<content::WebContents> new_web_contents( 110 std::unique_ptr<content::WebContents> new_web_contents(
105 content::WebContents::Create( 111 content::WebContents::Create(
106 content::WebContents::CreateParams(browser_context_))); 112 content::WebContents::CreateParams(browser_context_)));
107 content::SessionStorageNamespace* sessionStorageNamespace = 113 content::SessionStorageNamespace* sessionStorageNamespace =
108 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); 114 new_web_contents->GetController().GetDefaultSessionStorageNamespace();
109 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); 115 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size();
110 bool accepted = adapter_->StartPrerender( 116 bool accepted = adapter_->StartPrerender(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 adapter_ = std::move(prerender_adapter); 151 adapter_ = std::move(prerender_adapter);
146 } 152 }
147 153
148 void PrerenderingLoader::OnPrerenderStopLoading() { 154 void PrerenderingLoader::OnPrerenderStopLoading() {
149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
150 DCHECK(!IsIdle()); 156 DCHECK(!IsIdle());
151 DCHECK(adapter_->GetWebContents()); 157 DCHECK(adapter_->GetWebContents());
152 // Inform SnapshotController of OnLoad event so it can determine 158 // Inform SnapshotController of OnLoad event so it can determine
153 // when to consider it really LOADED. 159 // when to consider it really LOADED.
154 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); 160 snapshot_controller_->DocumentOnLoadCompletedInMainFrame();
161
162 // Add this signal to signal_data_.
163 std::string signal("OnLoad: ");
164 signal += std::to_string(base::Time::Now().ToJavaTime());
165 signal_data_.push_back(signal);
155 } 166 }
156 167
157 void PrerenderingLoader::OnPrerenderDomContentLoaded() { 168 void PrerenderingLoader::OnPrerenderDomContentLoaded() {
158 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
159 DCHECK(!IsIdle()); 170 DCHECK(!IsIdle());
160 if (!adapter_->GetWebContents()) { 171 if (!adapter_->GetWebContents()) {
161 // Without a WebContents object at this point, we are done. 172 // Without a WebContents object at this point, we are done.
162 HandleLoadingStopped(); 173 HandleLoadingStopped();
163 } else { 174 } else {
164 is_lowbar_met_ = true; 175 is_lowbar_met_ = true;
165 if (kConsiderDclForSnapshot) { 176 if (kConsiderDclForSnapshot) {
166 // Inform SnapshotController of DomContentLoaded event so it can 177 // Inform SnapshotController of DomContentLoaded event so it can
167 // determine when to consider it really LOADED (e.g., some multiple 178 // determine when to consider it really LOADED (e.g., some multiple
168 // second delay from this event). 179 // second delay from this event).
169 snapshot_controller_->DocumentAvailableInMainFrame(); 180 snapshot_controller_->DocumentAvailableInMainFrame();
170 } 181 }
182
183 // Add this signal to signal_data_.
184 std::string signal("OnDomContentLoaded: ");
185 signal += std::to_string(base::Time::Now().ToJavaTime());
186 signal_data_.push_back(signal);
171 } 187 }
172 } 188 }
173 189
174 void PrerenderingLoader::OnPrerenderStop() { 190 void PrerenderingLoader::OnPrerenderStop() {
175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 191 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
176 HandleLoadingStopped(); 192 HandleLoadingStopped();
177 } 193 }
178 194
179 void PrerenderingLoader::OnPrerenderNetworkBytesChanged(int64_t bytes) { 195 void PrerenderingLoader::OnPrerenderNetworkBytesChanged(int64_t bytes) {
180 if (state_ == State::LOADING) 196 if (state_ == State::LOADING)
181 progress_callback_.Run(bytes); 197 progress_callback_.Run(bytes);
182 } 198 }
183 199
184 void PrerenderingLoader::StartSnapshot() { 200 void PrerenderingLoader::StartSnapshot() {
185 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
202
203 // Add this signal to signal_data_.
204 std::string signal("Snapshotting: ");
205 signal += std::to_string(base::Time::Now().ToJavaTime());
206 signal_data_.push_back(signal);
207
186 HandleLoadEvent(); 208 HandleLoadEvent();
187 } 209 }
188 210
189 bool PrerenderingLoader::IsLowbarMet() { 211 bool PrerenderingLoader::IsLowbarMet() {
190 return is_lowbar_met_; 212 return is_lowbar_met_;
191 } 213 }
192 214
193 void PrerenderingLoader::HandleLoadEvent() { 215 void PrerenderingLoader::HandleLoadEvent() {
194 // If still loading, check if the load succeeded or not, then update 216 // 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 217 // 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()) { 290 if (adapter_->IsActive()) {
269 adapter_->DestroyActive(); 291 adapter_->DestroyActive();
270 } 292 }
271 snapshot_controller_.reset(nullptr); 293 snapshot_controller_.reset(nullptr);
272 session_contents_.reset(nullptr); 294 session_contents_.reset(nullptr);
273 state_ = State::IDLE; 295 state_ = State::IDLE;
274 is_lowbar_met_ = false; 296 is_lowbar_met_ = false;
275 } 297 }
276 298
277 } // namespace offline_pages 299 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698