| 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/tracking_ui.h" | 5 #include "chrome/browser/ui/webui/tracking_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
| 11 #include "chrome/browser/metrics/tracking_synchronizer.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 13 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "content/browser/trace_controller.h" | 16 #include "content/browser/trace_controller.h" |
| 16 #include "grit/browser_resources.h" | 17 #include "grit/browser_resources.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 using chrome_browser_metrics::TrackingSynchronizer; |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 ChromeWebUIDataSource* CreateTrackingHTMLSource() { | 25 ChromeWebUIDataSource* CreateTrackingHTMLSource() { |
| 24 // TODO(eroman): Use kChromeUITrackingHost instead of kChromeUITrackingHost2 | 26 // TODO(eroman): Use kChromeUITrackingHost instead of kChromeUITrackingHost2 |
| 25 // once migration to webui is complete. | 27 // once migration to webui is complete. |
| 26 ChromeWebUIDataSource* source = | 28 ChromeWebUIDataSource* source = |
| 27 new ChromeWebUIDataSource(chrome::kChromeUITrackingHost2); | 29 new ChromeWebUIDataSource(chrome::kChromeUITrackingHost2); |
| 28 | 30 |
| 29 source->set_json_path("strings.js"); | 31 source->set_json_path("strings.js"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 62 | 64 |
| 63 web_ui_->RegisterMessageCallback("getData", | 65 web_ui_->RegisterMessageCallback("getData", |
| 64 base::Bind(&TrackingMessageHandler::OnGetData,base::Unretained(this))); | 66 base::Bind(&TrackingMessageHandler::OnGetData,base::Unretained(this))); |
| 65 web_ui_->RegisterMessageCallback("resetData", | 67 web_ui_->RegisterMessageCallback("resetData", |
| 66 base::Bind(&TrackingMessageHandler::OnResetData, | 68 base::Bind(&TrackingMessageHandler::OnResetData, |
| 67 base::Unretained(this))); | 69 base::Unretained(this))); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void TrackingMessageHandler::OnGetData(const ListValue* list) { | 72 void TrackingMessageHandler::OnGetData(const ListValue* list) { |
| 71 // Send the data to the renderer. | 73 TrackingUI* tracking_ui = reinterpret_cast<TrackingUI*>(web_ui_); |
| 72 scoped_ptr<Value> data_values(tracked_objects::ThreadData::ToValue()); | 74 tracking_ui->GetData(); |
| 73 web_ui_->CallJavascriptFunction("g_browserBridge.receivedData", | |
| 74 *data_values.get()); | |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TrackingMessageHandler::OnResetData(const ListValue* list) { | 77 void TrackingMessageHandler::OnResetData(const ListValue* list) { |
| 78 tracked_objects::ThreadData::ResetAllThreadData(); | 78 tracked_objects::ThreadData::ResetAllThreadData(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 TrackingUI::TrackingUI(TabContents* contents) : ChromeWebUI(contents) { | 83 TrackingUI::TrackingUI(TabContents* contents) : ChromeWebUI(contents) { |
| 84 ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<TrackingUI>(this)); |
| 85 ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); |
| 86 |
| 84 AddMessageHandler((new TrackingMessageHandler())->Attach(this)); | 87 AddMessageHandler((new TrackingMessageHandler())->Attach(this)); |
| 85 | 88 |
| 86 // Set up the chrome://tracking2/ source. | 89 // Set up the chrome://tracking2/ source. |
| 87 Profile::FromBrowserContext(contents->browser_context())-> | 90 Profile::FromBrowserContext(contents->browser_context())-> |
| 88 GetChromeURLDataManager()->AddDataSource(CreateTrackingHTMLSource()); | 91 GetChromeURLDataManager()->AddDataSource(CreateTrackingHTMLSource()); |
| 89 } | 92 } |
| 93 |
| 94 TrackingUI::~TrackingUI() { |
| 95 } |
| 96 |
| 97 void TrackingUI::GetData() { |
| 98 TrackingSynchronizer::FetchTrackingDataAsynchronously(ui_weak_ptr_); |
| 99 } |
| 100 |
| 101 void TrackingUI::ReceivedData(base::Value* value) { |
| 102 // Send the data to the renderer. |
| 103 scoped_ptr<Value> data_values(value); |
| 104 CallJavascriptFunction("g_browserBridge.receivedData", *data_values.get()); |
| 105 } |
| 106 |
| OLD | NEW |