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 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
| 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ | 6 #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | |
| 17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "ui/base/page_transition_types.h" | 19 #include "ui/base/page_transition_types.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 | 22 |
| 22 namespace chrome { | 23 namespace chrome { |
| 23 | 24 |
| 24 namespace android { | 25 namespace android { |
| 25 | 26 |
| 26 // DataUseUITabModel tracks data use tracking start and end transitions on the | 27 // DataUseUITabModel tracks data use tracking start and end transitions on the |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 53 void ReportTabClosure(int32_t tab_id); | 54 void ReportTabClosure(int32_t tab_id); |
| 54 | 55 |
| 55 // Returns true if data use tracking has been started for the tab with id | 56 // Returns true if data use tracking has been started for the tab with id |
| 56 // |tab_id|. Calling this function resets the state of the tab. | 57 // |tab_id|. Calling this function resets the state of the tab. |
| 57 bool HasDataUseTrackingStarted(int32_t tab_id); | 58 bool HasDataUseTrackingStarted(int32_t tab_id); |
| 58 | 59 |
| 59 // Returns true if data use tracking has ended for the tab with id |tab_id|. | 60 // Returns true if data use tracking has ended for the tab with id |tab_id|. |
| 60 // Calling this function resets the state of the tab. | 61 // Calling this function resets the state of the tab. |
| 61 bool HasDataUseTrackingEnded(int32_t tab_id); | 62 bool HasDataUseTrackingEnded(int32_t tab_id); |
| 62 | 63 |
| 64 void set_data_use_tab_model( | |
| 65 base::WeakPtr<DataUseTabModel> data_use_tab_model) { | |
| 66 data_use_tab_model_ = data_use_tab_model_; | |
|
bengr
2015/11/14 03:54:39
bug? You are setting it to itself?
tbansal1
2015/11/16 17:49:08
Done.
| |
| 67 } | |
| 68 | |
| 63 private: | 69 private: |
| 64 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntranceExitState); | 70 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, EntranceExitState); |
| 71 FRIEND_TEST_ALL_PREFIXES(DataUseUITabModelTest, ConvertTransitionType); | |
| 65 | 72 |
| 66 // DataUseTrackingEvent indicates the state of a tab. | 73 // DataUseTrackingEvent indicates the state of a tab. |
| 67 enum DataUseTrackingEvent { | 74 enum DataUseTrackingEvent { |
| 68 // Indicates that data use tracking has started. | 75 // Indicates that data use tracking has started. |
| 69 DATA_USE_TRACKING_STARTED, | 76 DATA_USE_TRACKING_STARTED, |
| 70 | 77 |
| 71 // Indicates that data use tracking has ended. | 78 // Indicates that data use tracking has ended. |
| 72 DATA_USE_TRACKING_ENDED, | 79 DATA_USE_TRACKING_ENDED, |
| 73 }; | 80 }; |
| 74 | 81 |
| 75 typedef std::unordered_map<int32_t, DataUseTrackingEvent> TabEvents; | 82 typedef std::unordered_map<int32_t, DataUseTrackingEvent> TabEvents; |
| 76 | 83 |
| 77 // DataUseTabModel::Observer implementation: | 84 // DataUseTabModel::Observer implementation: |
| 78 // TODO(tbansal): Add override once DataUseTabModel is checked in. | 85 // TODO(tbansal): Add override once DataUseTabModel is checked in. |
| 79 void OnTrackingStarted(int32_t tab_id); | 86 void OnTrackingStarted(int32_t tab_id); |
| 80 void OnTrackingEnded(int32_t tab_id); | 87 void OnTrackingEnded(int32_t tab_id); |
| 81 | 88 |
| 82 // Creates |event| for tab with id |tab_id| and value |event|, if there is no | 89 // Creates |event| for tab with id |tab_id| and value |event|, if there is no |
| 83 // existing entry for |tab_id|, and returns true. Otherwise, returns false | 90 // existing entry for |tab_id|, and returns true. Otherwise, returns false |
| 84 // without modifying the entry. | 91 // without modifying the entry. |
| 85 bool MaybeCreateTabEvent(int32_t tab_id, DataUseTrackingEvent event); | 92 bool MaybeCreateTabEvent(int32_t tab_id, DataUseTrackingEvent event); |
| 86 | 93 |
| 87 // Removes event entry for |tab_id|, if the entry is equal to |event|, and | 94 // Removes event entry for |tab_id|, if the entry is equal to |event|, and |
| 88 // returns true. Otherwise, returns false without modifying the entry. | 95 // returns true. Otherwise, returns false without modifying the entry. |
| 89 bool RemoveTabEvent(int32_t tab_id, DataUseTrackingEvent event); | 96 bool RemoveTabEvent(int32_t tab_id, DataUseTrackingEvent event); |
| 90 | 97 |
| 98 // Converts |page_transition| to DataUseTabModel::TransitionType enum. | |
| 99 // Returns true if conversion was successful, and updates |transition_type|. | |
| 100 // Otherwise, returns false, and |transition_type| is not changed. | |
| 101 // |transition_type| must not be null. | |
| 102 bool ConvertTransitionType( | |
| 103 ui::PageTransition page_transition, | |
| 104 DataUseTabModel::TransitionType* transition_type) const; | |
| 105 | |
| 106 // |data_use_tab_model_| is notified of browser navigations and tab closures | |
| 107 // on IO thread. | |
| 108 base::WeakPtr<DataUseTabModel> data_use_tab_model_; | |
| 109 | |
| 91 // |tab_events_| stores tracking events of multiple tabs. | 110 // |tab_events_| stores tracking events of multiple tabs. |
| 92 TabEvents tab_events_; | 111 TabEvents tab_events_; |
| 93 | 112 |
| 94 // |io_task_runner_| accesses DataUseTabModel members on IO thread. | 113 // |io_task_runner_| accesses DataUseTabModel members on IO thread. |
| 95 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 114 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 96 | 115 |
| 97 base::ThreadChecker thread_checker_; | 116 base::ThreadChecker thread_checker_; |
| 98 | 117 |
| 99 DISALLOW_COPY_AND_ASSIGN(DataUseUITabModel); | 118 DISALLOW_COPY_AND_ASSIGN(DataUseUITabModel); |
| 100 }; | 119 }; |
| 101 | 120 |
| 102 } // namespace android | 121 } // namespace android |
| 103 | 122 |
| 104 } // namespace chrome | 123 } // namespace chrome |
| 105 | 124 |
| 106 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ | 125 #endif // CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_UI_TAB_MODEL_H_ |
| OLD | NEW |