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_ui_tab_model.h" | 5 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 DataUseUITabModel::~DataUseUITabModel() {} | 25 DataUseUITabModel::~DataUseUITabModel() {} |
| 26 | 26 |
| 27 void DataUseUITabModel::ReportBrowserNavigation( | 27 void DataUseUITabModel::ReportBrowserNavigation( |
| 28 const GURL& gurl, | 28 const GURL& gurl, |
| 29 ui::PageTransition page_transition, | 29 ui::PageTransition page_transition, |
| 30 int32_t tab_id) const { | 30 int32_t tab_id) const { |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 | 33 |
| 34 // TODO(tbansal): Post to DataUseTabModel on IO thread. | 34 if (data_use_tab_model_) { |
|
mmenke
2015/11/13 22:49:55
Is this legal? You're checking if a weak ptr is N
bengr
2015/11/14 03:54:39
This doesn't seem kosher. I think it should just p
tbansal1
2015/11/16 17:49:08
Now using two weak pointers (one for UI, one for I
tbansal1
2015/11/16 17:49:08
Done.
| |
| 35 DataUseTabModel::TransitionType transition_type; | |
| 36 if (ConvertTransitionType(page_transition, &transition_type)) { | |
| 37 io_task_runner_->PostTask( | |
| 38 FROM_HERE, | |
| 39 base::Bind(&DataUseTabModel::OnNavigationEvent, data_use_tab_model_, | |
| 40 tab_id, transition_type, gurl)); | |
| 41 } | |
| 42 } | |
| 35 } | 43 } |
| 36 | 44 |
| 37 void DataUseUITabModel::ReportTabClosure(int32_t tab_id) { | 45 void DataUseUITabModel::ReportTabClosure(int32_t tab_id) { |
| 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 39 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 40 | 48 |
| 41 // TODO(tbansal): Post to DataUseTabModel on IO thread. | 49 if (data_use_tab_model_) { |
|
bengr
2015/11/14 03:54:39
Same here.
tbansal1
2015/11/16 17:49:08
Done.
| |
| 50 io_task_runner_->PostTask(FROM_HERE, | |
| 51 base::Bind(&DataUseTabModel::OnTabCloseEvent, | |
| 52 data_use_tab_model_, tab_id)); | |
| 53 } | |
| 42 | 54 |
| 43 // Clear out local state. | 55 // Clear out local state. |
| 44 TabEvents::iterator it = tab_events_.find(tab_id); | 56 TabEvents::iterator it = tab_events_.find(tab_id); |
| 45 if (it == tab_events_.end()) | 57 if (it == tab_events_.end()) |
| 46 return; | 58 return; |
| 47 tab_events_.erase(it); | 59 tab_events_.erase(it); |
| 48 } | 60 } |
| 49 | 61 |
| 50 void DataUseUITabModel::OnTrackingStarted(int32_t tab_id) { | 62 void DataUseUITabModel::OnTrackingStarted(int32_t tab_id) { |
| 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 DataUseTrackingEvent event) { | 117 DataUseTrackingEvent event) { |
| 106 TabEvents::iterator it = tab_events_.find(tab_id); | 118 TabEvents::iterator it = tab_events_.find(tab_id); |
| 107 DCHECK(it != tab_events_.end()); | 119 DCHECK(it != tab_events_.end()); |
| 108 if (it->second == event) { | 120 if (it->second == event) { |
| 109 tab_events_.erase(it); | 121 tab_events_.erase(it); |
| 110 return true; | 122 return true; |
| 111 } | 123 } |
| 112 return false; | 124 return false; |
| 113 } | 125 } |
| 114 | 126 |
| 127 bool DataUseUITabModel::ConvertTransitionType( | |
| 128 ui::PageTransition page_transition, | |
| 129 DataUseTabModel::TransitionType* transition_type) const { | |
| 130 int32_t mask = 0xFFFFFFFF ^ ui::PAGE_TRANSITION_QUALIFIER_MASK; | |
| 131 switch (page_transition & mask) { | |
| 132 case ui::PAGE_TRANSITION_TYPED: | |
| 133 *transition_type = DataUseTabModel::TRANSITION_OMNIBOX_NAVIGATION; | |
| 134 return true; | |
| 135 case ui::PAGE_TRANSITION_AUTO_BOOKMARK: | |
|
bengr
2015/11/14 03:54:39
Where do we track navigation from history? Also, i
tbansal1
2015/11/16 17:49:08
List should be exhaustive now.
| |
| 136 *transition_type = DataUseTabModel::TRANSITION_BOOKMARK; | |
| 137 return true; | |
| 138 case ui::PAGE_TRANSITION_GENERATED: | |
| 139 *transition_type = DataUseTabModel::TRANSITION_OMNIBOX_SEARCH; | |
| 140 return true; | |
| 141 default: | |
| 142 return false; | |
| 143 } | |
| 144 } | |
| 145 | |
| 115 } // namespace android | 146 } // namespace android |
| 116 | 147 |
| 117 } // namespace chrome | 148 } // namespace chrome |
| OLD | NEW |