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

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, const base::Closure& callback,
82 int wait_time);
Ilya Sherman 2011/11/21 21:09:46 nit: As long as you're updating this declaration,
dcheng 2011/11/21 22:06:01 Done.
82 83
83 // This method is called on the IO thread. Deserializes the histograms and 84 // This method is called on the IO thread. Deserializes the histograms and
84 // records that we have received histograms from a renderer process. 85 // records that we have received histograms from a renderer process.
85 static void DeserializeHistogramList( 86 static void DeserializeHistogramList(
86 int sequence_number, const std::vector<std::string>& histograms); 87 int sequence_number, const std::vector<std::string>& histograms);
87 88
88 private: 89 private:
89 friend class base::RefCountedThreadSafe<HistogramSynchronizer>; 90 friend class base::RefCountedThreadSafe<HistogramSynchronizer>;
90 91
91 ~HistogramSynchronizer(); 92 ~HistogramSynchronizer();
92 93
93 // Establish a new sequence_number_, and use it to notify all the renderers of 94 // 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. 95 // the need to supply, to the browser, any changes in their histograms.
95 // The argument indicates whether this will set async_sequence_number_ or 96 // The argument indicates whether this will set async_sequence_number_ or
96 // synchronous_sequence_number_. 97 // synchronous_sequence_number_.
97 // Return the sequence number that was used. 98 // Return the sequence number that was used.
98 int NotifyAllRenderers(RendererHistogramRequester requester); 99 int NotifyAllRenderers(RendererHistogramRequester requester);
99 100
100 // Records that we are waiting for one less histogram from a renderer for the 101 // 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, 102 // given sequence number. If we have received a response from all renderers,
102 // either signal the waiting process or call the callback function. 103 // either signal the waiting process or call the callback function.
103 void DecrementPendingRenderers(int sequence_number); 104 void DecrementPendingRenderers(int sequence_number);
104 105
105 // Set the callback_thread_ and callback_task_ members. If these members 106 // 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 107 // 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, 108 // 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 109 // place to assure correctness (that any tasks that were set, are eventually
109 // eventually called, and never merely discarded). 110 // called, and never merely discarded).
110 void SetCallbackTaskAndThread(MessageLoop* callback_thread, 111 void SetCallbackTaskAndThread(MessageLoop* callback_thread,
111 Task* callback_task); 112 const base::Closure& callback);
112 113
113 void ForceHistogramSynchronizationDoneCallback(int sequence_number); 114 void ForceHistogramSynchronizationDoneCallback(int sequence_number);
114 115
115 // Gets a new sequence number to be sent to renderers from browser process and 116 // 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. 117 // set the number of pending responses for the given type to renderer_count.
117 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster, 118 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster,
118 int renderer_count); 119 int renderer_count);
119 120
120 // Internal helper function, to post task, and record callback stats. 121 // Internal helper function, to post task, and record callback stats.
121 void InternalPostTask(MessageLoop* thread, Task* task, 122 void InternalPostTask(MessageLoop* thread, const base::Closure& callback,
122 int unresponsive_renderers, const base::TimeTicks& started); 123 int unresponsive_renderers, const base::TimeTicks& started);
Ilya Sherman 2011/11/21 21:09:46 nit: Here too.
dcheng 2011/11/21 22:06:01 Done.
123 124
124 // This lock_ protects access to all members. 125 // This lock_ protects access to all members.
125 base::Lock lock_; 126 base::Lock lock_;
126 127
127 // This condition variable is used to block caller of the synchronous request 128 // 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. 129 // to update histograms, and to signal that thread when updates are completed.
129 base::ConditionVariable received_all_renderer_histograms_; 130 base::ConditionVariable received_all_renderer_histograms_;
130 131
131 // When a request is made to asynchronously update the histograms, we store 132 // 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 133 // the task and thread we use to post a completion notification in
133 // callback_task_ and callback_thread_. 134 // callback_ and callback_thread_.
134 Task* callback_task_; 135 base::Closure callback_;
135 MessageLoop* callback_thread_; 136 MessageLoop* callback_thread_;
136 137
137 // We don't track the actual renderers that are contacted for an update, only 138 // 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 139 // 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 140 // 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 141 // sure a response from a renderer is associated with the current round of
141 // requests (and not merely a VERY belated prior response). 142 // requests (and not merely a VERY belated prior response).
142 // All sequence numbers used are non-negative. 143 // All sequence numbers used are non-negative.
143 // last_used_sequence_number_ is the most recently used number (used to avoid 144 // last_used_sequence_number_ is the most recently used number (used to avoid
144 // reuse for a long time). 145 // reuse for a long time).
(...skipping 23 matching lines...) Expand all
168 // portion of main(). It initializes globals to provide support for all future 169 // 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 170 // 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 171 // 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. 172 // from the UI thread (for UMA uploads), or for about:histograms.
172 static HistogramSynchronizer* histogram_synchronizer_; 173 static HistogramSynchronizer* histogram_synchronizer_;
173 174
174 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); 175 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer);
175 }; 176 };
176 177
177 #endif // CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_ 178 #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