Roll src/third_party/WebKit e353f22:4d062fa (svn 200353:200356)
[chromium-blink-merge.git] / content / browser / histogram_controller.h
blob0fc46221d4adf6a9a68e58d639509d5f6abd8904
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_
6 #define CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/singleton.h"
13 namespace content {
15 class HistogramSubscriber;
17 // HistogramController is used on the browser process to collect histogram data.
18 // Only the browser UI thread is allowed to interact with the
19 // HistogramController object.
20 class HistogramController {
21 public:
22 // Returns the HistogramController object for the current process, or NULL if
23 // none.
24 static HistogramController* GetInstance();
26 // Normally instantiated when the child process is launched. Only one instance
27 // should be created per process.
28 HistogramController();
29 virtual ~HistogramController();
31 // Register the subscriber so that it will be called when for example
32 // OnHistogramDataCollected is returning histogram data from a child process.
33 // This is called on UI thread.
34 void Register(HistogramSubscriber* subscriber);
36 // Unregister the subscriber so that it will not be called when for example
37 // OnHistogramDataCollected is returning histogram data from a child process.
38 // Safe to call even if caller is not the current subscriber.
39 void Unregister(const HistogramSubscriber* subscriber);
41 // Contact all processes and get their histogram data.
42 void GetHistogramData(int sequence_number);
44 // Notify the |subscriber_| that it should expect at least |pending_processes|
45 // additional calls to OnHistogramDataCollected(). OnPendingProcess() may be
46 // called repeatedly; the last call will have |end| set to true, indicating
47 // that there is no longer a possibility for the count of pending processes to
48 // increase. This is called on the UI thread.
49 void OnPendingProcesses(int sequence_number, int pending_processes, bool end);
51 // Send the |histogram| back to the |subscriber_|.
52 // This can be called from any thread.
53 void OnHistogramDataCollected(
54 int sequence_number,
55 const std::vector<std::string>& pickled_histograms);
57 private:
58 friend struct DefaultSingletonTraits<HistogramController>;
60 // Contact PLUGIN and GPU child processes and get their histogram data.
61 // TODO(rtenneti): Enable getting histogram data for other processes like
62 // PPAPI and NACL.
63 void GetHistogramDataFromChildProcesses(int sequence_number);
65 HistogramSubscriber* subscriber_;
67 DISALLOW_COPY_AND_ASSIGN(HistogramController);
70 } // namespace content
72 #endif // CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_