OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/profiler_ui.h" | 5 #include "chrome/browser/ui/webui/profiler_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 // When testing the javacript code, it is cumbersome to have to keep | 9 // When testing the javacript code, it is cumbersome to have to keep |
10 // re-building the resouces package and reloading the browser. To solve | 10 // re-building the resouces package and reloading the browser. To solve |
11 // this, enable the following flag to read the webapp's source files | 11 // this, enable the following flag to read the webapp's source files |
12 // directly off disk, so all you have to do is refresh the page to | 12 // directly off disk, so all you have to do is refresh the page to |
13 // test the modifications. | 13 // test the modifications. |
14 //#define USE_SOURCE_FILES_DIRECTLY | 14 //#define USE_SOURCE_FILES_DIRECTLY |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
| 19 #include "base/values.h" |
18 #include "chrome/browser/metrics/tracking_synchronizer.h" | 20 #include "chrome/browser/metrics/tracking_synchronizer.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" |
20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
21 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
24 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
25 #include "content/public/browser/web_ui_message_handler.h" | 28 #include "content/public/browser/web_ui_message_handler.h" |
26 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
27 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
28 | 31 |
29 #ifdef USE_SOURCE_FILES_DIRECTLY | 32 #ifdef USE_SOURCE_FILES_DIRECTLY |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 void OnResetData(const ListValue* list); | 123 void OnResetData(const ListValue* list); |
121 | 124 |
122 private: | 125 private: |
123 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); | 126 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); |
124 }; | 127 }; |
125 | 128 |
126 void ProfilerMessageHandler::RegisterMessages() { | 129 void ProfilerMessageHandler::RegisterMessages() { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
128 | 131 |
129 web_ui()->RegisterMessageCallback("getData", | 132 web_ui()->RegisterMessageCallback("getData", |
130 base::Bind(&ProfilerMessageHandler::OnGetData,base::Unretained(this))); | 133 base::Bind(&ProfilerMessageHandler::OnGetData, base::Unretained(this))); |
131 web_ui()->RegisterMessageCallback("resetData", | 134 web_ui()->RegisterMessageCallback("resetData", |
132 base::Bind(&ProfilerMessageHandler::OnResetData, | 135 base::Bind(&ProfilerMessageHandler::OnResetData, |
133 base::Unretained(this))); | 136 base::Unretained(this))); |
134 } | 137 } |
135 | 138 |
136 void ProfilerMessageHandler::OnGetData(const ListValue* list) { | 139 void ProfilerMessageHandler::OnGetData(const ListValue* list) { |
137 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); | 140 ProfilerUI* profiler_ui = static_cast<ProfilerUI*>(web_ui()->GetController()); |
138 profiler_ui->GetData(); | 141 profiler_ui->GetData(); |
139 } | 142 } |
140 | 143 |
141 void ProfilerMessageHandler::OnResetData(const ListValue* list) { | 144 void ProfilerMessageHandler::OnResetData(const ListValue* list) { |
142 tracked_objects::ThreadData::ResetAllThreadData(); | 145 tracked_objects::ThreadData::ResetAllThreadData(); |
143 } | 146 } |
144 | 147 |
145 } // namespace | 148 } // namespace |
146 | 149 |
147 ProfilerUI::ProfilerUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 150 ProfilerUI::ProfilerUI(content::WebUI* web_ui) |
148 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this)); | 151 : WebUIController(web_ui), |
149 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); | 152 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
150 | |
151 web_ui->AddMessageHandler(new ProfilerMessageHandler()); | 153 web_ui->AddMessageHandler(new ProfilerMessageHandler()); |
152 | 154 |
153 // Set up the chrome://profiler/ source. | 155 // Set up the chrome://profiler/ source. |
154 Profile::FromWebUI(web_ui)-> | 156 Profile::FromWebUI(web_ui)-> |
155 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); | 157 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); |
156 } | 158 } |
157 | 159 |
158 ProfilerUI::~ProfilerUI() { | 160 ProfilerUI::~ProfilerUI() { |
159 } | 161 } |
160 | 162 |
161 void ProfilerUI::GetData() { | 163 void ProfilerUI::GetData() { |
162 TrackingSynchronizer::FetchProfilerDataAsynchronously(ui_weak_ptr_); | 164 TrackingSynchronizer::FetchProfilerDataAsynchronously( |
| 165 weak_ptr_factory_.GetWeakPtr()); |
163 } | 166 } |
164 | 167 |
165 void ProfilerUI::ReceivedData(base::Value* value) { | 168 void ProfilerUI::ReceivedProfilerData( |
| 169 const tracked_objects::ProcessDataSnapshot& profiler_data, |
| 170 content::ProcessType process_type) { |
| 171 // Serialize the data to JSON. |
| 172 DictionaryValue json_data; |
| 173 task_profiler::TaskProfilerDataSerializer::ToValue(profiler_data, |
| 174 process_type, |
| 175 &json_data); |
| 176 |
166 // Send the data to the renderer. | 177 // Send the data to the renderer. |
167 scoped_ptr<Value> data_values(value); | 178 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", json_data); |
168 web_ui()->CallJavascriptFunction( | |
169 "g_browserBridge.receivedData", *data_values.get()); | |
170 } | 179 } |
171 | |
OLD | NEW |