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

Side by Side Diff: trunk/src/chrome/browser/feedback/tracing_manager.h

Issue 89753004: Revert 237280 "Remove TraceController" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_FEEDBACK_TRACING_MANAGER_H_ 5 #ifndef CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
6 #define CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_ 6 #define CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "content/public/browser/trace_subscriber.h"
15 16
16 namespace base {
17
18 class RefCountedString;
19 class FilePath;
20
21 }
22 // Callback used for getting the output of a trace. 17 // Callback used for getting the output of a trace.
23 typedef base::Callback<void(scoped_refptr<base::RefCountedString> trace_data)> 18 typedef base::Callback<void(scoped_refptr<base::RefCountedString> trace_data)>
24 TraceDataCallback; 19 TraceDataCallback;
25 20
26 // This class is used to manage performance metrics that can be attached to 21 // This class is used to manage performance meterics that can be attached to
27 // feedback reports. This class is a Singleton that is owned by the preference 22 // feedback reports. This class is a Singleton that is owned by the preference
28 // system. It should only be created when it is enabled, and should only be 23 // system. It should only be created when it is enabled, and should only be
29 // accessed elsewhere via Get(). 24 // accessed elsewhere via Get().
30 // 25 //
31 // When a performance trace is desired, TracingManager::Get()->RequestTrace() 26 // When a performance trace is desired, TracingManager::Get()->RequestTrace()
32 // should be invoked. The TracingManager will then start preparing a zipped 27 // should be invoked. The TracingManager will then start preparing a zipped
33 // version of the performance data. That data can then be requested via 28 // version of the performance data. That data can then be requested via
34 // GetTraceData(). When the data is no longer needed, it should be discarded 29 // GetTraceData(). When the data is no longer needed, it should be discarded
35 // via DiscardTraceData(). 30 // via DiscardTraceData().
36 class TracingManager { 31 class TracingManager : public content::TraceSubscriber {
37 public: 32 public:
38 virtual ~TracingManager(); 33 virtual ~TracingManager();
39 34
40 // Create a TracingManager. Can only be called when none exists. 35 // Create a TracingManager. Can only be called when none exists.
41 static scoped_ptr<TracingManager> Create(); 36 static scoped_ptr<TracingManager> Create();
42 37
43 // Get the current TracingManager. Returns NULL if one doesn't exist. 38 // Get the current TracingManager. Returns NULL if one doesn't exist.
44 static TracingManager* Get(); 39 static TracingManager* Get();
45 40
46 // Request a trace ending at the current time. If a trace is already being 41 // Request a trace ending at the current time. If a trace is already being
47 // collected, the id for that trace is returned. 42 // collected, the id for that trace is returned.
48 int RequestTrace(); 43 int RequestTrace();
49 44
50 // Get the trace data for |id|. On success, true is returned, and the data is 45 // Get the trace data for |id|. On success, true is returned, and the data is
51 // returned via |callback|. Returns false on failure. 46 // returned via |callback|. Returns false on failure.
52 bool GetTraceData(int id, const TraceDataCallback& callback); 47 bool GetTraceData(int id, const TraceDataCallback& callback);
53 48
54 // Discard the data for trace |id|. 49 // Discard the data for trace |id|.
55 void DiscardTraceData(int id); 50 void DiscardTraceData(int id);
56 51
57 private: 52 private:
53 void StartTracing();
54
55 // content::TraceSubscriber overrides
56 virtual void OnEndTracingComplete() OVERRIDE;
57 virtual void OnTraceDataCollected(
58 const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE;
59
58 TracingManager(); 60 TracingManager();
59 61
60 void StartTracing(); 62 // Data being collected from the current trace.
61 void OnTraceDataCollected(const base::FilePath& path); 63 std::string data_;
62 64
63 // ID of the trace that is being collected. 65 // ID of the trace that is being collected.
64 int current_trace_id_; 66 int current_trace_id_;
65 67
66 // Mapping of trace ID to trace data. 68 // Mapping of trace ID to trace data.
67 std::map<int, scoped_refptr<base::RefCountedString> > trace_data_; 69 std::map<int, scoped_refptr<base::RefCountedString> > trace_data_;
68 70
69 // Callback for the current trace request. 71 // Callback for the current trace request.
70 TraceDataCallback trace_callback_; 72 TraceDataCallback trace_callback_;
71 73
72 base::WeakPtrFactory<TracingManager> weak_ptr_factory_; 74 base::WeakPtrFactory<TracingManager> weak_ptr_factory_;
73 75
74 DISALLOW_COPY_AND_ASSIGN(TracingManager); 76 DISALLOW_COPY_AND_ASSIGN(TracingManager);
75 }; 77 };
76 78
77 #endif // CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_ 79 #endif // CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_
78 80
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/feedback/feedback_util.cc ('k') | trunk/src/chrome/browser/feedback/tracing_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698