OLD | NEW |
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_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ |
6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ | 6 #define CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 class WebContents; | 12 class WebContents; |
13 } | 13 } |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 class SiteEngagementService; | 16 class SiteEngagementService; |
17 | 17 |
18 class SiteEngagementObserver { | 18 class SiteEngagementObserver { |
19 public: | 19 public: |
20 // Called when the engagement for |url| loaded in |web_contents| increases to | 20 // Called when the engagement for |url| loaded in |web_contents| increases to |
21 // |score|. |is_hidden| is true if the engagement occurred when |web_contents| | 21 // |score|. |is_hidden| is true if the engagement occurred when |web_contents| |
22 // was hidden (e.g. in the background). | 22 // was hidden (e.g. in the background). This method may be run on user input, |
23 // This method may be run on user input, so observers *must not* perform any | 23 // so observers *must not* perform any expensive tasks here. |web_contents| |
24 // expensive tasks here. | 24 // may be null if the engagement has increased when |url| is not in a tab, |
| 25 // e.g. from a notification interaction. |
25 virtual void OnEngagementIncreased(content::WebContents* web_contents, | 26 virtual void OnEngagementIncreased(content::WebContents* web_contents, |
26 const GURL& url, | 27 const GURL& url, |
27 double score) {} | 28 double score) {} |
28 | 29 |
29 protected: | 30 protected: |
30 explicit SiteEngagementObserver(SiteEngagementService* service); | 31 explicit SiteEngagementObserver(SiteEngagementService* service); |
31 | 32 |
32 SiteEngagementObserver(); | 33 SiteEngagementObserver(); |
33 | 34 |
34 ~SiteEngagementObserver(); | 35 ~SiteEngagementObserver(); |
35 | 36 |
36 // Returns the site engagement service which this object is observing. | 37 // Returns the site engagement service which this object is observing. |
37 SiteEngagementService* GetSiteEngagementService() const; | 38 SiteEngagementService* GetSiteEngagementService() const; |
38 | 39 |
39 // Begin observing |service| for engagement increases. | 40 // Begin observing |service| for engagement increases. |
40 // To stop observing, call Observe(nullptr). | 41 // To stop observing, call Observe(nullptr). |
41 void Observe(SiteEngagementService* service); | 42 void Observe(SiteEngagementService* service); |
42 | 43 |
43 private: | 44 private: |
44 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, Observers); | 45 FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, Observers); |
45 SiteEngagementService* service_; | 46 SiteEngagementService* service_; |
46 | 47 |
47 DISALLOW_COPY_AND_ASSIGN(SiteEngagementObserver); | 48 DISALLOW_COPY_AND_ASSIGN(SiteEngagementObserver); |
48 }; | 49 }; |
49 | 50 |
50 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ | 51 #endif // CHROME_BROWSER_ENGAGEMENT_SITE_ENGAGEMENT_OBSERVER_H_ |
OLD | NEW |