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

Side by Side Diff: chrome/browser/android/vr_shell/vr_usage_monitor.h

Issue 2572013003: Remove unnecessary threading concerns from VrMetricsHelper. (Closed)
Patch Set: Created 4 years 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_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_ 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_ 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_
7 7
8 #include "base/threading/platform_thread.h" 8 #include <memory>
9
10 #include "base/memory/weak_ptr.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "content/public/browser/navigation_handle.h" 12 #include "content/public/browser/navigation_handle.h"
11 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
13 15
14 namespace vr_shell { 16 namespace vr_shell {
15 17
16 enum class VRMode { 18 enum class VRMode {
17 NO_VR = 0, 19 NO_VR = 0,
18 VR_BROWSER = 1, // VR Shell. 20 VR_BROWSER = 1, // VR Shell.
(...skipping 25 matching lines...) Expand all
44 // config members: 46 // config members:
45 // time between stop and start to count as same session 47 // time between stop and start to count as same session
46 base::TimeDelta maximum_session_gap_time_; 48 base::TimeDelta maximum_session_gap_time_;
47 49
48 // minimum time between start and stop to add to duration 50 // minimum time between start and stop to add to duration
49 base::TimeDelta minimum_duration_; 51 base::TimeDelta minimum_duration_;
50 52
51 DISALLOW_COPY_AND_ASSIGN(SessionTimer); 53 DISALLOW_COPY_AND_ASSIGN(SessionTimer);
52 }; 54 };
53 55
54 // Most methods of this class are not threadsafe - they must be called 56 // This class is not threadsafe and must only be used from the main thread.
55 // on the Browser's main thread. This happens by default except for 57 class VrMetricsHelper : public content::WebContentsObserver {
56 // SetWebVREnabled and SetVRActive, where we'll post a message to get to the
57 // correct thread.
58 // Destruction must happen on the main thread, or there could be corruption when
59 // WebContentsObserver unregisters itself from the web_contents_.
60 // There are DCHECKS to ensure these threading rules are satisfied.
61 class VrMetricsHelper : public content::WebContentsObserver,
62 public base::RefCountedThreadSafe<VrMetricsHelper> {
63 public: 58 public:
64 explicit VrMetricsHelper(content::WebContents*); 59 explicit VrMetricsHelper(content::WebContents*);
65 60 ~VrMetricsHelper() override;
66 void SetWebVREnabled(bool is_webvr_presenting); 61 void SetWebVREnabled(bool is_webvr_presenting);
67 void SetVRActive(bool is_vr_enabled); 62 void SetVRActive(bool is_vr_enabled);
68 63
64 private:
69 // WebContentObserver 65 // WebContentObserver
70 void MediaStartedPlaying(const MediaPlayerInfo& media_info, 66 void MediaStartedPlaying(const MediaPlayerInfo& media_info,
71 const MediaPlayerId&) override; 67 const MediaPlayerId&) override;
72 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, 68 void MediaStoppedPlaying(const MediaPlayerInfo& media_info,
73 const MediaPlayerId&) override; 69 const MediaPlayerId&) override;
74 void DidFinishNavigation(content::NavigationHandle*) override; 70 void DidFinishNavigation(content::NavigationHandle*) override;
75 void DidToggleFullscreenModeForTab(bool entered_fullscreen, 71 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
76 bool will_cause_resize) override; 72 bool will_cause_resize) override;
77 73
78 protected:
79 friend class base::RefCountedThreadSafe<VrMetricsHelper>;
80 ~VrMetricsHelper() override;
81
82 void SetWebVREnabledOnMainThread(bool is_webvr_presenting);
83 void SetVRActiveOnMainThread(bool is_vr_enabled);
84
85 void SetVrMode(VRMode mode); 74 void SetVrMode(VRMode mode);
86 void UpdateMode(); 75 void UpdateMode();
87 76
88 std::unique_ptr<SessionTimer> mode_video_timer_; 77 std::unique_ptr<SessionTimer> mode_video_timer_;
89 std::unique_ptr<SessionTimer> session_video_timer_; 78 std::unique_ptr<SessionTimer> session_video_timer_;
90 std::unique_ptr<SessionTimer> mode_timer_; 79 std::unique_ptr<SessionTimer> mode_timer_;
91 std::unique_ptr<SessionTimer> session_timer_; 80 std::unique_ptr<SessionTimer> session_timer_;
92 81
93 VRMode mode_ = VRMode::NO_VR; 82 VRMode mode_ = VRMode::NO_VR;
94 83
95 // state that gets translated into vr_mode: 84 // state that gets translated into vr_mode:
96 bool is_fullscreen_ = false; 85 bool is_fullscreen_ = false;
97 bool is_webvr_ = false; 86 bool is_webvr_ = false;
98 bool is_vr_enabled_ = false; 87 bool is_vr_enabled_ = false;
99 88
100 int num_videos_playing_ = 0; 89 int num_videos_playing_ = 0;
101 int num_session_navigation_ = 0; 90 int num_session_navigation_ = 0;
102 int num_session_video_playback_ = 0; 91 int num_session_video_playback_ = 0;
103 92
104 GURL origin_; 93 GURL origin_;
105
106 // not thread safe, so ensure we are on the same thread at all times:
107 base::PlatformThreadId thread_id_;
108 }; 94 };
109 95
110 } // namespace vr_shell 96 } // namespace vr_shell
111 97
112 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_ 98 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_USAGE_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.cc ('k') | chrome/browser/android/vr_shell/vr_usage_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698