| Index: chrome/browser/android/data_usage/data_use_tab_model.h
|
| diff --git a/chrome/browser/android/data_usage/data_use_tab_model.h b/chrome/browser/android/data_usage/data_use_tab_model.h
|
| index 2420de1a7a85465d58ade6bbbb54af066d2fd8a7..44e3b5f2d1816af10ba5108795b50e3861ee00dc 100644
|
| --- a/chrome/browser/android/data_usage/data_use_tab_model.h
|
| +++ b/chrome/browser/android/data_usage/data_use_tab_model.h
|
| @@ -5,8 +5,7 @@
|
| #ifndef CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_
|
| #define CHROME_BROWSER_ANDROID_DATA_USAGE_DATA_USE_TAB_MODEL_H_
|
|
|
| -#include <stdint.h>
|
| -
|
| +#include <list>
|
| #include <string>
|
|
|
| #include "base/containers/hash_tables.h"
|
| @@ -14,12 +13,20 @@
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "base/observer_list_threadsafe.h"
|
| #include "base/threading/thread_checker.h"
|
| #include "base/time/time.h"
|
| #include "chrome/browser/android/data_usage/tab_data_use_entry.h"
|
| -#include "components/data_usage/core/data_use.h"
|
| -#include "url/gurl.h"
|
| +#include "components/sessions/core/session_id.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace data_usage {
|
| +struct DataUse;
|
| +}
|
| +
|
| +class GURL;
|
|
|
| namespace chrome {
|
|
|
| @@ -46,12 +53,6 @@ class DataUseTabModel {
|
| // TODO(rajendrant): Remove this if not needed.
|
| TRANSITION_FROM_EXTERNAL_APP,
|
|
|
| - // Navigating to another app.
|
| - TRANSITION_TO_EXTERNAL_APP,
|
| -
|
| - // Navigation from NavSuggest below omnibox.
|
| - TRANSITION_FROM_NAVSUGGEST,
|
| -
|
| // Navigation from the omnibox when typing a URL.
|
| TRANSITION_OMNIBOX_NAVIGATION,
|
|
|
| @@ -63,7 +64,7 @@ class DataUseTabModel {
|
| };
|
|
|
| // TabDataUseObserver provides the interface for getting notifications from
|
| - // the DataUseTabModel.
|
| + // the DataUseTabModel. TabDataUseObserver is called back on UI thread.
|
| class TabDataUseObserver {
|
| public:
|
| virtual ~TabDataUseObserver() {}
|
| @@ -71,8 +72,8 @@ class DataUseTabModel {
|
| // Notification callback when tab tracking sessions are started and ended.
|
| // The callback will be received on the same thread AddObserver was called
|
| // from.
|
| - virtual void NotifyTrackingStarting(int32_t tab_id) = 0;
|
| - virtual void NotifyTrackingEnding(int32_t tab_id) = 0;
|
| + virtual void NotifyTrackingStarting(SessionID::id_type tab_id) = 0;
|
| + virtual void NotifyTrackingEnding(SessionID::id_type tab_id) = 0;
|
| };
|
|
|
| DataUseTabModel(const ExternalDataUseObserver* data_use_observer,
|
| @@ -86,7 +87,7 @@ class DataUseTabModel {
|
| // tab of the generated event, |transition| indicates the type of the UI
|
| // event/transition, |url| is the URL in the source tab, |package| indicates
|
| // the android package name of external application that initiated the event.
|
| - void OnNavigationEvent(int32_t tab_id,
|
| + void OnNavigationEvent(SessionID::id_type tab_id,
|
| TransitionType transition,
|
| const GURL& url,
|
| const std::string& package);
|
| @@ -94,7 +95,7 @@ class DataUseTabModel {
|
| // Notifies the DataUseTabModel that tab with |tab_id| is closed. Any active
|
| // tracking sessions for the tab are terminated, and the tab is marked as
|
| // closed.
|
| - void OnTabCloseEvent(int32_t tab_id);
|
| + void OnTabCloseEvent(SessionID::id_type tab_id);
|
|
|
| // Notifies the DataUseTabModel that tracking label |label| is removed. Any
|
| // active tracking sessions with the label are ended.
|
| @@ -107,10 +108,19 @@ class DataUseTabModel {
|
| virtual bool GetLabelForDataUse(const data_usage::DataUse& data_use,
|
| std::string* output_label) const;
|
|
|
| - // Adds or removes observers from the observer list. These functions are
|
| - // thread-safe and can be called from any thread.
|
| - void AddObserver(TabDataUseObserver* observer);
|
| - void RemoveObserver(TabDataUseObserver* observer);
|
| + // Adds observers to the observer list. Must be called on IO thread.
|
| + // |observer| is notified on UI thread.
|
| + // TODO(tbansal): Remove observers that have been destroyed.
|
| + void AddObserver(base::WeakPtr<TabDataUseObserver> observer);
|
| +
|
| + protected:
|
| + // Notifies the observers that a data usage tracking session started for
|
| + // |tab_id|. Protected for testing.
|
| + void NotifyObserversOfTrackingStarting(SessionID::id_type tab_id);
|
| +
|
| + // Notifies the observers that an active data usage tracking session ended for
|
| + // |tab_id|. Protected for testing.
|
| + void NotifyObserversOfTrackingEnding(SessionID::id_type tab_id);
|
|
|
| private:
|
| friend class DataUseTabModelTest;
|
| @@ -119,7 +129,6 @@ class DataUseTabModel {
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, SingleTabTracking);
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, MultipleTabTracking);
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverStartEndEvents);
|
| - FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, ObserverNotNotifiedAfterRemove);
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest,
|
| MultipleObserverMultipleStartEndEvents);
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest, TabCloseEvent);
|
| @@ -134,24 +143,17 @@ class DataUseTabModel {
|
| FRIEND_TEST_ALL_PREFIXES(DataUseTabModelTest,
|
| ExpiredActiveTabEntryRemovaltimeHistogram);
|
|
|
| - typedef base::hash_map<int32_t, TabDataUseEntry> TabEntryMap;
|
| + typedef base::hash_map<SessionID::id_type, TabDataUseEntry> TabEntryMap;
|
|
|
| // Virtualized for unit test support.
|
| virtual base::TimeTicks Now() const;
|
|
|
| - // Notifies the observers that a data usage tracking session started for
|
| - // |tab_id|.
|
| - void NotifyObserversOfTrackingStarting(int32_t tab_id);
|
| -
|
| - // Notifies the observers that an active data usage tracking session ended for
|
| - // |tab_id|.
|
| - void NotifyObserversOfTrackingEnding(int32_t tab_id);
|
| -
|
| // Initiates a new tracking session with the |label| for tab with id |tab_id|.
|
| - void StartTrackingDataUse(int32_t tab_id, const std::string& label);
|
| + void StartTrackingDataUse(SessionID::id_type tab_id,
|
| + const std::string& label);
|
|
|
| // Ends the current tracking session for tab with id |tab_id|.
|
| - void EndTrackingDataUse(int32_t tab_id);
|
| + void EndTrackingDataUse(SessionID::id_type tab_id);
|
|
|
| // Compacts the tab entry map |active_tabs_| by removing expired tab entries.
|
| // After removing expired tab entries, if the size of |active_tabs_| exceeds
|
| @@ -163,9 +165,9 @@ class DataUseTabModel {
|
| // |data_use_observer_| outlives this instance.
|
| const ExternalDataUseObserver* data_use_observer_;
|
|
|
| - // List of observers waiting for tracking session start and end notifications.
|
| - const scoped_refptr<base::ObserverListThreadSafe<TabDataUseObserver>>
|
| - observer_list_;
|
| + // Collection of observers that receive tracking session start and end
|
| + // notifications. Notifications are posted on UI thread.
|
| + std::list<base::WeakPtr<TabDataUseObserver>> observers_;
|
|
|
| // Maintains the tracking sessions of multiple tabs.
|
| TabEntryMap active_tabs_;
|
| @@ -173,10 +175,11 @@ class DataUseTabModel {
|
| // Maximum number of tab entries to maintain session information about.
|
| const size_t max_tab_entries_;
|
|
|
| + // |ui_task_runner_| is used to notify TabDataUseObserver on UI thread.
|
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
|
| +
|
| base::ThreadChecker thread_checker_;
|
|
|
| - // |weak_factory_| is used for generating weak pointers to be passed to
|
| - // DataUseTabUIManager on the UI thread.
|
| base::WeakPtrFactory<DataUseTabModel> weak_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(DataUseTabModel);
|
|
|