Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h

Issue 2333113002: Rename DesktopEngagement* to DesktopSessionDuration*. (Closed)
Patch Set: Change name Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ 5 #ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION _TRACKER_H_
6 #define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ 6 #define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION _TRACKER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h" 12 #include "chrome/browser/metrics/desktop_session_duration/audible_contents_track er.h"
13 #include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h " 13 #include "chrome/browser/metrics/desktop_session_duration/chrome_visibility_obse rver.h"
14 14
15 namespace metrics { 15 namespace metrics {
16 16
17 // Class for tracking and recording user engagement based on browser visibility, 17 // Class for tracking and recording session length on desktop based on browser
18 // audio and user interaction. 18 // visibility, audio and user interaction.
19 class DesktopEngagementService : public AudibleContentsTracker::Observer { 19 class DesktopSessionDurationTracker : public AudibleContentsTracker::Observer {
20 public: 20 public:
21 // Creates the |DesktopEngagementService| instance and initializes the 21 // Creates the |DesktopSessionDurationTracker| instance and initializes the
22 // observes that notify to it. 22 // observers that notify to it.
23 static void Initialize(); 23 static void Initialize();
24 24
25 // Returns true if the |DesktopEngagementService| instance has been created. 25 // Returns true if the |DesktopSessionDurationTracker| instance has been
26 // created.
26 static bool IsInitialized(); 27 static bool IsInitialized();
27 28
28 // Returns the |DesktopEngagementService| instance. 29 // Returns the |DesktopSessionDurationTracker| instance.
29 static DesktopEngagementService* Get(); 30 static DesktopSessionDurationTracker* Get();
30 31
31 // Called when user interaction with the browser is caught. 32 // Called when user interaction with the browser is caught.
32 void OnUserEvent(); 33 void OnUserEvent();
33 34
34 // Called when visibility of the browser changes. 35 // Called when visibility of the browser changes.
35 void OnVisibilityChanged(bool visible); 36 void OnVisibilityChanged(bool visible);
36 37
37 bool is_visible() const { return is_visible_; } 38 bool is_visible() const { return is_visible_; }
38 bool in_session() const { return in_session_; } 39 bool in_session() const { return in_session_; }
39 bool is_audio_playing() const { return is_audio_playing_; } 40 bool is_audio_playing() const { return is_audio_playing_; }
40 41
41 void SetInactivityTimeoutForTesting(int seconds) { 42 void SetInactivityTimeoutForTesting(int seconds) {
42 inactivity_timeout_ = base::TimeDelta::FromSeconds(seconds); 43 inactivity_timeout_ = base::TimeDelta::FromSeconds(seconds);
43 } 44 }
44 45
45 protected: 46 protected:
46 DesktopEngagementService(); 47 DesktopSessionDurationTracker();
47 ~DesktopEngagementService() override; 48 ~DesktopSessionDurationTracker() override;
48 49
49 // AudibleContentsTracker::Observer 50 // AudibleContentsTracker::Observer
50 void OnAudioStart() override; 51 void OnAudioStart() override;
51 void OnAudioEnd() override; 52 void OnAudioEnd() override;
52 53
53 // Decides whether session should be ended. Called when timer for inactivity 54 // Decides whether session should be ended. Called when timer for inactivity
54 // timeout was fired. Overridden by tests. 55 // timeout was fired. Overridden by tests.
55 virtual void OnTimerFired(); 56 virtual void OnTimerFired();
56 57
57 private: 58 private:
(...skipping 22 matching lines...) Expand all
80 bool is_first_session_ = true; 81 bool is_first_session_ = true;
81 82
82 // Timeout for waiting for user interaction. 83 // Timeout for waiting for user interaction.
83 base::TimeDelta inactivity_timeout_; 84 base::TimeDelta inactivity_timeout_;
84 85
85 base::OneShotTimer timer_; 86 base::OneShotTimer timer_;
86 87
87 ChromeVisibilityObserver visibility_observer_; 88 ChromeVisibilityObserver visibility_observer_;
88 AudibleContentsTracker audio_tracker_; 89 AudibleContentsTracker audio_tracker_;
89 90
90 base::WeakPtrFactory<DesktopEngagementService> weak_factory_; 91 base::WeakPtrFactory<DesktopSessionDurationTracker> weak_factory_;
91 92
92 DISALLOW_COPY_AND_ASSIGN(DesktopEngagementService); 93 DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationTracker);
93 }; 94 };
94 95
95 } // namespace metrics 96 } // namespace metrics
96 97
97 #endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_ H_ 98 #endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURAT ION_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698