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

Side by Side Diff: chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h

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

Powered by Google App Engine
This is Rietveld 408576698