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

Side by Side Diff: chrome/browser/metrics/histogram_synchronizer.h

Issue 8603013: base::Bind() conversion for MetricsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/metrics/histogram_synchronizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_METRICS_HISTOGRAM_SYNCHRONIZER_H_ 5 #ifndef CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_
6 #define CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_ 6 #define CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/condition_variable.h" 15 #include "base/synchronization/condition_variable.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 18
18 class MessageLoop; 19 class MessageLoop;
19 class Task;
20 20
21 // This class maintains state that is used to upload histogram data from the 21 // This class maintains state that is used to upload histogram data from the
22 // various renderer processes, into the browser process. Such transactions are 22 // various renderer processes, into the browser process. Such transactions are
23 // usually instigated by the browser. In general, a renderer process will 23 // usually instigated by the browser. In general, a renderer process will
24 // respond by gathering snapshots of all internal histograms, calculating what 24 // respond by gathering snapshots of all internal histograms, calculating what
25 // has changed since its last upload, and transmitting a pickled collection of 25 // has changed since its last upload, and transmitting a pickled collection of
26 // deltas. 26 // deltas.
27 // 27 //
28 // There are actually two modes of update request. One is synchronous (and 28 // There are actually two modes of update request. One is synchronous (and
29 // blocks the UI thread, waiting to populate an about:histograms tab) and the 29 // blocks the UI thread, waiting to populate an about:histograms tab) and the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 static HistogramSynchronizer* CurrentSynchronizer(); 68 static HistogramSynchronizer* CurrentSynchronizer();
69 69
70 // Contact all renderers, and get them to upload to the browser any/all 70 // Contact all renderers, and get them to upload to the browser any/all
71 // changes to histograms. Return when all changes have been acquired, or when 71 // changes to histograms. Return when all changes have been acquired, or when
72 // the wait time expires (whichever is sooner). This method is called on the 72 // the wait time expires (whichever is sooner). This method is called on the
73 // main UI thread from about:histograms. 73 // main UI thread from about:histograms.
74 void FetchRendererHistogramsSynchronously(base::TimeDelta wait_time); 74 void FetchRendererHistogramsSynchronously(base::TimeDelta wait_time);
75 75
76 // Contact all renderers, and get them to upload to the browser any/all 76 // Contact all renderers, and get them to upload to the browser any/all
77 // changes to histograms. When all changes have been acquired, or when the 77 // changes to histograms. When all changes have been acquired, or when the
78 // wait time expires (whichever is sooner), post the callback_task to the 78 // wait time expires (whichever is sooner), post the callback to the
79 // specified thread. Note the callback_task is posted exactly once. 79 // specified message loop. Note the callback is posted exactly once.
80 static void FetchRendererHistogramsAsynchronously( 80 static void FetchRendererHistogramsAsynchronously(
81 MessageLoop* callback_thread, Task* callback_task, int wait_time); 81 MessageLoop* callback_thread,
82 const base::Closure& callback,
83 int wait_time);
82 84
83 // This method is called on the IO thread. Deserializes the histograms and 85 // This method is called on the IO thread. Deserializes the histograms and
84 // records that we have received histograms from a renderer process. 86 // records that we have received histograms from a renderer process.
85 static void DeserializeHistogramList( 87 static void DeserializeHistogramList(
86 int sequence_number, const std::vector<std::string>& histograms); 88 int sequence_number, const std::vector<std::string>& histograms);
87 89
88 private: 90 private:
89 friend class base::RefCountedThreadSafe<HistogramSynchronizer>; 91 friend class base::RefCountedThreadSafe<HistogramSynchronizer>;
90 92
91 ~HistogramSynchronizer(); 93 ~HistogramSynchronizer();
92 94
93 // Establish a new sequence_number_, and use it to notify all the renderers of 95 // Establish a new sequence_number_, and use it to notify all the renderers of
94 // the need to supply, to the browser, any changes in their histograms. 96 // the need to supply, to the browser, any changes in their histograms.
95 // The argument indicates whether this will set async_sequence_number_ or 97 // The argument indicates whether this will set async_sequence_number_ or
96 // synchronous_sequence_number_. 98 // synchronous_sequence_number_.
97 // Return the sequence number that was used. 99 // Return the sequence number that was used.
98 int NotifyAllRenderers(RendererHistogramRequester requester); 100 int NotifyAllRenderers(RendererHistogramRequester requester);
99 101
100 // Records that we are waiting for one less histogram from a renderer for the 102 // Records that we are waiting for one less histogram from a renderer for the
101 // given sequence number. If we have received a response from all renderers, 103 // given sequence number. If we have received a response from all renderers,
102 // either signal the waiting process or call the callback function. 104 // either signal the waiting process or call the callback function.
103 void DecrementPendingRenderers(int sequence_number); 105 void DecrementPendingRenderers(int sequence_number);
104 106
105 // Set the callback_thread_ and callback_task_ members. If these members 107 // Set the callback_thread_ and callback_ members. If these members already
106 // already had values, then as a side effect, post the old callback_task_ to 108 // had values, then as a side effect, post the old callback_ to the old
107 // the old callaback_thread_. This side effect should not generally happen, 109 // callaback_thread_. This side effect should not generally happen, but is in
108 // but is in place to assure correctness (that any tasks that were set, are 110 // place to assure correctness (that any tasks that were set, are eventually
109 // eventually called, and never merely discarded). 111 // called, and never merely discarded).
110 void SetCallbackTaskAndThread(MessageLoop* callback_thread, 112 void SetCallbackTaskAndThread(MessageLoop* callback_thread,
111 Task* callback_task); 113 const base::Closure& callback);
112 114
113 void ForceHistogramSynchronizationDoneCallback(int sequence_number); 115 void ForceHistogramSynchronizationDoneCallback(int sequence_number);
114 116
115 // Gets a new sequence number to be sent to renderers from browser process and 117 // Gets a new sequence number to be sent to renderers from browser process and
116 // set the number of pending responses for the given type to renderer_count. 118 // set the number of pending responses for the given type to renderer_count.
117 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster, 119 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster,
118 int renderer_count); 120 int renderer_count);
119 121
120 // Internal helper function, to post task, and record callback stats. 122 // Internal helper function, to post task, and record callback stats.
121 void InternalPostTask(MessageLoop* thread, Task* task, 123 void InternalPostTask(MessageLoop* thread,
122 int unresponsive_renderers, const base::TimeTicks& started); 124 const base::Closure& callback,
125 int unresponsive_renderers,
126 const base::TimeTicks& started);
123 127
124 // This lock_ protects access to all members. 128 // This lock_ protects access to all members.
125 base::Lock lock_; 129 base::Lock lock_;
126 130
127 // This condition variable is used to block caller of the synchronous request 131 // This condition variable is used to block caller of the synchronous request
128 // to update histograms, and to signal that thread when updates are completed. 132 // to update histograms, and to signal that thread when updates are completed.
129 base::ConditionVariable received_all_renderer_histograms_; 133 base::ConditionVariable received_all_renderer_histograms_;
130 134
131 // When a request is made to asynchronously update the histograms, we store 135 // When a request is made to asynchronously update the histograms, we store
132 // the task and thread we use to post a completion notification in 136 // the task and thread we use to post a completion notification in
133 // callback_task_ and callback_thread_. 137 // callback_ and callback_thread_.
134 Task* callback_task_; 138 base::Closure callback_;
135 MessageLoop* callback_thread_; 139 MessageLoop* callback_thread_;
136 140
137 // We don't track the actual renderers that are contacted for an update, only 141 // We don't track the actual renderers that are contacted for an update, only
138 // the count of the number of renderers, and we can sometimes time-out and 142 // the count of the number of renderers, and we can sometimes time-out and
139 // give up on a "slow to respond" renderer. We use a sequence_number to be 143 // give up on a "slow to respond" renderer. We use a sequence_number to be
140 // sure a response from a renderer is associated with the current round of 144 // sure a response from a renderer is associated with the current round of
141 // requests (and not merely a VERY belated prior response). 145 // requests (and not merely a VERY belated prior response).
142 // All sequence numbers used are non-negative. 146 // All sequence numbers used are non-negative.
143 // last_used_sequence_number_ is the most recently used number (used to avoid 147 // last_used_sequence_number_ is the most recently used number (used to avoid
144 // reuse for a long time). 148 // reuse for a long time).
(...skipping 23 matching lines...) Expand all
168 // portion of main(). It initializes globals to provide support for all future 172 // portion of main(). It initializes globals to provide support for all future
169 // calls. This object is created on the UI thread, and it is destroyed after 173 // calls. This object is created on the UI thread, and it is destroyed after
170 // all the other threads have gone away. As a result, it is ok to call it 174 // all the other threads have gone away. As a result, it is ok to call it
171 // from the UI thread (for UMA uploads), or for about:histograms. 175 // from the UI thread (for UMA uploads), or for about:histograms.
172 static HistogramSynchronizer* histogram_synchronizer_; 176 static HistogramSynchronizer* histogram_synchronizer_;
173 177
174 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); 178 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer);
175 }; 179 };
176 180
177 #endif // CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_ 181 #endif // CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/metrics/histogram_synchronizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698