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 <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 | |
| 16 // Class for tracking and recording user engagement based on browser visibility, | |
| 17 // audio and user interaction. | |
| 18 class DesktopEngagementService { | |
| 19 public: | |
| 20 // Creates the |DesktopEngagementService| instance and initializes the | |
| 21 // observes that notify to it. | |
| 22 static void Initialize(); | |
| 23 // Returns true if the |DesktopEngagementService| instance has been created. | |
|
Alexei Svitkine (slow)
2016/07/26 22:00:41
Please add empty lines between functions. Fix thro
gayane -on leave until 09-2017
2016/07/27 21:10:25
Done.
| |
| 24 static bool IsInitialized(); | |
| 25 // Returns the |DesktopEngagementService| instance. | |
| 26 static DesktopEngagementService* Get(); | |
| 27 | |
| 28 // Called when user interaction with the browser is caught. | |
| 29 void OnUserEvent(); | |
| 30 | |
| 31 // Called when visibility of the browser changes. | |
| 32 void OnVisibilityChanged(bool visible); | |
| 33 | |
| 34 // Called when audio starts or ends. | |
| 35 void OnAudioStart(); | |
| 36 void OnAudioEnd(); | |
| 37 | |
| 38 private: | |
| 39 friend class MockDesktopEngagementService; | |
| 40 | |
| 41 DesktopEngagementService(); | |
| 42 ~DesktopEngagementService(); | |
| 43 | |
| 44 // Decides whether session should be ended. Called when timer for inactivity | |
| 45 // timeout was fired. Overridden by tests. | |
| 46 virtual void OnTimerFired(); | |
| 47 // Starts timer based on |inactivity_timeout_|. | |
| 48 void StartTimer(base::TimeDelta duration); | |
| 49 | |
| 50 // Marks the start of the session. | |
| 51 void StartSession(); | |
| 52 // Ends the session and saves session information into histograms. | |
| 53 void EndSession(); | |
| 54 | |
| 55 // Sets |inactivity_timeout_| based on variation params. | |
| 56 void InitInactivityTimeout(); | |
| 57 | |
| 58 // Used for marking start if the session. | |
| 59 base::TimeTicks session_start_; | |
| 60 // Used for marking last user interaction. | |
| 61 base::TimeTicks last_user_event_; | |
| 62 | |
| 63 // Used for marking current state of the user engagement. | |
| 64 bool is_visible_ = false; | |
| 65 bool in_session_ = false; | |
| 66 bool is_audio_playing_ = false; | |
| 67 bool is_first_session_ = true; | |
| 68 base::TimeDelta inactivity_timeout_; | |
| 69 | |
| 70 base::OneShotTimer timer_; | |
| 71 | |
| 72 base::WeakPtrFactory<DesktopEngagementService> weak_factory_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(DesktopEngagementService); | |
| 75 }; | |
| 76 | |
| 77 #endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_ H_ | |
| OLD | NEW |