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

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

Issue 4193008: Cleanup histogram syncronizer a bit... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // records that we have received histograms from a renderer process. 53 // records that we have received histograms from a renderer process.
54 static void DeserializeHistogramList( 54 static void DeserializeHistogramList(
55 int sequence_number, const std::vector<std::string>& histograms); 55 int sequence_number, const std::vector<std::string>& histograms);
56 56
57 private: 57 private:
58 // Records that we have received the histograms from a renderer for the given 58 // Records that we have received the histograms from a renderer for the given
59 // sequence number. If we have received a response from all histograms, either 59 // sequence number. If we have received a response from all histograms, either
60 // signal the waiting process or call the callback function. Returns true when 60 // signal the waiting process or call the callback function. Returns true when
61 // we receive histograms from the last of N renderers that were contacted for 61 // we receive histograms from the last of N renderers that were contacted for
62 // an update. This is called on IO Thread. 62 // an update. This is called on IO Thread.
63 bool RecordRendererHistogram(int sequence_number); 63 bool DecrementPendingRenderers(int sequence_number);
64 64
65 void SetCallbackTaskToCallAfterGettingHistograms( 65 void SetCallbackTaskToCallAfterGettingHistograms(
66 MessageLoop* callback_thread, Task* callback_task); 66 MessageLoop* callback_thread, Task* callback_task);
67 67
68 void ForceHistogramSynchronizationDoneCallback(int sequence_number); 68 void ForceHistogramSynchronizationDoneCallback(int sequence_number);
69 69
70 // Calls the callback task, if there is a callback_task. 70 // Calls the callback task, if there is a callback_task.
71 void CallCallbackTaskAndResetData(); 71 void CallCallbackTaskAndResetData();
72 72
73 // Gets a new sequence number to be sent to renderers from browser process. 73 // Gets a new sequence number to be sent to renderers from browser process.
74 // This will also reset the current pending renderers for the given type. 74 // This will also reset the current pending renderers for the given type.
75 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster); 75 int GetNextAvailableSequenceNumber(RendererHistogramRequester requster);
76 76
77 // Increments the count of the renderers we're waiting for for the request 77 // Increments the count of the renderers we're waiting for for the request
78 // of the given type. 78 // of the given type.
79 void IncrementPendingRenderers(RendererHistogramRequester requester); 79 void IncrementPendingRenderers(RendererHistogramRequester requester);
80 80
81 // For use ONLY in a DCHECK. This method initializes io_message_loop_ in its 81 // For use ONLY in a DCHECK. This method initializes io_message_loop_ in its
82 // first call and then compares io_message_loop_ with MessageLoop::current() 82 // first call and then compares io_message_loop_ with MessageLoop::current()
83 // in subsequent calls. This method guarantees we're consistently on the 83 // in subsequent calls. This method guarantees we're consistently on the
84 // singular IO thread and we don't need to worry about locks. 84 // singular IO thread and we don't need to worry about locks.
85 bool IsOnIoThread(); 85 bool IsOnIoThread();
86 86
87 // This lock_ protects access to sequence number and 87 // This lock_ protects access to next_sequence_number_,
88 // synchronous_renderers_pending_. 88 // synchronous_renderers_pending_, and synchronous_sequence_number_.
89 Lock lock_; 89 Lock lock_;
90 90
91 // This condition variable is used to block caller of the synchronous request 91 // This condition variable is used to block caller of the synchronous request
92 // to update histograms, and to signal that thread when updates are completed. 92 // to update histograms, and to signal that thread when updates are completed.
93 ConditionVariable received_all_renderer_histograms_; 93 ConditionVariable received_all_renderer_histograms_;
94 94
95 // When a request is made to asynchronously update the histograms, we store 95 // When a request is made to asynchronously update the histograms, we store
96 // the task and thread we use to post a completion notification in 96 // the task and thread we use to post a completion notification in
97 // callback_task_ and callback_thread_. 97 // callback_task_ and callback_thread_.
98 Task* callback_task_; 98 Task* callback_task_;
99 MessageLoop* callback_thread_; 99 MessageLoop* callback_thread_;
100 100
101 // For use ONLY in a DCHECK and is used in IsOnIoThread(). io_message_loop_ is 101 // For use ONLY in a DCHECK and is used in IsOnIoThread(). io_message_loop_ is
102 // initialized during the first call to IsOnIoThread(), and then compares 102 // initialized during the first call to IsOnIoThread(), and then compares
103 // MessageLoop::current() against io_message_loop_ in subsequent calls for 103 // MessageLoop::current() against io_message_loop_ in subsequent calls for
104 // consistency. 104 // consistency.
105 MessageLoop* io_message_loop_; 105 MessageLoop* io_message_loop_;
106 106
107 // We don't track the actual renderers that are contacted for an update, only 107 // We don't track the actual renderers that are contacted for an update, only
108 // the count of the number of renderers, and we can sometimes time-out and 108 // the count of the number of renderers, and we can sometimes time-out and
109 // give up on a "slow to respond" renderer. We use a sequence_number to be 109 // give up on a "slow to respond" renderer. We use a sequence_number to be
110 // sure a response from a renderer is associated with the current round of 110 // sure a response from a renderer is associated with the current round of
111 // requests (and not merely a VERY belated prior response). 111 // requests (and not merely a VERY belated prior response).
112 // next_available_sequence_number_ is the next available number (used to 112 // next_available_sequence_number_ is the next available number (used to
113 // avoid reuse for a long time). 113 // avoid reuse for a long time). Access is protected by lock_.
114 int next_available_sequence_number_; 114 int next_available_sequence_number_;
115 115
116 // The sequence number used by the most recent asynchronous update request to 116 // The sequence number used by the most recent asynchronous update request to
117 // contact all renderers. 117 // contact all renderers. Access is only permitted on the IO thread.
118 int async_sequence_number_; 118 int async_sequence_number_;
119 119
120 // The number of renderers that have not yet responded to requests (as part of 120 // The number of renderers that have not yet responded to requests (as part of
121 // an asynchronous update). 121 // an asynchronous update). Access is only permitted on the IO thread.
122 int async_renderers_pending_; 122 int async_renderers_pending_;
123 123
124 // The time when we were told to start the fetch histograms asynchronously 124 // The time when we were told to start the fetch histograms asynchronously
125 // from renderers. 125 // from renderers. Access is only permitted on the IO thread.
126 base::TimeTicks async_callback_start_time_; 126 base::TimeTicks async_callback_start_time_;
127 127
128 // The sequence number used by the most recent synchronous update request to 128 // The sequence number used by the most recent synchronous update request to
129 // contact all renderers. 129 // contact all renderers. Protected by lock_.
130 int synchronous_sequence_number_; 130 int synchronous_sequence_number_;
131 131
132 // The number of renderers that have not yet responded to requests (as part of 132 // The number of renderers that have not yet responded to requests (as part of
133 // a synchronous update). 133 // a synchronous update). Protected by lock_.
134 int synchronous_renderers_pending_; 134 int synchronous_renderers_pending_;
135 135
136 // This singleton instance should be started during the single threaded 136 // This singleton instance should be started during the single threaded
137 // portion of main(). It initializes globals to provide support for all future 137 // portion of main(). It initializes globals to provide support for all future
138 // calls. This object is created on the UI thread, and it is destroyed after 138 // calls. This object is created on the UI thread, and it is destroyed after
139 // all the other threads have gone away. As a result, it is ok to call it 139 // all the other threads have gone away. As a result, it is ok to call it
140 // from the UI thread (for UMA uploads), or for about:histograms. 140 // from the UI thread (for UMA uploads), or for about:histograms.
141 static HistogramSynchronizer* histogram_synchronizer_; 141 static HistogramSynchronizer* histogram_synchronizer_;
142 142
143 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); 143 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer);
144 }; 144 };
145 145
146 #endif // CHROME_BROWSER_METRICS_HISTOGRAM_SYNCHRONIZER_H_ 146 #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