OLD | NEW |
---|---|
(Empty) | |
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 #include "tracing_shell.h" | |
Ted C
2012/12/26 16:18:28
should be the full path
| |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/bind.h" | |
10 #include "base/bind_helpers.h" | |
11 #include "base/lazy_instance.h" | |
12 #include "base/logging.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 #include "content/public/browser/trace_controller.h" | |
15 #include "jni/TraceController_jni.h" | |
16 | |
17 namespace content { | |
18 | |
19 base::LazyInstance<TracingIntentHandler> g_traceIntentHandler = | |
Ted C
2012/12/26 16:18:28
no camel caps in the name, so this should be g_tra
| |
20 LAZY_INSTANCE_INITIALIZER; | |
21 | |
22 void WriteTraceFileCallback(const FilePath& path, std::string* contents) { | |
23 if (file_util::WriteFile(path, contents->c_str(), contents->size()) <= 0) | |
24 LOG(INFO) << "fail to write trace file"; | |
25 } | |
26 | |
27 TracingIntentHandler::TracingIntentHandler() | |
28 : in_tracing_(false) { | |
Ted C
2012/12/26 16:18:28
indent to 4
| |
29 } | |
30 | |
31 void TracingIntentHandler::OnEndTracingComplete() { | |
32 trace_data_to_save_.Finish(); | |
33 BrowserThread::PostTask( | |
34 BrowserThread::FILE, FROM_HERE, | |
35 base::Bind(&WriteTraceFileCallback, | |
36 path_to_save_, | |
Ted C
2012/12/26 16:18:28
align with the (
| |
37 &trace_data_to_save_.data_)); | |
38 SetInTracing(false); | |
39 } | |
40 | |
41 void TracingIntentHandler::OnTraceDataCollected( | |
42 const scoped_refptr<base::RefCountedString>& trace_fragment) { | |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
44 | |
45 trace_data_to_save_.AddFragment(trace_fragment->data()); | |
46 } | |
47 | |
48 void TracingIntentHandler::OnBeginTracing(std::string path) { | |
49 SetInTracing(true); | |
50 path_to_save_ = FilePath(path); | |
51 trace_data_to_save_.Start(); | |
52 TraceController::GetInstance()->BeginTracing(this, std::string("-test*")); | |
53 } | |
54 | |
55 void TracingIntentHandler::OnEndTracing() { | |
56 if (in_tracing() && !TraceController::GetInstance()->EndTracingAsync(this)) | |
57 OnEndTracingComplete(); | |
58 } | |
59 | |
60 void TracingIntentHandler::JsonString::Start() { | |
61 first_ = true; | |
62 data_ = "["; | |
63 } | |
64 | |
65 void TracingIntentHandler::JsonString::Finish() { | |
66 data_ += "]"; | |
67 } | |
68 | |
69 void TracingIntentHandler::JsonString::AddFragment( | |
70 const std::string& fragment) { | |
71 if (first_) | |
72 first_ = false; | |
73 else | |
74 data_ += ","; | |
75 data_ += fragment; | |
76 } | |
77 | |
78 static void BeginTracing(JNIEnv* env, jclass clazz, jstring jspath) { | |
79 std::string path(base::android::ConvertJavaStringToUTF8(env, jspath)); | |
80 g_traceIntentHandler.Get().OnBeginTracing(path); | |
81 } | |
82 | |
83 static void EndTracing(JNIEnv* env, jclass clazz) { | |
84 g_traceIntentHandler.Get().OnEndTracing(); | |
85 } | |
86 | |
87 bool RegisterTracingHandler(JNIEnv* env) { | |
88 return RegisterNativesImpl(env); | |
89 } | |
90 | |
91 } // namespace content | |
OLD | NEW |