OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/prerender/prerender_plt_recorder.h" |
| 6 |
| 7 #include "base/time.h" |
| 8 #include "chrome/browser/prerender/prerender_manager.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/common/render_messages.h" |
| 12 |
| 13 PrerenderPLTRecorder::PrerenderPLTRecorder(TabContents* tab_contents) |
| 14 : tab_contents_(tab_contents), |
| 15 pplt_load_start_() { |
| 16 |
| 17 } |
| 18 |
| 19 PrerenderPLTRecorder::~PrerenderPLTRecorder() { |
| 20 } |
| 21 |
| 22 bool PrerenderPLTRecorder::OnMessageReceived(const IPC::Message& message) { |
| 23 IPC_BEGIN_MESSAGE_MAP(PrerenderPLTRecorder, message) |
| 24 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
| 25 OnDidStartProvisionalLoadForFrame) |
| 26 IPC_END_MESSAGE_MAP() |
| 27 return false; |
| 28 } |
| 29 |
| 30 void PrerenderPLTRecorder::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 31 bool is_main_frame, |
| 32 const GURL& url) { |
| 33 if (is_main_frame) { |
| 34 // Record the beginning of a new PPLT navigation. |
| 35 pplt_load_start_ = base::TimeTicks::Now(); |
| 36 } |
| 37 } |
| 38 |
| 39 void PrerenderPLTRecorder::DidStopLoading() { |
| 40 // Compute the PPLT metric and report it in a histogram, if needed. |
| 41 PrerenderManager* pm = tab_contents_->profile()->GetPrerenderManager(); |
| 42 if (pm != NULL && !pplt_load_start_.is_null()) |
| 43 pm->RecordPerceivedPageLoadTime(base::TimeTicks::Now() - pplt_load_start_); |
| 44 |
| 45 // Reset the PPLT metric. |
| 46 pplt_load_start_ = base::TimeTicks(); |
| 47 } |
OLD | NEW |