• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_
6 #define CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/memory/singleton.h"
12 
13 namespace content {
14 
15 class HistogramSubscriber;
16 
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();
25 
26   // Normally instantiated when the child process is launched. Only one instance
27   // should be created per process.
28   HistogramController();
29   virtual ~HistogramController();
30 
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);
35 
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);
40 
41   // Contact all processes and get their histogram data.
42   void GetHistogramData(int sequence_number);
43 
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);
50 
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);
56 
57  private:
58   friend struct DefaultSingletonTraits<HistogramController>;
59 
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);
64 
65   HistogramSubscriber* subscriber_;
66 
67   DISALLOW_COPY_AND_ASSIGN(HistogramController);
68 };
69 
70 }  // namespace content
71 
72 #endif  // CONTENT_BROWSER_HISTOGRAM_CONTROLLER_H_
73