| OLD | NEW |
| (Empty) | |
| 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_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_H_ |
| 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "chrome/browser/ui/browser_list_observer.h" |
| 10 |
| 11 namespace metrics { |
| 12 |
| 13 // Observer for tracking browser visibility events. |
| 14 class ChromeVisibilityObserver : public chrome::BrowserListObserver { |
| 15 public: |
| 16 ChromeVisibilityObserver(); |
| 17 ~ChromeVisibilityObserver() override; |
| 18 |
| 19 // Initialize |ChromeVisibilityObserver| instance which observes |BrowserList| |
| 20 // for browser visibility changes. |
| 21 static void Initialize(); |
| 22 |
| 23 protected: |
| 24 // Notifies |DesktopEngagementService| of visibility changes. Overridden by |
| 25 // tests. |
| 26 virtual void SendVisibilityChangeEvent(bool active); |
| 27 |
| 28 private: |
| 29 // Cancels visibility change in case when the browser becomes visible after a |
| 30 // short gap. |
| 31 void CancelVisibilityChange(); |
| 32 |
| 33 // chrome::BrowserListObserver: |
| 34 void OnBrowserSetLastActive(Browser* browser) override; |
| 35 void OnBrowserNoLongerActive(Browser* browser) override; |
| 36 void OnBrowserRemoved(Browser* browser) override; |
| 37 |
| 38 // Sets |visibility_gap_timeout_| based on variation params. |
| 39 void InitVisibilityGapTimeout(); |
| 40 |
| 41 // Timeout interval for waiting after loss of visibility. This allows merging |
| 42 // two visibility session if they happened very shortly after each other, for |
| 43 // example, when user switching between two browser windows. |
| 44 base::TimeDelta visibility_gap_timeout_; |
| 45 |
| 46 base::WeakPtrFactory<ChromeVisibilityObserver> weak_factory_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(ChromeVisibilityObserver); |
| 49 }; |
| 50 |
| 51 } // namespace metrics |
| 52 |
| 53 #endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_
H_ |
| OLD | NEW |