Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "base/timer/timer.h" | |
| 12 | |
| 13 namespace metrics { | |
| 14 | |
| 15 // Class for tracking and recording user engagement based on browser visibility, | |
| 16 // audio and user interaction. | |
| 17 class DesktopEngagementService { | |
| 18 public: | |
| 19 // Creates the |DesktopEngagementService| instance and initializes the | |
| 20 // observes that notify to it. | |
| 21 static void Initialize(); | |
| 22 | |
| 23 // Returns true if the |DesktopEngagementService| instance has been created. | |
| 24 static bool IsInitialized(); | |
| 25 | |
| 26 // Returns the |DesktopEngagementService| instance. | |
| 27 static DesktopEngagementService* Get(); | |
| 28 | |
| 29 // Called when user interaction with the browser is caught. | |
| 30 void OnUserEvent(); | |
| 31 | |
| 32 // Called when visibility of the browser changes. | |
| 33 void OnVisibilityChanged(bool visible); | |
| 34 | |
| 35 // Called when audio starts or ends. | |
| 36 void OnAudioStart(); | |
| 37 void OnAudioEnd(); | |
| 38 | |
| 39 protected: | |
| 40 DesktopEngagementService(); | |
| 41 ~DesktopEngagementService(); | |
| 42 | |
| 43 // Decides whether session should be ended. Called when timer for inactivity | |
| 44 // timeout was fired. Overridden by tests. | |
| 45 virtual void OnTimerFired(); | |
| 46 | |
| 47 // Used for marking current state of the user engagement. | |
|
Alexei Svitkine (slow)
2016/07/28 18:37:22
Data members should not be protected, per the styl
gayane -on leave until 09-2017
2016/07/28 21:21:34
moved the functions to public.
| |
| 48 bool is_visible_ = false; | |
| 49 bool in_session_ = false; | |
| 50 bool is_audio_playing_ = false; | |
| 51 bool is_first_session_ = true; | |
| 52 | |
| 53 // Timeout for waiting for user interaction. | |
| 54 base::TimeDelta inactivity_timeout_; | |
| 55 | |
| 56 private: | |
| 57 // Starts timer based on |inactivity_timeout_|. | |
| 58 void StartTimer(base::TimeDelta duration); | |
| 59 | |
| 60 // Marks the start of the session. | |
| 61 void StartSession(); | |
| 62 | |
| 63 // Ends the session and saves session information into histograms. | |
| 64 void EndSession(); | |
| 65 | |
| 66 // Sets |inactivity_timeout_| based on variation params. | |
| 67 void InitInactivityTimeout(); | |
| 68 | |
| 69 // Used for marking start if the session. | |
| 70 base::TimeTicks session_start_; | |
| 71 | |
| 72 // Used for marking last user interaction. | |
| 73 base::TimeTicks last_user_event_; | |
| 74 | |
| 75 base::OneShotTimer timer_; | |
| 76 | |
| 77 base::WeakPtrFactory<DesktopEngagementService> weak_factory_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(DesktopEngagementService); | |
| 80 }; | |
| 81 | |
| 82 } // namespace metrics | |
| 83 | |
| 84 #endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_ H_ | |
| OLD | NEW |