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

Side by Side Diff: components/feedback/tracing_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698