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_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_ 6 #define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_ 7 8 #include "base/macros.h" 9 #include "content/public/browser/render_widget_host.h" 10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_user_data.h" 13 #include "third_party/blink/public/common/input/web_input_event.h" 14 15 namespace metrics { 16 17 class DesktopSessionDurationTracker; 18 19 // Tracks user input events from web contents and notifies 20 // |DesktopSessionDurationTracker|. 21 class DesktopSessionDurationObserver 22 : public content::WebContentsObserver, 23 public content::WebContentsUserData<DesktopSessionDurationObserver>, 24 public content::RenderWidgetHost::InputEventObserver { 25 public: 26 DesktopSessionDurationObserver(content::WebContents* web_contents, 27 DesktopSessionDurationTracker* service); 28 ~DesktopSessionDurationObserver() override; 29 30 static DesktopSessionDurationObserver* CreateForWebContents( 31 content::WebContents* web_contents); 32 33 private: 34 friend class content::WebContentsUserData<DesktopSessionDurationObserver>; 35 36 // Register / Unregister input event callback to given RenderViewHost 37 void RegisterInputEventObserver(content::RenderViewHost* host); 38 void UnregisterInputEventObserver(content::RenderViewHost* host); 39 40 // content::RenderWidgetHost::InputEventObserver: 41 void OnInputEvent(const blink::WebInputEvent& event) override; 42 43 // content::WebContentsObserver: 44 void RenderViewHostChanged(content::RenderViewHost* old_host, 45 content::RenderViewHost* new_host) override; 46 47 DesktopSessionDurationTracker* service_; 48 49 WEB_CONTENTS_USER_DATA_KEY_DECL(); 50 51 DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationObserver); 52 }; 53 54 } // namespace metrics 55 56 #endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_ 57