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

Side by Side Diff: content/browser/histogram_synchronizer.h

Issue 2412903002: Remove MessageLoop::current() from chrome_metrics_service_client.cc (Closed)
Patch Set: Created 4 years, 2 months 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 (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/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.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/task_runner.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "content/browser/histogram_subscriber.h" 17 #include "content/browser/histogram_subscriber.h"
17 18
18 namespace base {
19 class MessageLoop;
20 }
21
22 namespace content { 19 namespace content {
23 20
24 // 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
25 // various child processes, into the browser process. Such transactions are 22 // various child processes, into the browser process. Such transactions are
26 // usually instigated by the browser. In general, a child process will respond 23 // usually instigated by the browser. In general, a child process will respond
27 // by gathering snapshots of all internal histograms, calculating what has 24 // by gathering snapshots of all internal histograms, calculating what has
28 // changed since its last upload, and transmitting a pickled collection of 25 // changed since its last upload, and transmitting a pickled collection of
29 // deltas. 26 // deltas.
30 // 27 //
31 // 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
(...skipping 29 matching lines...) Expand all
61 // Return pointer to the singleton instance for the current process, or NULL 58 // Return pointer to the singleton instance for the current process, or NULL
62 // if none. 59 // if none.
63 static HistogramSynchronizer* GetInstance(); 60 static HistogramSynchronizer* GetInstance();
64 61
65 // Contact all processes, and get them to upload to the browser any/all 62 // Contact all processes, and get them to upload to the browser any/all
66 // changes to histograms. This method is called from about:histograms. 63 // changes to histograms. This method is called from about:histograms.
67 static void FetchHistograms(); 64 static void FetchHistograms();
68 65
69 // Contact all child processes, and get them to upload to the browser any/all 66 // Contact all child processes, and get them to upload to the browser any/all
70 // changes to histograms. When all changes have been acquired, or when the 67 // changes to histograms. When all changes have been acquired, or when the
71 // wait time expires (whichever is sooner), post the callback to the 68 // wait time expires (whichever is sooner), post the callback to the specified
72 // specified message loop. Note the callback is posted exactly once. 69 // TaskRunner. Note the callback is posted exactly once.
73 static void FetchHistogramsAsynchronously(base::MessageLoop* callback_thread, 70 static void FetchHistogramsAsynchronously(
74 const base::Closure& callback, 71 scoped_refptr<base::TaskRunner> task_runner,
75 base::TimeDelta wait_time); 72 const base::Closure& callback,
73 base::TimeDelta wait_time);
76 74
77 private: 75 private:
78 friend struct base::DefaultSingletonTraits<HistogramSynchronizer>; 76 friend struct base::DefaultSingletonTraits<HistogramSynchronizer>;
79 77
80 class RequestContext; 78 class RequestContext;
81 79
82 HistogramSynchronizer(); 80 HistogramSynchronizer();
83 ~HistogramSynchronizer() override; 81 ~HistogramSynchronizer() override;
84 82
85 // Establish a new sequence number, and use it to notify all processes 83 // Establish a new sequence number, and use it to notify all processes
(...skipping 13 matching lines...) Expand all
99 int pending_processes, 97 int pending_processes,
100 bool end) override; 98 bool end) override;
101 99
102 // Send histogram_data back to caller and also record that we are waiting 100 // Send histogram_data back to caller and also record that we are waiting
103 // for one less histogram data from child process for the given sequence 101 // for one less histogram data from child process for the given sequence
104 // number. This method is accessible on UI thread. 102 // number. This method is accessible on UI thread.
105 void OnHistogramDataCollected( 103 void OnHistogramDataCollected(
106 int sequence_number, 104 int sequence_number,
107 const std::vector<std::string>& pickled_histograms) override; 105 const std::vector<std::string>& pickled_histograms) override;
108 106
109 // Set the callback_thread_ and callback_ members. If these members already 107 // Set the |callback_task_runner_| and |callback_| members. If these members
110 // had values, then as a side effect, post the old callback_ to the old 108 // already had values, then as a side effect, post the old |callback_| to the
111 // callaback_thread_. This side effect should not generally happen, but is in 109 // old |callback_task_runner_|. This side effect should not generally happen,
112 // place to assure correctness (that any tasks that were set, are eventually 110 // but is in place to assure correctness (that any tasks that were set, are
113 // called, and never merely discarded). 111 // eventually called, and never merely discarded).
114 void SetCallbackTaskAndThread(base::MessageLoop* callback_thread, 112 void SetTaskRunnerAndCallback(scoped_refptr<base::TaskRunner> task_runner,
115 const base::Closure& callback); 113 const base::Closure& callback);
116 114
117 void ForceHistogramSynchronizationDoneCallback(int sequence_number); 115 void ForceHistogramSynchronizationDoneCallback(int sequence_number);
118 116
119 // Internal helper function, to post task, and record callback stats. 117 // Internal helper function, to post task, and record callback stats.
120 void InternalPostTask(base::MessageLoop* thread, 118 void InternalPostTask(scoped_refptr<base::TaskRunner> task_runner,
121 const base::Closure& callback); 119 const base::Closure& callback);
122 120
123 // Gets a new sequence number to be sent to processes from browser process. 121 // Gets a new sequence number to be sent to processes from browser process.
124 int GetNextAvailableSequenceNumber(ProcessHistogramRequester requester); 122 int GetNextAvailableSequenceNumber(ProcessHistogramRequester requester);
125 123
126 // This lock_ protects access to all members. 124 // This lock_ protects access to all members.
127 base::Lock lock_; 125 base::Lock lock_;
128 126
129 // When a request is made to asynchronously update the histograms, we store 127 // When a request is made to asynchronously update the histograms, we store
130 // the task and thread we use to post a completion notification in 128 // the task and TaskRunner we use to post a completion notification in
131 // callback_ and callback_thread_. 129 // |callback_| and |callback_task_runner_|.
132 base::Closure callback_; 130 base::Closure callback_;
133 base::MessageLoop* callback_thread_; 131 scoped_refptr<base::TaskRunner> callback_task_runner_;
134 132
135 // We don't track the actual processes that are contacted for an update, only 133 // We don't track the actual processes that are contacted for an update, only
136 // the count of the number of processes, and we can sometimes time-out and 134 // the count of the number of processes, and we can sometimes time-out and
137 // give up on a "slow to respond" process. We use a sequence_number to be 135 // give up on a "slow to respond" process. We use a sequence_number to be
138 // sure a response from a process is associated with the current round of 136 // sure a response from a process is associated with the current round of
139 // requests (and not merely a VERY belated prior response). 137 // requests (and not merely a VERY belated prior response).
140 // All sequence numbers used are non-negative. 138 // All sequence numbers used are non-negative.
141 // last_used_sequence_number_ is the most recently used number (used to avoid 139 // last_used_sequence_number_ is the most recently used number (used to avoid
142 // reuse for a long time). 140 // reuse for a long time).
143 int last_used_sequence_number_; 141 int last_used_sequence_number_;
144 142
145 // The sequence number used by the most recent asynchronous update request to 143 // The sequence number used by the most recent asynchronous update request to
146 // contact all processes. 144 // contact all processes.
147 int async_sequence_number_; 145 int async_sequence_number_;
148 146
149 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer); 147 DISALLOW_COPY_AND_ASSIGN(HistogramSynchronizer);
150 }; 148 };
151 149
152 } // namespace content 150 } // namespace content
153 151
154 #endif // CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_ 152 #endif // CONTENT_BROWSER_HISTOGRAM_SYNCHRONIZER_H_
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.cc ('k') | content/browser/histogram_synchronizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698