| OLD | NEW |
| 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/data_use_measurement/chrome_data_use_ascriber_service.h
" | 5 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber_service.h
" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" | 10 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::Bind(&ChromeDataUseAscriber::RenderFrameDeleted, | 108 base::Bind(&ChromeDataUseAscriber::RenderFrameDeleted, |
| 109 base::Unretained(ascriber_), | 109 base::Unretained(ascriber_), |
| 110 render_frame_host->GetProcess()->GetID(), | 110 render_frame_host->GetProcess()->GetID(), |
| 111 render_frame_host->GetRoutingID(), parent_render_process_id, | 111 render_frame_host->GetRoutingID(), parent_render_process_id, |
| 112 parent_render_frame_id)); | 112 parent_render_frame_id)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ChromeDataUseAscriberService::DidStartNavigation( | 115 void ChromeDataUseAscriberService::DidStartNavigation( |
| 116 content::NavigationHandle* navigation_handle) { | 116 content::NavigationHandle* navigation_handle) { |
| 117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 118 | |
| 119 if (!navigation_handle->IsInMainFrame()) | 118 if (!navigation_handle->IsInMainFrame()) |
| 120 return; | 119 return; |
| 121 | 120 |
| 122 if (!ascriber_) | 121 if (!ascriber_) |
| 123 return; | 122 return; |
| 124 | |
| 125 content::WebContents* web_contents = navigation_handle->GetWebContents(); | 123 content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 126 content::BrowserThread::PostTask( | 124 content::BrowserThread::PostTask( |
| 127 content::BrowserThread::IO, FROM_HERE, | 125 content::BrowserThread::IO, FROM_HERE, |
| 128 base::Bind(&ChromeDataUseAscriber::DidStartMainFrameNavigation, | 126 base::Bind(&ChromeDataUseAscriber::DidStartMainFrameNavigation, |
| 129 base::Unretained(ascriber_), navigation_handle->GetURL(), | 127 base::Unretained(ascriber_), navigation_handle->GetURL(), |
| 130 web_contents->GetRenderProcessHost()->GetID(), | 128 web_contents->GetRenderProcessHost()->GetID(), |
| 131 web_contents->GetMainFrame()->GetRoutingID(), | 129 web_contents->GetMainFrame()->GetRoutingID(), |
| 132 navigation_handle)); | 130 navigation_handle)); |
| 133 } | 131 } |
| 134 | 132 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 148 base::Bind( | 146 base::Bind( |
| 149 &ChromeDataUseAscriber::ReadyToCommitMainFrameNavigation, | 147 &ChromeDataUseAscriber::ReadyToCommitMainFrameNavigation, |
| 150 base::Unretained(ascriber_), navigation_handle->GetURL(), | 148 base::Unretained(ascriber_), navigation_handle->GetURL(), |
| 151 navigation_handle->GetGlobalRequestID(), | 149 navigation_handle->GetGlobalRequestID(), |
| 152 web_contents->GetRenderProcessHost()->GetID(), | 150 web_contents->GetRenderProcessHost()->GetID(), |
| 153 web_contents->GetMainFrame()->GetRoutingID(), | 151 web_contents->GetMainFrame()->GetRoutingID(), |
| 154 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage(), | 152 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage(), |
| 155 navigation_handle)); | 153 navigation_handle)); |
| 156 } | 154 } |
| 157 | 155 |
| 158 void ChromeDataUseAscriberService::DidRedirectNavigation( | |
| 159 content::NavigationHandle* navigation_handle) { | |
| 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 161 | |
| 162 if (!is_initialized_ || !navigation_handle->IsInMainFrame()) | |
| 163 return; | |
| 164 | |
| 165 if (!ascriber_) | |
| 166 return; | |
| 167 | |
| 168 content::WebContents* web_contents = navigation_handle->GetWebContents(); | |
| 169 content::BrowserThread::PostTask( | |
| 170 content::BrowserThread::IO, FROM_HERE, | |
| 171 base::Bind(&ChromeDataUseAscriber::DidRedirectMainFrameNavigation, | |
| 172 base::Unretained(ascriber_), navigation_handle->GetURL(), | |
| 173 web_contents->GetRenderProcessHost()->GetID(), | |
| 174 web_contents->GetMainFrame()->GetRoutingID(), | |
| 175 navigation_handle)); | |
| 176 } | |
| 177 | |
| 178 void ChromeDataUseAscriberService::SetDataUseAscriber( | 156 void ChromeDataUseAscriberService::SetDataUseAscriber( |
| 179 ChromeDataUseAscriber* ascriber) { | 157 ChromeDataUseAscriber* ascriber) { |
| 180 DCHECK(!is_initialized_); | 158 DCHECK(!is_initialized_); |
| 181 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 182 | 160 |
| 183 ascriber_ = ascriber; | 161 ascriber_ = ascriber; |
| 184 is_initialized_ = true; | 162 is_initialized_ = true; |
| 185 | 163 |
| 186 for (auto& it : pending_frames_queue_) { | 164 for (auto& it : pending_frames_queue_) { |
| 187 RenderFrameCreated(it); | 165 RenderFrameCreated(it); |
| 188 } | 166 } |
| 189 pending_frames_queue_.clear(); | 167 pending_frames_queue_.clear(); |
| 190 } | 168 } |
| 191 | 169 |
| 192 } // namespace data_use_measurement | 170 } // namespace data_use_measurement |
| OLD | NEW |