Index: chrome/browser/android/data_usage/data_use_ui_tab_model.h |
diff --git a/chrome/browser/android/data_usage/data_use_ui_tab_model.h b/chrome/browser/android/data_usage/data_use_ui_tab_model.h |
index a8dc492f521ad5e92f65f86ce1b2ddd2246189d0..76de5783c950dfe04c87be91388aea1524e4fbd7 100644 |
--- a/chrome/browser/android/data_usage/data_use_ui_tab_model.h |
+++ b/chrome/browser/android/data_usage/data_use_ui_tab_model.h |
@@ -8,13 +8,15 @@ |
#include <stdint.h> |
#include <string> |
-#include <unordered_map> |
+#include "base/containers/hash_tables.h" |
#include "base/gtest_prod_util.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/weak_ptr.h" |
+#include "base/single_thread_task_runner.h" |
#include "base/threading/thread_checker.h" |
+#include "chrome/browser/android/data_usage/data_use_tab_model.h" |
#include "components/keyed_service/core/keyed_service.h" |
#include "ui/base/page_transition_types.h" |
@@ -67,8 +69,23 @@ class DataUseUITabModel : public KeyedService { |
// Calling this function resets the state of the tab. |
bool HasDataUseTrackingEnded(int32_t tab_id); |
+ // Sets the weak pointer to DataUseTabModel that can be used on IO thread. |
+ // Should be called at most once. |
+ void SetIODataUseTabModel(base::WeakPtr<DataUseTabModel> data_use_tab_model); |
sclittle
2015/11/18 21:42:04
nit: pass in a const base::WeakPtr<DataUseTabModel
tbansal1
2015/11/19 00:47:07
Done. Made the CreateTabObserverOnIOThread a stati
|
+ |
+ // Notifies |this| of starting and ending of data tracking for tab with id |
+ // |tab_id|. |
+ void NotifyTrackingStarting(int32_t tab_id); |
+ void NotifyTrackingEnding(int32_t tab_id); |
+ |
+ class TabObserverOnIOThread; |
sclittle
2015/11/18 21:42:04
nit: Can this be moved to private?
tbansal1
2015/11/19 00:47:07
No, CreateTabObserverOnIOThread in .cc file needs
|
+ |
private: |
+ // Friends for testing. |
+ friend class DataUseUITabModelTest; |
FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntranceExitState); |
+ FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ConvertTransitionType); |
+ FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ReportTabEventsTest); |
// DataUseTrackingEvent indicates the state of a tab. |
enum DataUseTrackingEvent { |
@@ -79,12 +96,10 @@ class DataUseUITabModel : public KeyedService { |
DATA_USE_TRACKING_ENDED, |
}; |
- typedef std::unordered_map<int32_t, DataUseTrackingEvent> TabEvents; |
+ typedef base::hash_map<int32_t, DataUseTrackingEvent> TabEvents; |
- // DataUseTabModel::Observer implementation: |
- // TODO(tbansal): Add override once DataUseTabModel is checked in. |
- void OnTrackingStarted(int32_t tab_id); |
- void OnTrackingEnded(int32_t tab_id); |
+ void SetTabDataUseObserver( |
+ scoped_refptr<TabObserverOnIOThread> tab_data_use_observer); |
// Creates |event| for tab with id |tab_id| and value |event|, if there is no |
// existing entry for |tab_id|, and returns true. Otherwise, returns false |
@@ -95,14 +110,33 @@ class DataUseUITabModel : public KeyedService { |
// returns true. Otherwise, returns false without modifying the entry. |
bool RemoveTabEvent(int32_t tab_id, DataUseTrackingEvent event); |
+ // Converts |page_transition| to DataUseTabModel::TransitionType enum. |
+ // Returns true if conversion was successful, and updates |transition_type|. |
+ // Otherwise, returns false, and |transition_type| is not changed. |
+ // |transition_type| must not be null. |
+ bool ConvertTransitionType( |
+ ui::PageTransition page_transition, |
+ DataUseTabModel::TransitionType* transition_type) const; |
+ |
+ // |tab_data_use_observer_| notifies |this| of starting and ending of data |
+ // tracking. |
sclittle
2015/11/18 21:42:04
nit: Could you also mention here that it should on
tbansal1
2015/11/19 00:47:07
Done.
|
+ scoped_refptr<TabObserverOnIOThread> tab_data_use_observer_; |
+ |
// |tab_events_| stores tracking events of multiple tabs. |
TabEvents tab_events_; |
- // |io_task_runner_| accesses DataUseTabModel members on IO thread. |
+ // |io_data_use_tab_model_| is notified by |this| about browser navigations |
+ // and tab closures on IO thread. |io_data_use_tab_model_| should only be |
+ // used on IO thread. |
+ base::WeakPtr<DataUseTabModel> io_data_use_tab_model_; |
+ |
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
base::ThreadChecker thread_checker_; |
+ base::WeakPtrFactory<DataUseUITabModel> weak_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(DataUseUITabModel); |
}; |