OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ | 5 #ifndef CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ |
6 #define CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ | 6 #define CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "content/browser/histogram_subscriber.h" | 16 #include "content/browser/histogram_subscriber.h" |
17 | 17 |
| 18 namespace base { |
18 class MessageLoop; | 19 class MessageLoop; |
| 20 } |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 // This class maintains state that is used to upload histogram data from the | 24 // This class maintains state that is used to upload histogram data from the |
23 // various child processes, into the browser process. Such transactions are | 25 // various child processes, into the browser process. Such transactions are |
24 // usually instigated by the browser. In general, a child process will respond | 26 // usually instigated by the browser. In general, a child process will respond |
25 // by gathering snapshots of all internal histograms, calculating what has | 27 // by gathering snapshots of all internal histograms, calculating what has |
26 // changed since its last upload, and transmitting a pickled collection of | 28 // changed since its last upload, and transmitting a pickled collection of |
27 // deltas. | 29 // deltas. |
28 // | 30 // |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 static HistogramSynchronizer* GetInstance(); | 63 static HistogramSynchronizer* GetInstance(); |
62 | 64 |
63 // Contact all processes, and get them to upload to the browser any/all | 65 // Contact all processes, and get them to upload to the browser any/all |
64 // changes to histograms. This method is called from about:histograms. | 66 // changes to histograms. This method is called from about:histograms. |
65 static void FetchHistograms(); | 67 static void FetchHistograms(); |
66 | 68 |
67 // Contact all child processes, and get them to upload to the browser any/all | 69 // Contact all child processes, and get them to upload to the browser any/all |
68 // changes to histograms. When all changes have been acquired, or when the | 70 // changes to histograms. When all changes have been acquired, or when the |
69 // wait time expires (whichever is sooner), post the callback to the | 71 // wait time expires (whichever is sooner), post the callback to the |
70 // specified message loop. Note the callback is posted exactly once. | 72 // specified message loop. Note the callback is posted exactly once. |
71 static void FetchHistogramsAsynchronously(MessageLoop* callback_thread, | 73 static void FetchHistogramsAsynchronously(base::MessageLoop* callback_thread, |
72 const base::Closure& callback, | 74 const base::Closure& callback, |
73 base::TimeDelta wait_time); | 75 base::TimeDelta wait_time); |
74 | 76 |
75 private: | 77 private: |
76 friend struct DefaultSingletonTraits<HistogramSynchronizer>; | 78 friend struct DefaultSingletonTraits<HistogramSynchronizer>; |
77 | 79 |
78 class RequestContext; | 80 class RequestContext; |
79 | 81 |
80 HistogramSynchronizer(); | 82 HistogramSynchronizer(); |
81 virtual ~HistogramSynchronizer(); | 83 virtual ~HistogramSynchronizer(); |
(...skipping 20 matching lines...) Expand all Loading... |
102 // number. This method is accessible on UI thread. | 104 // number. This method is accessible on UI thread. |
103 virtual void OnHistogramDataCollected( | 105 virtual void OnHistogramDataCollected( |
104 int sequence_number, | 106 int sequence_number, |
105 const std::vector<std::string>& pickled_histograms) OVERRIDE; | 107 const std::vector<std::string>& pickled_histograms) OVERRIDE; |
106 | 108 |
107 // Set the callback_thread_ and callback_ members. If these members already | 109 // Set the callback_thread_ and callback_ members. If these members already |
108 // had values, then as a side effect, post the old callback_ to the old | 110 // had values, then as a side effect, post the old callback_ to the old |
109 // callaback_thread_. This side effect should not generally happen, but is in | 111 // callaback_thread_. This side effect should not generally happen, but is in |
110 // place to assure correctness (that any tasks that were set, are eventually | 112 // place to assure correctness (that any tasks that were set, are eventually |
111 // called, and never merely discarded). | 113 // called, and never merely discarded). |
112 void SetCallbackTaskAndThread(MessageLoop* callback_thread, | 114 void SetCallbackTaskAndThread(base::MessageLoop* callback_thread, |
113 const base::Closure& callback); | 115 const base::Closure& callback); |
114 | 116 |
115 void ForceHistogramSynchronizationDoneCallback(int sequence_number); | 117 void ForceHistogramSynchronizationDoneCallback(int sequence_number); |
116 | 118 |
117 // Internal helper function, to post task, and record callback stats. | 119 // Internal helper function, to post task, and record callback stats. |
118 void InternalPostTask(MessageLoop* thread, const base::Closure& callback); | 120 void InternalPostTask(base::MessageLoop* thread, |
| 121 const base::Closure& callback); |
119 | 122 |
120 // Gets a new sequence number to be sent to processes from browser process. | 123 // Gets a new sequence number to be sent to processes from browser process. |
121 int GetNextAvailableSequenceNumber(ProcessHistogramRequester requester); | 124 int GetNextAvailableSequenceNumber(ProcessHistogramRequester requester); |
122 | 125 |
123 // This lock_ protects access to all members. | 126 // This lock_ protects access to all members. |
124 base::Lock lock_; | 127 base::Lock lock_; |
125 | 128 |
126 // When a request is made to asynchronously update the histograms, we store | 129 // When a request is made to asynchronously update the histograms, we store |
127 // the task and thread we use to post a completion notification in | 130 // the task and thread we use to post a completion notification in |
128 // callback_ and callback_thread_. | 131 // callback_ and callback_thread_. |
129 base::Closure callback_; | 132 base::Closure callback_; |
130 MessageLoop* callback_thread_; | 133 base::MessageLoop* callback_thread_; |
131 | 134 |
132 // We don't track the actual processes that are contacted for an update, only | 135 // We don't track the actual processes that are contacted for an update, only |
133 // the count of the number of processes, and we can sometimes time-out and | 136 // the count of the number of processes, and we can sometimes time-out and |
134 // give up on a "slow to respond" process. We use a sequence_number to be | 137 // give up on a "slow to respond" process. We use a sequence_number to be |
135 // sure a response from a process is associated with the current round of | 138 // sure a response from a process is associated with the current round of |
136 // requests (and not merely a VERY belated prior response). | 139 // requests (and not merely a VERY belated prior response). |
137 // All sequence numbers used are non-negative. | 140 // All sequence numbers used are non-negative. |
138 // last_used_sequence_number_ is the most recently used number (used to avoid | 141 // last_used_sequence_number_ is the most recently used number (used to avoid |
139 // reuse for a long time). | 142 // reuse for a long time). |
140 int last_used_sequence_number_; | 143 int last_used_sequence_number_; |
141 | 144 |
142 // The sequence number used by the most recent asynchronous update request to | 145 // The sequence number used by the most recent asynchronous update request to |
143 // contact all processes. | 146 // contact all processes. |
144 int async_sequence_number_; | 147 int async_sequence_number_; |
145 | 148 |
146 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); | 149 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); |
147 }; | 150 }; |
148 | 151 |
149 } // namespace content | 152 } // namespace content |
150 | 153 |
151 #endif // CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ | 154 #endif // CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ |
OLD | NEW |