OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/memory/scoped_ptr.h" |
18 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/metrics/tracking_synchronizer.h" | 20 #include "chrome/browser/metrics/tracking_synchronizer.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" | 22 #include "chrome/browser/task_profiler/task_profiler_data_serializer.h" |
23 #include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h" | |
23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
28 #include "content/public/browser/web_ui_message_handler.h" | 29 #include "content/public/browser/web_ui_message_handler.h" |
29 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
31 | 32 |
32 #ifdef USE_SOURCE_FILES_DIRECTLY | 33 #ifdef USE_SOURCE_FILES_DIRECTLY |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 147 } |
147 | 148 |
148 } // namespace | 149 } // namespace |
149 | 150 |
150 ProfilerUI::ProfilerUI(content::WebUI* web_ui) | 151 ProfilerUI::ProfilerUI(content::WebUI* web_ui) |
151 : WebUIController(web_ui), | 152 : WebUIController(web_ui), |
152 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
153 web_ui->AddMessageHandler(new ProfilerMessageHandler()); | 154 web_ui->AddMessageHandler(new ProfilerMessageHandler()); |
154 | 155 |
155 // Set up the chrome://profiler/ source. | 156 // Set up the chrome://profiler/ source. |
156 Profile::FromWebUI(web_ui)-> | 157 Profile* profile = Profile::FromWebUI(web_ui); |
157 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); | 158 ChromeURLDataManagerFactory::GetForProfile(profile) |
Evan Stade
2012/04/24 19:02:43
-> goes at end of line
Kyle Horimoto
2012/04/24 21:09:59
Done.
| |
159 ->AddDataSource(CreateProfilerHTMLSource()); | |
158 } | 160 } |
159 | 161 |
160 ProfilerUI::~ProfilerUI() { | 162 ProfilerUI::~ProfilerUI() { |
161 } | 163 } |
162 | 164 |
163 void ProfilerUI::GetData() { | 165 void ProfilerUI::GetData() { |
164 TrackingSynchronizer::FetchProfilerDataAsynchronously( | 166 TrackingSynchronizer::FetchProfilerDataAsynchronously( |
165 weak_ptr_factory_.GetWeakPtr()); | 167 weak_ptr_factory_.GetWeakPtr()); |
166 } | 168 } |
167 | 169 |
168 void ProfilerUI::ReceivedProfilerData( | 170 void ProfilerUI::ReceivedProfilerData( |
169 const tracked_objects::ProcessDataSnapshot& profiler_data, | 171 const tracked_objects::ProcessDataSnapshot& profiler_data, |
170 content::ProcessType process_type) { | 172 content::ProcessType process_type) { |
171 // Serialize the data to JSON. | 173 // Serialize the data to JSON. |
172 DictionaryValue json_data; | 174 DictionaryValue json_data; |
173 task_profiler::TaskProfilerDataSerializer::ToValue(profiler_data, | 175 task_profiler::TaskProfilerDataSerializer::ToValue(profiler_data, |
174 process_type, | 176 process_type, |
175 &json_data); | 177 &json_data); |
176 | 178 |
177 // Send the data to the renderer. | 179 // Send the data to the renderer. |
178 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", json_data); | 180 web_ui()->CallJavascriptFunction("g_browserBridge.receivedData", json_data); |
179 } | 181 } |
OLD | NEW |