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_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_H_ |
6 #define CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_H_ | 6 #define CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <unordered_set> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 class NavigationHandle; | 15 class NavigationHandle; |
15 class RenderFrameHost; | 16 class RenderFrameHost; |
16 } | 17 } |
17 | 18 |
18 namespace data_use_measurement { | 19 namespace data_use_measurement { |
(...skipping 27 matching lines...) Expand all Loading... |
46 // Called when a navigation is started. Propagates main frame navigation | 47 // Called when a navigation is started. Propagates main frame navigation |
47 // start to the |ascriber_| on the IO thread. NavigationHandle methods | 48 // start to the |ascriber_| on the IO thread. NavigationHandle methods |
48 // cannot be called on the IO thread, so the pointer is cast to void*. | 49 // cannot be called on the IO thread, so the pointer is cast to void*. |
49 void DidStartNavigation(content::NavigationHandle* navigation_handle); | 50 void DidStartNavigation(content::NavigationHandle* navigation_handle); |
50 | 51 |
51 // Called when the navigation is ready to be committed in a renderer. | 52 // Called when the navigation is ready to be committed in a renderer. |
52 // Propagates the event to the |ascriber_| on the IO thread. NavigationHandle | 53 // Propagates the event to the |ascriber_| on the IO thread. NavigationHandle |
53 // methods cannot be called on the IO thread, so the pointer is cast to void*. | 54 // methods cannot be called on the IO thread, so the pointer is cast to void*. |
54 void ReadyToCommitNavigation(content::NavigationHandle* navigation_handle); | 55 void ReadyToCommitNavigation(content::NavigationHandle* navigation_handle); |
55 | 56 |
| 57 // Called every time the WebContents changes visibility. Propagates the event |
| 58 // to the |ascriber_| on the IO thread. |
| 59 void WasShownOrHidden(content::RenderFrameHost* main_render_frame_host, |
| 60 bool visible); |
| 61 |
| 62 // Called when one of the render frames of a WebContents is swapped. |
| 63 void RenderFrameHostChanged(content::RenderFrameHost* old_host, |
| 64 content::RenderFrameHost* new_host); |
| 65 |
56 private: | 66 private: |
57 friend class ChromeDataUseAscriberServiceTest; | 67 friend class ChromeDataUseAscriberServiceTest; |
58 | 68 |
59 void SetDataUseAscriber(ChromeDataUseAscriber* ascriber); | 69 void SetDataUseAscriber(ChromeDataUseAscriber* ascriber); |
60 | 70 |
61 // |ascriber_| outlives this instance. | 71 // |ascriber_| outlives this instance. |
62 ChromeDataUseAscriber* ascriber_; | 72 ChromeDataUseAscriber* ascriber_; |
63 | 73 |
64 // Tracks whether |ascriber_| was set. This field is required because tests | 74 // Tracks whether |ascriber_| was set. This field is required because tests |
65 // might set |ascriber_| to nullptr. | 75 // might set |ascriber_| to nullptr. |
66 bool is_initialized_; | 76 bool is_initialized_; |
67 | 77 |
68 // Frame events might arrive from the UI thread before |ascriber_| is set. A | 78 // Frame events might arrive from the UI thread before |ascriber_| is set. A |
69 // queue of frame events that arrive before |ascriber_| is set is maintained | 79 // queue of frame events that arrive before |ascriber_| is set is maintained |
70 // in this field so that they can be propagated immediately after |ascriber_| | 80 // in this field so that they can be propagated immediately after |ascriber_| |
71 // is set. The RenderFrameHost pointers in the queues are valid for the | 81 // is set. The RenderFrameHost pointers in the queues are valid for the |
72 // duration that they are in the queue. | 82 // duration that they are in the queue. |
73 std::list<content::RenderFrameHost*> pending_frames_queue_; | 83 std::list<content::RenderFrameHost*> pending_frames_queue_; |
74 | 84 |
| 85 // WebContents visibility change events might arrive from the UI thread before |
| 86 // |ascriber_| is set. Sucn pending main render frame visibile events are |
| 87 // maintained in this set and propagated immediately after |ascriber_| is set. |
| 88 std::unordered_set<content::RenderFrameHost*> pending_visible_main_frames_; |
| 89 |
75 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriberService); | 90 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriberService); |
76 }; | 91 }; |
77 | 92 |
78 } // namespace data_use_measurement | 93 } // namespace data_use_measurement |
79 | 94 |
80 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_
H_ | 95 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_
H_ |
OLD | NEW |