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

Side by Side Diff: chrome/browser/ui/webui/profiler_ui.cc

Issue 8520016: Complete the rename from about:tracking2 --> about:profiler by changing the implementation code t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: try synching again... Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/webui/profiler_ui.h ('k') | chrome/browser/ui/webui/tracking_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tracking_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
(...skipping 15 matching lines...) Expand all
31 #include "base/path_service.h" 31 #include "base/path_service.h"
32 #endif // USE_SOURCE_FILES_DIRECTLY 32 #endif // USE_SOURCE_FILES_DIRECTLY
33 33
34 using content::BrowserThread; 34 using content::BrowserThread;
35 using chrome_browser_metrics::TrackingSynchronizer; 35 using chrome_browser_metrics::TrackingSynchronizer;
36 36
37 namespace { 37 namespace {
38 38
39 #ifdef USE_SOURCE_FILES_DIRECTLY 39 #ifdef USE_SOURCE_FILES_DIRECTLY
40 40
41 class TrackingWebUIDataSource : public ChromeURLDataManager::DataSource { 41 class ProfilerWebUIDataSource : public ChromeURLDataManager::DataSource {
42 public: 42 public:
43 TrackingWebUIDataSource() 43 ProfilerWebUIDataSource()
44 : DataSource(chrome::kChromeUITrackingHost2, MessageLoop::current()) { 44 : DataSource(chrome::kChromeUIProfilerHost, MessageLoop::current()) {
45 } 45 }
46 46
47 protected: 47 protected:
48 // ChromeURLDataManager 48 // ChromeURLDataManager
49 virtual std::string GetMimeType(const std::string& path) const OVERRIDE { 49 virtual std::string GetMimeType(const std::string& path) const OVERRIDE {
50 if (EndsWith(path, ".js", false)) 50 if (EndsWith(path, ".js", false))
51 return "application/javascript"; 51 return "application/javascript";
52 return "text/html"; 52 return "text/html";
53 } 53 }
54 54
55 virtual void StartDataRequest(const std::string& path, 55 virtual void StartDataRequest(const std::string& path,
56 bool is_incognito, 56 bool is_incognito,
57 int request_id) OVERRIDE { 57 int request_id) OVERRIDE {
58 FilePath base_path; 58 FilePath base_path;
59 PathService::Get(base::DIR_SOURCE_ROOT, &base_path); 59 PathService::Get(base::DIR_SOURCE_ROOT, &base_path);
60 base_path = base_path.AppendASCII("chrome"); 60 base_path = base_path.AppendASCII("chrome");
61 base_path = base_path.AppendASCII("browser"); 61 base_path = base_path.AppendASCII("browser");
62 base_path = base_path.AppendASCII("resources"); 62 base_path = base_path.AppendASCII("resources");
63 63
64 // If no resource was specified, default to tracking.html. 64 // If no resource was specified, default to profiler.html.
65 std::string filename = path.empty() ? "tracking.html" : path; 65 std::string filename = path.empty() ? "profiler.html" : path;
66 66
67 FilePath file_path; 67 FilePath file_path;
68 file_path = base_path.AppendASCII(filename); 68 file_path = base_path.AppendASCII(filename);
69 69
70 // Read the file synchronously and send it as the response. 70 // Read the file synchronously and send it as the response.
71 base::ThreadRestrictions::ScopedAllowIO allow; 71 base::ThreadRestrictions::ScopedAllowIO allow;
72 std::string file_contents; 72 std::string file_contents;
73 if (!file_util::ReadFileToString(file_path, &file_contents)) 73 if (!file_util::ReadFileToString(file_path, &file_contents))
74 LOG(ERROR) << "Couldn't read file: " << file_path.value(); 74 LOG(ERROR) << "Couldn't read file: " << file_path.value();
75 scoped_refptr<base::RefCountedString> response = 75 scoped_refptr<base::RefCountedString> response =
76 new base::RefCountedString(); 76 new base::RefCountedString();
77 response->data() = file_contents; 77 response->data() = file_contents;
78 SendResponse(request_id, response); 78 SendResponse(request_id, response);
79 } 79 }
80 80
81 private: 81 private:
82 DISALLOW_COPY_AND_ASSIGN(TrackingWebUIDataSource); 82 DISALLOW_COPY_AND_ASSIGN(ProfilerWebUIDataSource);
83 }; 83 };
84 84
85 ChromeURLDataManager::DataSource* CreateTrackingHTMLSource() { 85 ChromeURLDataManager::DataSource* CreateProfilerHTMLSource() {
86 return new TrackingWebUIDataSource(); 86 return new ProfilerWebUIDataSource();
87 } 87 }
88 88
89 #else // USE_SOURCE_FILES_DIRECTLY 89 #else // USE_SOURCE_FILES_DIRECTLY
90 90
91 ChromeWebUIDataSource* CreateTrackingHTMLSource() { 91 ChromeWebUIDataSource* CreateProfilerHTMLSource() {
92 // TODO(eroman): Use kChromeUITrackingHost instead of kChromeUITrackingHost2
93 // once migration to webui is complete.
94 ChromeWebUIDataSource* source = 92 ChromeWebUIDataSource* source =
95 new ChromeWebUIDataSource(chrome::kChromeUITrackingHost2); 93 new ChromeWebUIDataSource(chrome::kChromeUIProfilerHost);
96 94
97 source->set_json_path("strings.js"); 95 source->set_json_path("strings.js");
98 source->add_resource_path("tracking.js", IDR_TRACKING_JS); 96 source->add_resource_path("profiler.js", IDR_PROFILER_JS);
99 source->set_default_resource(IDR_TRACKING_HTML); 97 source->set_default_resource(IDR_PROFILER_HTML);
100 return source; 98 return source;
101 } 99 }
102 100
103 #endif 101 #endif
104 102
105 // This class receives javascript messages from the renderer. 103 // This class receives javascript messages from the renderer.
106 // Note that the WebUI infrastructure runs on the UI thread, therefore all of 104 // Note that the WebUI infrastructure runs on the UI thread, therefore all of
107 // this class's methods are expected to run on the UI thread. 105 // this class's methods are expected to run on the UI thread.
108 class TrackingMessageHandler : public WebUIMessageHandler { 106 class ProfilerMessageHandler : public WebUIMessageHandler {
109 public: 107 public:
110 TrackingMessageHandler() {} 108 ProfilerMessageHandler() {}
111 109
112 // WebUIMessageHandler implementation. 110 // WebUIMessageHandler implementation.
113 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; 111 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE;
114 virtual void RegisterMessages() OVERRIDE; 112 virtual void RegisterMessages() OVERRIDE;
115 113
116 // Messages. 114 // Messages.
117 void OnGetData(const ListValue* list); 115 void OnGetData(const ListValue* list);
118 void OnResetData(const ListValue* list); 116 void OnResetData(const ListValue* list);
119 117
120 private: 118 private:
121 DISALLOW_COPY_AND_ASSIGN(TrackingMessageHandler); 119 DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler);
122 }; 120 };
123 121
124 WebUIMessageHandler* TrackingMessageHandler::Attach(WebUI* web_ui) { 122 WebUIMessageHandler* ProfilerMessageHandler::Attach(WebUI* web_ui) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); 124 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui);
127 return result; 125 return result;
128 } 126 }
129 127
130 void TrackingMessageHandler::RegisterMessages() { 128 void ProfilerMessageHandler::RegisterMessages() {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
132 130
133 web_ui_->RegisterMessageCallback("getData", 131 web_ui_->RegisterMessageCallback("getData",
134 base::Bind(&TrackingMessageHandler::OnGetData,base::Unretained(this))); 132 base::Bind(&ProfilerMessageHandler::OnGetData,base::Unretained(this)));
135 web_ui_->RegisterMessageCallback("resetData", 133 web_ui_->RegisterMessageCallback("resetData",
136 base::Bind(&TrackingMessageHandler::OnResetData, 134 base::Bind(&ProfilerMessageHandler::OnResetData,
137 base::Unretained(this))); 135 base::Unretained(this)));
138 } 136 }
139 137
140 void TrackingMessageHandler::OnGetData(const ListValue* list) { 138 void ProfilerMessageHandler::OnGetData(const ListValue* list) {
141 TrackingUI* tracking_ui = reinterpret_cast<TrackingUI*>(web_ui_); 139 ProfilerUI* profiler_ui = reinterpret_cast<ProfilerUI*>(web_ui_);
142 tracking_ui->GetData(); 140 profiler_ui->GetData();
143 } 141 }
144 142
145 void TrackingMessageHandler::OnResetData(const ListValue* list) { 143 void ProfilerMessageHandler::OnResetData(const ListValue* list) {
146 tracked_objects::ThreadData::ResetAllThreadData(); 144 tracked_objects::ThreadData::ResetAllThreadData();
147 } 145 }
148 146
149 } // namespace 147 } // namespace
150 148
151 TrackingUI::TrackingUI(TabContents* contents) : ChromeWebUI(contents) { 149 ProfilerUI::ProfilerUI(TabContents* contents) : ChromeWebUI(contents) {
152 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<TrackingUI>(this)); 150 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this));
153 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); 151 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr();
154 152
155 AddMessageHandler((new TrackingMessageHandler())->Attach(this)); 153 AddMessageHandler((new ProfilerMessageHandler())->Attach(this));
156 154
157 // Set up the chrome://tracking2/ source. 155 // Set up the chrome://profiler/ source.
158 Profile::FromBrowserContext(contents->browser_context())-> 156 Profile::FromBrowserContext(contents->browser_context())->
159 GetChromeURLDataManager()->AddDataSource(CreateTrackingHTMLSource()); 157 GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource());
160 } 158 }
161 159
162 TrackingUI::~TrackingUI() { 160 ProfilerUI::~ProfilerUI() {
163 } 161 }
164 162
165 void TrackingUI::GetData() { 163 void ProfilerUI::GetData() {
166 TrackingSynchronizer::FetchTrackingDataAsynchronously(ui_weak_ptr_); 164 TrackingSynchronizer::FetchTrackingDataAsynchronously(ui_weak_ptr_);
167 } 165 }
168 166
169 void TrackingUI::ReceivedData(base::Value* value) { 167 void ProfilerUI::ReceivedData(base::Value* value) {
170 // Send the data to the renderer. 168 // Send the data to the renderer.
171 scoped_ptr<Value> data_values(value); 169 scoped_ptr<Value> data_values(value);
172 CallJavascriptFunction("g_browserBridge.receivedData", *data_values.get()); 170 CallJavascriptFunction("g_browserBridge.receivedData", *data_values.get());
173 } 171 }
174 172
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/profiler_ui.h ('k') | chrome/browser/ui/webui/tracking_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698