diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 23:38:45 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 23:38:45 +0000 |
commit | fae5a932cfca282ef028ac054e8719afce554e08 (patch) | |
tree | b9afc2854ec4113406e71b8a72737879b99040b1 | |
parent | dd1f9fe143f20d4be760c44c974351e8c9aaca6d (diff) | |
download | chromium_src-fae5a932cfca282ef028ac054e8719afce554e08.zip chromium_src-fae5a932cfca282ef028ac054e8719afce554e08.tar.gz chromium_src-fae5a932cfca282ef028ac054e8719afce554e08.tar.bz2 |
Complete the rename from about:tracking2 --> about:profiler by changing the implementation code to always reference "profiler" rather than "tracking".
BUG=100992
Review URL: http://codereview.chromium.org/8520016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110207 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_resources.grd | 4 | ||||
-rw-r--r-- | chrome/browser/metrics/tracking_synchronizer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/metrics/tracking_synchronizer.h | 10 | ||||
-rw-r--r-- | chrome/browser/resources/profiler.html (renamed from chrome/browser/resources/tracking.html) | 0 | ||||
-rw-r--r-- | chrome/browser/resources/profiler.js (renamed from chrome/browser/resources/tracking.js) | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_factory.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/profiler_ui.cc | 172 | ||||
-rw-r--r-- | chrome/browser/ui/webui/profiler_ui.h (renamed from chrome/browser/ui/webui/tracking_ui.h) | 20 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 2 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 2 |
11 files changed, 199 insertions, 27 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index ebbe5661..0e7fa6b 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -93,6 +93,8 @@ <include name="IDR_POLICY_JS" file="resources\policy.js" type="BINDATA"/> <include name="IDR_PRINT_PREVIEW_HTML" file="resources\print_preview\print_preview.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_PRINT_PREVIEW_JS" file="resources\print_preview\print_preview.js" flattenhtml="true" type="BINDATA" /> + <include name="IDR_PROFILER_HTML" file="resources\profiler.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> + <include name="IDR_PROFILER_JS" file="resources\profiler.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_READER_OUT_OF_DATE_HTML" file="resources\reader_out_of_date.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_SAFE_BROWSING_MALWARE_BLOCK" file="resources\safe_browsing_malware_block.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK" file="resources\safe_browsing_multiple_threat_block.html" flattenhtml="true" type="BINDATA" /> @@ -114,8 +116,6 @@ <include name="IDR_TASK_MANAGER_JS" file="resources\task_manager\main.js" type="BINDATA" /> <include name="IDR_TRACING_HTML" file="resources\tracing.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_TRACING_JS" file="resources\tracing.js" flattenhtml="true" type="BINDATA" /> - <include name="IDR_TRACKING_HTML" file="resources\tracking.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> - <include name="IDR_TRACKING_JS" file="resources\tracking.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_TRANSLATE_JS" file="resources\translate.js" type="BINDATA" /> <include name="IDR_WEBSTORE_MANIFEST" file="resources\webstore_app\manifest.json" type="BINDATA" /> <if expr="not pp_ifdef('chromeos')"> diff --git a/chrome/browser/metrics/tracking_synchronizer.cc b/chrome/browser/metrics/tracking_synchronizer.cc index 7e89367..e1b3673 100644 --- a/chrome/browser/metrics/tracking_synchronizer.cc +++ b/chrome/browser/metrics/tracking_synchronizer.cc @@ -55,7 +55,7 @@ TrackingSynchronizer* TrackingSynchronizer::CurrentSynchronizer() { // static void TrackingSynchronizer::FetchTrackingDataAsynchronously( - const base::WeakPtr<TrackingUI>& callback_object) { + const base::WeakPtr<ProfilerUI>& callback_object) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); TrackingSynchronizer* current_synchronizer = CurrentSynchronizer(); @@ -159,7 +159,7 @@ void TrackingSynchronizer::DeserializeTrackingListOnUI( } int TrackingSynchronizer::RegisterAndNotifyAllProcesses( - const base::WeakPtr<TrackingUI>& callback_object) { + const base::WeakPtr<ProfilerUI>& callback_object) { // To iterate over all processes, or to send messages to the hosts, we need // to be on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/chrome/browser/metrics/tracking_synchronizer.h b/chrome/browser/metrics/tracking_synchronizer.h index fff2a63..fda547f 100644 --- a/chrome/browser/metrics/tracking_synchronizer.h +++ b/chrome/browser/metrics/tracking_synchronizer.h @@ -15,7 +15,7 @@ #include "base/memory/weak_ptr.h" #include "base/time.h" #include "base/values.h" -#include "chrome/browser/ui/webui/tracking_ui.h" +#include "chrome/browser/ui/webui/profiler_ui.h" #include "content/common/child_process_info.h" #include "content/public/browser/browser_thread.h" @@ -42,7 +42,7 @@ class TrackingSynchronizer : public // The "RequestContext" structure describes an individual request received // from the UI. struct RequestContext { - RequestContext(const base::WeakPtr<TrackingUI>& callback_object, + RequestContext(const base::WeakPtr<ProfilerUI>& callback_object, int sequence_number, int processes_pending, base::TimeTicks callback_start_time) @@ -55,7 +55,7 @@ class TrackingSynchronizer : public ~RequestContext() {} // Requests are made to asynchronously send data to the |callback_object_|. - base::WeakPtr<TrackingUI> callback_object_; + base::WeakPtr<ProfilerUI> callback_object_; // The sequence number used by the most recent update request to contact all // processes. @@ -86,7 +86,7 @@ class TrackingSynchronizer : public // the data received from each sub-process. // This method is accessible on UI thread. static void FetchTrackingDataAsynchronously( - const base::WeakPtr<TrackingUI>& callback_object); + const base::WeakPtr<ProfilerUI>& callback_object); // Contact all processes and set tracking status to |enable|. // This method is accessible on UI thread. @@ -129,7 +129,7 @@ class TrackingSynchronizer : public // |callback_object| in |outstanding_requests_| map. Return the // sequence_number_ that was used. This method is accessible on UI thread. int RegisterAndNotifyAllProcesses( - const base::WeakPtr<TrackingUI>& callback_object); + const base::WeakPtr<ProfilerUI>& callback_object); // It finds the |callback_object_| in |outstanding_requests_| map for the // given |sequence_number| and notifies the |callback_object_| about the diff --git a/chrome/browser/resources/tracking.html b/chrome/browser/resources/profiler.html index 29a999f..29a999f 100644 --- a/chrome/browser/resources/tracking.html +++ b/chrome/browser/resources/profiler.html diff --git a/chrome/browser/resources/tracking.js b/chrome/browser/resources/profiler.js index b9bf11fd..28ab5ae 100644 --- a/chrome/browser/resources/tracking.js +++ b/chrome/browser/resources/profiler.js @@ -61,7 +61,7 @@ var BrowserBridge = (function() { })(); /** - * This class handles the presentation of our tracking view. Used as a + * This class handles the presentation of our profiler view. Used as a * singleton. */ var MainView = (function() { diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index 43647a8..3326c3a 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -34,12 +34,12 @@ #include "chrome/browser/ui/webui/plugins_ui.h" #include "chrome/browser/ui/webui/policy_ui.h" #include "chrome/browser/ui/webui/print_preview_ui.h" +#include "chrome/browser/ui/webui/profiler_ui.h" #include "chrome/browser/ui/webui/quota_internals_ui.h" #include "chrome/browser/ui/webui/sessions_ui.h" #include "chrome/browser/ui/webui/sync_internals_ui.h" #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" #include "chrome/browser/ui/webui/tracing_ui.h" -#include "chrome/browser/ui/webui/tracking_ui.h" #include "chrome/browser/ui/webui/workers_ui.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_constants.h" @@ -211,8 +211,8 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, return &NewWebUI<TaskManagerUI>; if (url.host() == chrome::kChromeUITracingHost) return &NewWebUI<TracingUI>; - if (url.host() == chrome::kChromeUITrackingHost2) - return &NewWebUI<TrackingUI>; + if (url.host() == chrome::kChromeUIProfilerHost) + return &NewWebUI<ProfilerUI>; if (url.host() == chrome::kChromeUIWorkersHost) return &NewWebUI<WorkersUI>; diff --git a/chrome/browser/ui/webui/profiler_ui.cc b/chrome/browser/ui/webui/profiler_ui.cc new file mode 100644 index 0000000..0264edd --- /dev/null +++ b/chrome/browser/ui/webui/profiler_ui.cc @@ -0,0 +1,172 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/profiler_ui.h" + +#include <string> + +// When testing the javacript code, it is cumbersome to have to keep +// re-building the resouces package and reloading the browser. To solve +// this, enable the following flag to read the webapp's source files +// directly off disk, so all you have to do is refresh the page to +// test the modifications. +//#define USE_SOURCE_FILES_DIRECTLY + +#include "base/bind.h" +#include "base/tracked_objects.h" +#include "chrome/browser/metrics/tracking_synchronizer.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" +#include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/trace_controller.h" +#include "grit/browser_resources.h" +#include "grit/generated_resources.h" + +#ifdef USE_SOURCE_FILES_DIRECTLY +#include "base/base_paths.h" +#include "base/file_util.h" +#include "base/memory/ref_counted_memory.h" +#include "base/path_service.h" +#endif // USE_SOURCE_FILES_DIRECTLY + +using content::BrowserThread; +using chrome_browser_metrics::TrackingSynchronizer; + +namespace { + +#ifdef USE_SOURCE_FILES_DIRECTLY + +class ProfilerWebUIDataSource : public ChromeURLDataManager::DataSource { + public: + ProfilerWebUIDataSource() + : DataSource(chrome::kChromeUIProfilerHost, MessageLoop::current()) { + } + + protected: + // ChromeURLDataManager + virtual std::string GetMimeType(const std::string& path) const OVERRIDE { + if (EndsWith(path, ".js", false)) + return "application/javascript"; + return "text/html"; + } + + virtual void StartDataRequest(const std::string& path, + bool is_incognito, + int request_id) OVERRIDE { + FilePath base_path; + PathService::Get(base::DIR_SOURCE_ROOT, &base_path); + base_path = base_path.AppendASCII("chrome"); + base_path = base_path.AppendASCII("browser"); + base_path = base_path.AppendASCII("resources"); + + // If no resource was specified, default to profiler.html. + std::string filename = path.empty() ? "profiler.html" : path; + + FilePath file_path; + file_path = base_path.AppendASCII(filename); + + // Read the file synchronously and send it as the response. + base::ThreadRestrictions::ScopedAllowIO allow; + std::string file_contents; + if (!file_util::ReadFileToString(file_path, &file_contents)) + LOG(ERROR) << "Couldn't read file: " << file_path.value(); + scoped_refptr<base::RefCountedString> response = + new base::RefCountedString(); + response->data() = file_contents; + SendResponse(request_id, response); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ProfilerWebUIDataSource); +}; + +ChromeURLDataManager::DataSource* CreateProfilerHTMLSource() { + return new ProfilerWebUIDataSource(); +} + +#else // USE_SOURCE_FILES_DIRECTLY + +ChromeWebUIDataSource* CreateProfilerHTMLSource() { + ChromeWebUIDataSource* source = + new ChromeWebUIDataSource(chrome::kChromeUIProfilerHost); + + source->set_json_path("strings.js"); + source->add_resource_path("profiler.js", IDR_PROFILER_JS); + source->set_default_resource(IDR_PROFILER_HTML); + return source; +} + +#endif + +// This class receives javascript messages from the renderer. +// Note that the WebUI infrastructure runs on the UI thread, therefore all of +// this class's methods are expected to run on the UI thread. +class ProfilerMessageHandler : public WebUIMessageHandler { + public: + ProfilerMessageHandler() {} + + // WebUIMessageHandler implementation. + virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; + virtual void RegisterMessages() OVERRIDE; + + // Messages. + void OnGetData(const ListValue* list); + void OnResetData(const ListValue* list); + + private: + DISALLOW_COPY_AND_ASSIGN(ProfilerMessageHandler); +}; + +WebUIMessageHandler* ProfilerMessageHandler::Attach(WebUI* web_ui) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); + return result; +} + +void ProfilerMessageHandler::RegisterMessages() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + web_ui_->RegisterMessageCallback("getData", + base::Bind(&ProfilerMessageHandler::OnGetData,base::Unretained(this))); + web_ui_->RegisterMessageCallback("resetData", + base::Bind(&ProfilerMessageHandler::OnResetData, + base::Unretained(this))); +} + +void ProfilerMessageHandler::OnGetData(const ListValue* list) { + ProfilerUI* profiler_ui = reinterpret_cast<ProfilerUI*>(web_ui_); + profiler_ui->GetData(); +} + +void ProfilerMessageHandler::OnResetData(const ListValue* list) { + tracked_objects::ThreadData::ResetAllThreadData(); +} + +} // namespace + +ProfilerUI::ProfilerUI(TabContents* contents) : ChromeWebUI(contents) { + ui_weak_ptr_factory_.reset(new base::WeakPtrFactory<ProfilerUI>(this)); + ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr(); + + AddMessageHandler((new ProfilerMessageHandler())->Attach(this)); + + // Set up the chrome://profiler/ source. + Profile::FromBrowserContext(contents->browser_context())-> + GetChromeURLDataManager()->AddDataSource(CreateProfilerHTMLSource()); +} + +ProfilerUI::~ProfilerUI() { +} + +void ProfilerUI::GetData() { + TrackingSynchronizer::FetchTrackingDataAsynchronously(ui_weak_ptr_); +} + +void ProfilerUI::ReceivedData(base::Value* value) { + // Send the data to the renderer. + scoped_ptr<Value> data_values(value); + CallJavascriptFunction("g_browserBridge.receivedData", *data_values.get()); +} + diff --git a/chrome/browser/ui/webui/tracking_ui.h b/chrome/browser/ui/webui/profiler_ui.h index afa2128..d36f275 100644 --- a/chrome/browser/ui/webui/tracking_ui.h +++ b/chrome/browser/ui/webui/profiler_ui.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_WEBUI_TRACKING_UI_H_ -#define CHROME_BROWSER_UI_WEBUI_TRACKING_UI_H_ +#ifndef CHROME_BROWSER_UI_WEBUI_PROFILER_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_PROFILER_UI_H_ #pragma once #include "base/memory/scoped_ptr.h" @@ -11,11 +11,11 @@ #include "base/values.h" #include "chrome/browser/ui/webui/chrome_web_ui.h" -// The C++ back-end for the chrome://tracking2 webui page. -class TrackingUI : public ChromeWebUI { +// The C++ back-end for the chrome://profiler webui page. +class ProfilerUI : public ChromeWebUI { public: - explicit TrackingUI(TabContents* contents); - virtual ~TrackingUI(); + explicit ProfilerUI(TabContents* contents); + virtual ~ProfilerUI(); // Get the tracking data from TrackingSynchronizer. void GetData(); @@ -25,10 +25,10 @@ class TrackingUI : public ChromeWebUI { private: // Used to get |weak_ptr_| to self on the UI thread. - scoped_ptr<base::WeakPtrFactory<TrackingUI> > ui_weak_ptr_factory_; - base::WeakPtr<TrackingUI> ui_weak_ptr_; + scoped_ptr<base::WeakPtrFactory<ProfilerUI> > ui_weak_ptr_factory_; + base::WeakPtr<ProfilerUI> ui_weak_ptr_; - DISALLOW_COPY_AND_ASSIGN(TrackingUI); + DISALLOW_COPY_AND_ASSIGN(ProfilerUI); }; -#endif // CHROME_BROWSER_UI_WEBUI_TRACKING_UI_H_ +#endif // CHROME_BROWSER_UI_WEBUI_PROFILER_UI_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1164397..7e5ca2d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3879,6 +3879,8 @@ 'browser/ui/webui/print_preview_handler.h', 'browser/ui/webui/print_preview_ui.cc', 'browser/ui/webui/print_preview_ui.h', + 'browser/ui/webui/profiler_ui.cc', + 'browser/ui/webui/profiler_ui.h', 'browser/ui/webui/quota_internals_handler.cc', 'browser/ui/webui/quota_internals_handler.h', 'browser/ui/webui/quota_internals_proxy.cc', @@ -3917,8 +3919,6 @@ 'browser/ui/webui/theme_source.h', 'browser/ui/webui/tracing_ui.cc', 'browser/ui/webui/tracing_ui.h', - 'browser/ui/webui/tracking_ui.cc', - 'browser/ui/webui/tracking_ui.h', 'browser/ui/webui/web_ui_util.cc', 'browser/ui/webui/web_ui_util.h', 'browser/ui/webui/workers_ui.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 1a742ba..9cb103f 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -164,6 +164,7 @@ const char kChromeUINewTabHost[] = "newtab"; const char kChromeUIPluginsHost[] = "plugins"; const char kChromeUIPolicyHost[] = "policy"; const char kChromeUIPrintHost[] = "print"; +const char kChromeUIProfilerHost[] = "profiler"; const char kChromeUIQuotaInternalsHost[] = "quota-internals"; const char kChromeUIResourcesHost[] = "resources"; const char kChromeUISessionsHost[] = "sessions"; @@ -182,7 +183,6 @@ const char kChromeUIThumbnailHost[] = "thumb"; const char kChromeUITouchIconHost[] = "touch-icon"; const char kChromeUITracingHost[] = "tracing"; const char kChromeUITrackingHost[] = "tracking"; -const char kChromeUITrackingHost2[] = "profiler"; const char kChromeUIVersionHost[] = "version"; const char kChromeUIWorkersHost[] = "workers"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 3dc7163..70a3341 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -156,6 +156,7 @@ extern const char kChromeUINewTabHost[]; extern const char kChromeUIPluginsHost[]; extern const char kChromeUIPolicyHost[]; extern const char kChromeUIPrintHost[]; +extern const char kChromeUIProfilerHost[]; extern const char kChromeUIQuotaInternalsHost[]; extern const char kChromeUIResourcesHost[]; extern const char kChromeUISessionsHost[]; @@ -174,7 +175,6 @@ extern const char kChromeUIThumbnailHost[]; extern const char kChromeUITouchIconHost[]; extern const char kChromeUITracingHost[]; extern const char kChromeUITrackingHost[]; -extern const char kChromeUITrackingHost2[]; extern const char kChromeUIVersionHost[]; extern const char kChromeUIWorkersHost[]; |