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

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

Issue 2385103003: [DesktopSessionDurationTracker] Remove visibility-switch timeout from session length. (Closed)
Patch Set: Address nits. Created 4 years, 2 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_SESSION_DURATION_DESKTOP_SESSION_DURATION _TRACKER_H_ 5 #ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION _TRACKER_H_
6 #define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION _TRACKER_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"
(...skipping 14 matching lines...) Expand all
25 // Returns true if the |DesktopSessionDurationTracker| instance has been 25 // Returns true if the |DesktopSessionDurationTracker| instance has been
26 // created. 26 // created.
27 static bool IsInitialized(); 27 static bool IsInitialized();
28 28
29 // Returns the |DesktopSessionDurationTracker| instance. 29 // Returns the |DesktopSessionDurationTracker| instance.
30 static DesktopSessionDurationTracker* Get(); 30 static DesktopSessionDurationTracker* Get();
31 31
32 // Called when user interaction with the browser is caught. 32 // Called when user interaction with the browser is caught.
33 void OnUserEvent(); 33 void OnUserEvent();
34 34
35 // Called when visibility of the browser changes. 35 // Called when visibility of the browser changes. These events can be delayed
36 void OnVisibilityChanged(bool visible); 36 // due to timeout logic, the extent of which can be communicated via
37 // |time_ago|. This time is used to correct the session duration.
38 void OnVisibilityChanged(bool visible, base::TimeDelta time_ago);
37 39
38 bool is_visible() const { return is_visible_; } 40 bool is_visible() const { return is_visible_; }
39 bool in_session() const { return in_session_; } 41 bool in_session() const { return in_session_; }
40 bool is_audio_playing() const { return is_audio_playing_; } 42 bool is_audio_playing() const { return is_audio_playing_; }
41 43
42 void SetInactivityTimeoutForTesting(int seconds) { 44 void SetInactivityTimeoutForTesting(int seconds) {
43 inactivity_timeout_ = base::TimeDelta::FromSeconds(seconds); 45 inactivity_timeout_ = base::TimeDelta::FromSeconds(seconds);
44 } 46 }
45 47
46 protected: 48 protected:
47 DesktopSessionDurationTracker(); 49 DesktopSessionDurationTracker();
48 ~DesktopSessionDurationTracker() override; 50 ~DesktopSessionDurationTracker() override;
49 51
50 // AudibleContentsTracker::Observer 52 // AudibleContentsTracker::Observer
51 void OnAudioStart() override; 53 void OnAudioStart() override;
52 void OnAudioEnd() override; 54 void OnAudioEnd() override;
53 55
54 // Decides whether session should be ended. Called when timer for inactivity 56 // Decides whether session should be ended. Called when timer for inactivity
55 // timeout was fired. Overridden by tests. 57 // timeout was fired. Overridden by tests.
56 virtual void OnTimerFired(); 58 virtual void OnTimerFired();
57 59
58 private: 60 private:
59 // Starts timer based on |inactivity_timeout_|. 61 // Starts timer based on |inactivity_timeout_|.
60 void StartTimer(base::TimeDelta duration); 62 void StartTimer(base::TimeDelta duration);
61 63
62 // Marks the start of the session. 64 // Marks the start of the session.
63 void StartSession(); 65 void StartSession();
64 66
65 // Ends the session and saves session information into histograms. 67 // Ends the session and saves session information into histograms.
66 void EndSession(); 68 // |time_to_discount| contains the amount of time that should be removed from
69 // the apparent session length due to timeout logic.
70 void EndSession(base::TimeDelta time_to_discount);
67 71
68 // Sets |inactivity_timeout_| based on variation params. 72 // Sets |inactivity_timeout_| based on variation params.
69 void InitInactivityTimeout(); 73 void InitInactivityTimeout();
70 74
71 // Used for marking start if the session. 75 // Used for marking start if the session.
72 base::TimeTicks session_start_; 76 base::TimeTicks session_start_;
73 77
74 // Used for marking last user interaction. 78 // Used for marking last user interaction.
75 base::TimeTicks last_user_event_; 79 base::TimeTicks last_user_event_;
76 80
(...skipping 12 matching lines...) Expand all
89 AudibleContentsTracker audio_tracker_; 93 AudibleContentsTracker audio_tracker_;
90 94
91 base::WeakPtrFactory<DesktopSessionDurationTracker> weak_factory_; 95 base::WeakPtrFactory<DesktopSessionDurationTracker> weak_factory_;
92 96
93 DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationTracker); 97 DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationTracker);
94 }; 98 };
95 99
96 } // namespace metrics 100 } // namespace metrics
97 101
98 #endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURAT ION_TRACKER_H_ 102 #endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURAT ION_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698