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

Side by Side Diff: chrome/browser/data_use_measurement/chrome_data_use_ascriber_service.h

Issue 2572823002: Propogate the tab foreground, background change events to data use (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_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
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 void RenderFrameHostChanged(content::RenderFrameHost* old_host,
RyanSturm 2016/12/13 22:04:20 nit: Can you add a class comment?
Raj 2016/12/14 23:00:50 Done.
63 content::RenderFrameHost* new_host);
64
56 private: 65 private:
57 friend class ChromeDataUseAscriberServiceTest; 66 friend class ChromeDataUseAscriberServiceTest;
58 67
59 void SetDataUseAscriber(ChromeDataUseAscriber* ascriber); 68 void SetDataUseAscriber(ChromeDataUseAscriber* ascriber);
60 69
61 // |ascriber_| outlives this instance. 70 // |ascriber_| outlives this instance.
62 ChromeDataUseAscriber* ascriber_; 71 ChromeDataUseAscriber* ascriber_;
63 72
64 // Tracks whether |ascriber_| was set. This field is required because tests 73 // Tracks whether |ascriber_| was set. This field is required because tests
65 // might set |ascriber_| to nullptr. 74 // might set |ascriber_| to nullptr.
66 bool is_initialized_; 75 bool is_initialized_;
67 76
68 // Frame events might arrive from the UI thread before |ascriber_| is set. A 77 // 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 78 // 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_| 79 // 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 80 // is set. The RenderFrameHost pointers in the queues are valid for the
72 // duration that they are in the queue. 81 // duration that they are in the queue.
73 std::list<content::RenderFrameHost*> pending_frames_queue_; 82 std::list<content::RenderFrameHost*> pending_frames_queue_;
74 83
84 // WebContents visibility change events might arrive from the UI thread before
85 // |ascriber_| is set. Sucn pending main render frame visibile events are
86 // maintained in this set and propagated immediately after |ascriber_| is set.
87 std::unordered_set<content::RenderFrameHost*> pending_visible_main_frames_;
88
75 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriberService); 89 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriberService);
76 }; 90 };
77 91
78 } // namespace data_use_measurement 92 } // namespace data_use_measurement
79 93
80 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_ H_ 94 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_SERVICE_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698