diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 12:16:06 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 12:16:06 +0000 |
commit | e0e4d726eba85f312c0d219f7ba302398a34d3d2 (patch) | |
tree | 5f0125f39b1f4be2c2284cd10548389bed18f0a6 /chrome/browser | |
parent | 52b15b4f40a2eb65a3d59c11d5f295d4217afe47 (diff) | |
download | chromium_src-e0e4d726eba85f312c0d219f7ba302398a34d3d2.zip chromium_src-e0e4d726eba85f312c0d219f7ba302398a34d3d2.tar.gz chromium_src-e0e4d726eba85f312c0d219f7ba302398a34d3d2.tar.bz2 |
[Sync] Port about:sync to DOMUI
Write chrome://sync-internals DOMUI page which is like about:sync but
automatically updates on sync events.
Make about:sync{,-internals} aliases for chrome://sync-internals.
More diagnostic capabilities will be added to chrome://sync-internals
in future CLs.
BUG=69500
TEST=Manual
Review URL: http://codereview.chromium.org/6299002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 43 | ||||
-rw-r--r-- | chrome/browser/browser_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.cc | 3 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_html_source.cc | 49 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_html_source.h | 31 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_message_handler.cc | 48 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_message_handler.h | 39 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_ui.cc | 30 | ||||
-rw-r--r-- | chrome/browser/dom_ui/sync_internals_ui.h | 21 | ||||
-rw-r--r-- | chrome/browser/resources/sync_internals/sync_index.html (renamed from chrome/browser/sync/resources/about_sync.html) | 38 | ||||
-rw-r--r-- | chrome/browser/resources/sync_internals_resources.grd | 24 | ||||
-rw-r--r-- | chrome/browser/sync/sync_ui_util.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/sync_ui_util.h | 1 |
13 files changed, 282 insertions, 50 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 0b42acd..83a27f0 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -40,8 +40,6 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/common/about_handler.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_version_info.h" @@ -80,8 +78,6 @@ #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" #endif -using sync_api::SyncManager; - using base::Time; using base::TimeDelta; @@ -115,7 +111,6 @@ const char kHistogramsPath[] = "histograms"; const char kMemoryRedirectPath[] = "memory-redirect"; const char kMemoryPath[] = "memory"; const char kStatsPath[] = "stats"; -const char kSyncPath[] = "sync"; const char kTasksPath[] = "tasks"; const char kTcmallocPath[] = "tcmalloc"; const char kTermsPath[] = "terms"; @@ -124,6 +119,7 @@ const char kAboutPath[] = "about"; // Not about:* pages, but included to make about:about look nicer const char kNetInternalsPath[] = "net-internals"; const char kPluginsPath[] = "plugins"; +const char kSyncInternalsPath[] = "sync-internals"; #if defined(OS_LINUX) const char kLinuxProxyConfigPath[] = "linux-proxy-config"; @@ -152,7 +148,7 @@ const char *kAllAboutPaths[] = { kNetInternalsPath, kPluginsPath, kStatsPath, - kSyncPath, + kSyncInternalsPath, kTasksPath, kTcmallocPath, kTermsPath, @@ -688,31 +684,6 @@ std::string AboutVersion(DictionaryValue* localized_strings) { version_html, localized_strings, "t" /* template root node id */); } - - -std::string AboutSync() { - FilePath user_data_dir; - if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) - return std::string(); - ProfileManager* profile_manager = g_browser_process->profile_manager(); - Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); - ProfileSyncService* service = profile->GetProfileSyncService(); - - DictionaryValue strings; - if (!service) { - strings.SetString("summary", "SYNC DISABLED"); - } else { - sync_ui_util::ConstructAboutInformation(service, &strings); - } - - static const base::StringPiece sync_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_ABOUT_SYNC_HTML)); - - return jstemplate_builder::GetTemplatesHtml( - sync_html, &strings , "t" /* template root node id */); -} - std::string VersionNumberToString(uint32 value) { int hi = (value >> 8) & 0xff; int low = value & 0xff; @@ -801,8 +772,6 @@ void AboutSource::StartDataRequest(const std::string& path_raw, } else if (path == kSandboxPath) { response = AboutSandbox(); #endif - } else if (path == kSyncPath) { - response = AboutSync(); } FinishDataRequest(response, request_id); @@ -1049,6 +1018,14 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { return true; } + // Rewrite about:sync-internals/* URLs (and about:sync, too, for + // legacy reasons) to chrome://sync-internals/* + if (StartsWithAboutSpecifier(*url, chrome::kAboutSyncInternalsURL) || + StartsWithAboutSpecifier(*url, chrome::kAboutSyncURL)) { + *url = RemapAboutURL(chrome::kSyncViewInternalsURL, *url); + return true; + } + // Rewrite about:plugins to chrome://plugins/. if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutPluginsURL)) { *url = GURL(chrome::kChromeUIPluginsURL); diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index e3bc1e4..6a288ba 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -24,7 +24,6 @@ without changes to the corresponding grd file. etaa --> <include name="IDR_ABOUT_MEMORY_HTML" file="resources\about_memory.html" flattenhtml="true" type="BINDATA" /> </if> <include name="IDR_ABOUT_STATS_HTML" file="resources\about_stats.html" flattenhtml="true" type="BINDATA" /> - <include name="IDR_ABOUT_SYNC_HTML" file="sync\resources\about_sync.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_ABOUT_VERSION_HTML" file="resources\about_version.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_BOOKMARKS_MANIFEST" file="resources\bookmark_manager\manifest.json" type="BINDATA" /> <include name="IDR_CREDITS_HTML" file="resources\about_credits.html" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index 69081da..2546253 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -23,6 +23,7 @@ #include "chrome/browser/dom_ui/remoting_ui.h" #include "chrome/browser/dom_ui/options/options_ui.h" #include "chrome/browser/dom_ui/slideshow_ui.h" +#include "chrome/browser/dom_ui/sync_internals_ui.h" #include "chrome/browser/dom_ui/textfields_ui.h" #include "chrome/browser/extensions/extension_dom_ui.h" #include "chrome/browser/extensions/extension_service.h" @@ -164,6 +165,8 @@ static DOMUIFactoryFunction GetDOMUIFactoryFunction(Profile* profile, return &NewDOMUI<NetInternalsUI>; if (url.host() == chrome::kChromeUIPluginsHost) return &NewDOMUI<PluginsUI>; + if (url.host() == chrome::kChromeUISyncInternalsHost) + return &NewDOMUI<SyncInternalsUI>; #if defined(ENABLE_REMOTING) if (url.host() == chrome::kChromeUIRemotingHost) { if (CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/dom_ui/sync_internals_html_source.cc b/chrome/browser/dom_ui/sync_internals_html_source.cc new file mode 100644 index 0000000..456c93f --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_html_source.cc @@ -0,0 +1,49 @@ +// 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/dom_ui/sync_internals_html_source.h" + +#include <algorithm> + +#include "app/resource_bundle.h" +#include "base/message_loop.h" +#include "base/ref_counted.h" +#include "base/ref_counted_memory.h" +#include "base/string_piece.h" +#include "base/values.h" +#include "chrome/common/jstemplate_builder.h" +#include "chrome/common/url_constants.h" +#include "grit/sync_internals_resources.h" + +SyncInternalsHTMLSource::SyncInternalsHTMLSource() + : DataSource(chrome::kChromeUISyncInternalsHost, + MessageLoop::current()) {} + +SyncInternalsHTMLSource::~SyncInternalsHTMLSource() {} + +void SyncInternalsHTMLSource::StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id) { + base::StringPiece html_template( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_SYNC_INTERNALS_INDEX_HTML)); + DictionaryValue localized_strings; + SetFontAndTextDirection(&localized_strings); + + std::string html(html_template.data(), html_template.size()); + jstemplate_builder::AppendI18nTemplateSourceHtml(&html); + jstemplate_builder::AppendJsTemplateSourceHtml(&html); + jstemplate_builder::AppendJsonHtml(&localized_strings, &html); + jstemplate_builder::AppendI18nTemplateProcessHtml(&html); + + scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes()); + bytes->data.resize(html.size()); + std::copy(html.begin(), html.end(), bytes->data.begin()); + SendResponse(request_id, bytes); +} + +std::string SyncInternalsHTMLSource::GetMimeType( + const std::string& path) const { + return "text/html"; +} diff --git a/chrome/browser/dom_ui/sync_internals_html_source.h b/chrome/browser/dom_ui/sync_internals_html_source.h new file mode 100644 index 0000000..bb8ab48 --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_html_source.h @@ -0,0 +1,31 @@ +// 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. + +#ifndef CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_HTML_SOURCE_H_ +#define CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_HTML_SOURCE_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" + +class SyncInternalsHTMLSource : public ChromeURLDataManager::DataSource { + public: + SyncInternalsHTMLSource(); + + // ChromeURLDataManager::DataSource implementation. + virtual void StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id); + virtual std::string GetMimeType(const std::string& path) const; + + protected: + virtual ~SyncInternalsHTMLSource(); + + private: + DISALLOW_COPY_AND_ASSIGN(SyncInternalsHTMLSource); +}; + +#endif // CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_HTML_SOURCE_H_ diff --git a/chrome/browser/dom_ui/sync_internals_message_handler.cc b/chrome/browser/dom_ui/sync_internals_message_handler.cc new file mode 100644 index 0000000..5ef0084 --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_message_handler.cc @@ -0,0 +1,48 @@ +// 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/dom_ui/sync_internals_message_handler.h" + +#include "base/callback.h" +#include "base/logging.h" +#include "base/values.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/sync_ui_util.h" + +SyncInternalsMessageHandler::SyncInternalsMessageHandler(Profile* profile) + : profile_(profile) { + DCHECK(profile_); + ProfileSyncService* service = profile_->GetProfileSyncService(); + if (service) { + service->AddObserver(this); + } + // TODO(akalin): Listen for when the service gets created/destroyed. +} + +SyncInternalsMessageHandler::~SyncInternalsMessageHandler() { + ProfileSyncService* service = profile_->GetProfileSyncService(); + if (service) { + service->RemoveObserver(this); + } +} + +void SyncInternalsMessageHandler::OnStateChanged() { + dom_ui_->CallJavascriptFunction(L"onSyncServiceStateChanged"); +} + +void SyncInternalsMessageHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback( + "getAboutInfo", + NewCallback( + this, &SyncInternalsMessageHandler::HandleGetAboutInfo)); +} + +void SyncInternalsMessageHandler::HandleGetAboutInfo(const ListValue* args) { + ProfileSyncService* service = profile_->GetProfileSyncService(); + DictionaryValue about_info; + sync_ui_util::ConstructAboutInformation(service, &about_info); + + dom_ui_->CallJavascriptFunction(L"onGetAboutInfoFinished", about_info); +} diff --git a/chrome/browser/dom_ui/sync_internals_message_handler.h b/chrome/browser/dom_ui/sync_internals_message_handler.h new file mode 100644 index 0000000..341750e --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_message_handler.h @@ -0,0 +1,39 @@ +// 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. + +#ifndef CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/dom_ui/dom_ui.h" +#include "chrome/browser/sync/profile_sync_service_observer.h" + +class Profile; + +class SyncInternalsMessageHandler : public DOMMessageHandler, + public ProfileSyncServiceObserver { + public: + // Does not take ownership of |profile|, which must outlive this + // object. + explicit SyncInternalsMessageHandler(Profile* profile); + virtual ~SyncInternalsMessageHandler(); + + // ProfileSyncServiceObserver implementation. + virtual void OnStateChanged(); + + protected: + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + private: + // Callback handlers. + void HandleGetAboutInfo(const ListValue* args); + + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(SyncInternalsMessageHandler); +}; + +#endif // CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_MESSAGE_HANDLER_H_ diff --git a/chrome/browser/dom_ui/sync_internals_ui.cc b/chrome/browser/dom_ui/sync_internals_ui.cc new file mode 100644 index 0000000..838f5d6 --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_ui.cc @@ -0,0 +1,30 @@ +// 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/dom_ui/sync_internals_ui.h" + +#include "base/ref_counted.h" +#include "base/task.h" +#include "base/tracked_objects.h" +#include "chrome/browser/browser_thread.h" +#include "chrome/browser/dom_ui/chrome_url_data_manager.h" +#include "chrome/browser/dom_ui/sync_internals_html_source.h" +#include "chrome/browser/dom_ui/sync_internals_message_handler.h" +#include "chrome/browser/tab_contents/tab_contents.h" + +SyncInternalsUI::SyncInternalsUI(TabContents* contents) : DOMUI(contents) { + SyncInternalsMessageHandler* message_handler = + new SyncInternalsMessageHandler(contents->profile()); + message_handler->Attach(this); + AddMessageHandler(message_handler); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod( + ChromeURLDataManager::GetInstance(), + &ChromeURLDataManager::AddDataSource, + make_scoped_refptr(new SyncInternalsHTMLSource()))); +} + +SyncInternalsUI::~SyncInternalsUI() {} diff --git a/chrome/browser/dom_ui/sync_internals_ui.h b/chrome/browser/dom_ui/sync_internals_ui.h new file mode 100644 index 0000000..d17f34a --- /dev/null +++ b/chrome/browser/dom_ui/sync_internals_ui.h @@ -0,0 +1,21 @@ +// 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. + +#ifndef CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_UI_H_ +#define CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_UI_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/dom_ui/dom_ui.h" + +class SyncInternalsUI : public DOMUI { + public: + explicit SyncInternalsUI(TabContents* contents); + virtual ~SyncInternalsUI(); + + private: + DISALLOW_COPY_AND_ASSIGN(SyncInternalsUI); +}; + +#endif // CHROME_BROWSER_DOM_UI_SYNC_INTERNALS_UI_H_ diff --git a/chrome/browser/sync/resources/about_sync.html b/chrome/browser/resources/sync_internals/sync_index.html index 6f62f5d..212a7bf 100644 --- a/chrome/browser/sync/resources/about_sync.html +++ b/chrome/browser/resources/sync_internals/sync_index.html @@ -1,13 +1,23 @@ -<html> -</html> -<html id="t"> +<!DOCTYPE HTML> +<html i18n-values="dir:textdirection;"> <head> -<title>About Sync</title> +<script> +function onLoad() { + chrome.send('getAboutInfo'); +} + +function onGetAboutInfoFinished(aboutInfo) { + var aboutInfoDiv = document.getElementById('aboutInfo'); + jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv); +} + +function onSyncServiceStateChanged() { + chrome.send('getAboutInfo'); +} +</script> <style type="text/css"> body { - font-size: 84%; - font-family: Arial, Helvetica, sans-serif; padding: 0.75em; margin: 0; min-width: 45em; @@ -64,16 +74,11 @@ div#header h1 { color: white; } -.desc { - font-size: 84%; -} - .err { color: red; } div#header p { - font-size: 84%; font-style: italic; padding: 0; margin: 0; @@ -85,7 +90,6 @@ div#header p { table.list { line-height: 200%; border-collapse: collapse; - font-size: 84%; table-layout: fixed; } table.list:not([class*='filtered']) tr:nth-child(odd) td { @@ -136,10 +140,14 @@ table.list#details .name { background-repeat: no-repeat; } </style> + </head> -<body> +<body i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize" + onload="onLoad()"> + +<div id='aboutInfo'> <div id='header'> - <h1>About Sync</h1> + <h1>Sync Internals</h1> <p> Sync engine diagnostic data</p> </div> <div id='content'> @@ -210,5 +218,7 @@ table.list#details .name { </td> </table> </div> +</div> + </body> </html> diff --git a/chrome/browser/resources/sync_internals_resources.grd b/chrome/browser/resources/sync_internals_resources.grd new file mode 100644 index 0000000..1c5c98b --- /dev/null +++ b/chrome/browser/resources/sync_internals_resources.grd @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- This comment is only here because changes to resources are not picked up + without changes to the corresponding grd file. --> +<grit latest_public_release="0" current_release="1"> + <outputs> + <output filename="grit/sync_internals_resources.h" type="rc_header"> + <emit emit_type='prepend'></emit> + </output> + <!-- Note: These next two files aren't actually used by Chrome, but they're + needed so that Visual Studio doesn't try to continually rebuild this + .grd (which it will do if it can't find some relevant output files). + Supposedly we could update our .gyp rules to not need this, but I don't + know how to do it and this doesn't really cost us anything... --> + <output filename="grit/sync_internals_resources_map.cc" type="resource_file_map_source" /> + <output filename="grit/sync_internals_resources_map.h" type="resource_map_header" /> + <output filename="sync_internals_resources.pak" type="data_package" /> + </outputs> + <release seq="1"> + <includes> + <!-- TODO(akalin): rename back to index.html once bug 69633 is fixed. --> + <include name="IDR_SYNC_INTERNALS_INDEX_HTML" file="sync_internals/sync_index.html" flattenhtml="true" type="BINDATA" /> + </includes> + </release> +</grit> diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc index 3f45c38..3e73fbc 100644 --- a/chrome/browser/sync/sync_ui_util.cc +++ b/chrome/browser/sync/sync_ui_util.cc @@ -281,8 +281,8 @@ std::string MakeSyncAuthErrorText( void ConstructAboutInformation(ProfileSyncService* service, DictionaryValue* strings) { - CHECK(strings != NULL); - if (!service->HasSyncSetupCompleted()) { + CHECK(strings); + if (!service || !service->HasSyncSetupCompleted()) { strings->SetString("summary", "SYNC DISABLED"); } else { sync_api::SyncManager::Status full_status( diff --git a/chrome/browser/sync/sync_ui_util.h b/chrome/browser/sync/sync_ui_util.h index 5a168c4..95e3ac7 100644 --- a/chrome/browser/sync/sync_ui_util.h +++ b/chrome/browser/sync/sync_ui_util.h @@ -56,6 +56,7 @@ void AddBoolSyncDetail(ListValue* details, const std::string& stat_name, bool stat_value); +// |service| can be NULL. void ConstructAboutInformation(ProfileSyncService* service, DictionaryValue* strings); |