Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/data_usage/data_use_tab_helper.h" | 5 #include "chrome/browser/android/data_usage/data_use_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h" | 8 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h" |
| 9 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h" | 9 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 11 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/navigation_handle.h" | 13 #include "content/public/browser/navigation_handle.h" |
| 14 #include "content/public/browser/render_frame_host.h" | |
| 14 #include "ui/base/page_transition_types.h" | 15 #include "ui/base/page_transition_types.h" |
| 15 | 16 |
| 16 namespace content { | |
| 17 class RenderFrameHost; | |
| 18 } | |
| 19 | |
| 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(DataUseTabHelper); | 17 DEFINE_WEB_CONTENTS_USER_DATA_KEY(DataUseTabHelper); |
| 21 | 18 |
| 22 DataUseTabHelper::~DataUseTabHelper() {} | 19 DataUseTabHelper::~DataUseTabHelper() {} |
| 23 | 20 |
| 24 DataUseTabHelper::DataUseTabHelper(content::WebContents* web_contents) | 21 DataUseTabHelper::DataUseTabHelper(content::WebContents* web_contents) |
| 25 : content::WebContentsObserver(web_contents) { | 22 : content::WebContentsObserver(web_contents) { |
| 26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 27 } | 24 } |
| 28 | 25 |
| 29 void DataUseTabHelper::ReadyToCommitNavigation( | 26 void DataUseTabHelper::DidFinishNavigation( |
| 30 content::NavigationHandle* navigation_handle) { | 27 content::NavigationHandle* navigation_handle) { |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 29 if (!navigation_handle->IsInMainFrame()) | |
| 30 return; | |
| 32 | 31 |
| 33 // Notify the DataUseUITabModel. | 32 // Notify the DataUseUITabModel. |
| 34 chrome::android::DataUseUITabModel* data_use_ui_tab_model = | 33 chrome::android::DataUseUITabModel* data_use_ui_tab_model = |
| 35 chrome::android::DataUseUITabModelFactory::GetForBrowserContext( | 34 chrome::android::DataUseUITabModelFactory::GetForBrowserContext( |
| 36 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 35 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| 37 if (data_use_ui_tab_model) { | 36 if (data_use_ui_tab_model) { |
| 38 data_use_ui_tab_model->ReportBrowserNavigation( | 37 data_use_ui_tab_model->ReportBrowserNavigation( |
| 39 navigation_handle->GetURL(), | 38 navigation_handle->GetURL(), |
| 40 ui::PageTransitionFromInt(navigation_handle->GetPageTransition()), | 39 ui::PageTransitionFromInt(navigation_handle->GetPageTransition()), |
| 41 SessionTabHelper::IdForTab(web_contents())); | 40 SessionTabHelper::IdForTab(web_contents())); |
|
sclittle
2015/11/16 23:13:42
SessionTabHelper::IdForTab could return -1 if web_
tbansal1
2015/11/17 21:12:33
Handled it in DataUseUITabModel::ReportBrowserNavi
| |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 | 43 |
| 45 void DataUseTabHelper::FrameDeleted( | 44 void DataUseTabHelper::RenderFrameDeleted( |
| 46 content::RenderFrameHost* render_frame_host) { | 45 content::RenderFrameHost* render_frame_host) { |
| 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 48 | 47 |
| 48 // Check if it is a main frame. | |
| 49 if (render_frame_host->GetParent() != nullptr || | |
| 50 render_frame_host->IsRenderFrameLive()) { | |
| 51 return; | |
| 52 } | |
| 53 | |
| 49 // Notify the DataUseUITabModel. | 54 // Notify the DataUseUITabModel. |
| 50 chrome::android::DataUseUITabModel* data_use_ui_tab_model = | 55 chrome::android::DataUseUITabModel* data_use_ui_tab_model = |
| 51 chrome::android::DataUseUITabModelFactory::GetForBrowserContext( | 56 chrome::android::DataUseUITabModelFactory::GetForBrowserContext( |
| 52 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 57 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| 53 if (data_use_ui_tab_model) { | 58 if (data_use_ui_tab_model) { |
| 54 data_use_ui_tab_model->ReportTabClosure( | 59 data_use_ui_tab_model->ReportTabClosure( |
| 55 SessionTabHelper::IdForTab(web_contents())); | 60 SessionTabHelper::IdForTab(web_contents())); |
|
sclittle
2015/11/16 23:13:42
Same here about handling -1 case if web_contents()
tbansal1
2015/11/17 21:12:33
Done.
| |
| 56 } | 61 } |
| 57 } | 62 } |
| OLD | NEW |