Skip to content
Snippets Groups Projects
Commit e0e4d726 authored by akalin@chromium.org's avatar akalin@chromium.org
Browse files

[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
parent 52b15b4f
No related merge requests found
Showing
with 306 additions and 51 deletions
......@@ -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);
......
......@@ -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" />
......
......@@ -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(
......
// 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";
}
// 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_
// 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);
}
// 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_
// 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() {}
// 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_
<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>
<?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>
......@@ -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(
......
......@@ -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);
......
......@@ -62,7 +62,8 @@
# it easier for us to reference them internally.
'browser/resources/component_extension_resources.grd',
'browser/resources/net_internals_resources.grd',
'browser/resources/shared_resources.grd'
'browser/resources/shared_resources.grd',
'browser/resources/sync_internals_resources.grd',
],
'grit_info_cmd': ['python', '../tools/grit/grit_info.py',
'<@(grit_defines)'],
......@@ -1510,6 +1511,7 @@
'<(grit_out_dir)/component_extension_resources.pak',
'<(grit_out_dir)/net_internals_resources.pak',
'<(grit_out_dir)/shared_resources.pak',
'<(grit_out_dir)/sync_internals_resources.pak',
],
},
'inputs': [
......
......@@ -986,6 +986,12 @@
'browser/dom_ui/shown_sections_handler.h',
'browser/dom_ui/slideshow_ui.cc',
'browser/dom_ui/slideshow_ui.h',
'browser/dom_ui/sync_internals_html_source.cc',
'browser/dom_ui/sync_internals_html_source.h',
'browser/dom_ui/sync_internals_message_handler.cc',
'browser/dom_ui/sync_internals_message_handler.h',
'browser/dom_ui/sync_internals_ui.cc',
'browser/dom_ui/sync_internals_ui.h',
'browser/dom_ui/textfields_ui.cc',
'browser/dom_ui/textfields_ui.h',
'browser/dom_ui/tips_handler.cc',
......
......@@ -390,6 +390,7 @@
'<(grit_out_dir)/component_extension_resources.pak',
'<(grit_out_dir)/net_internals_resources.pak',
'<(grit_out_dir)/shared_resources.pak',
'<(grit_out_dir)/sync_internals_resources.pak',
],
},
'inputs': [
......
......@@ -64,6 +64,8 @@ const char kAboutMemoryURL[] = "about:memory";
const char kAboutNetInternalsURL[] = "about:net-internals";
const char kAboutPluginsURL[] = "about:plugins";
const char kAboutShorthangURL[] = "about:shorthang";
const char kAboutSyncURL[] = "about:sync";
const char kAboutSyncInternalsURL[] = "about:sync-internals";
const char kAboutTermsURL[] = "about:terms";
const char kAboutVaporwareURL[] = "about:vaporware";
const char kAboutVersionURL[] = "about:version";
......@@ -132,6 +134,7 @@ const char kChromeUIRemotingResourcesHost[] = "remotingresources";
const char kChromeUIResourcesHost[] = "resources";
const char kChromeUIScreenshotPath[] = "screenshots";
const char kChromeUISettingsHost[] = "settings";
const char kChromeUISyncInternalsHost[] = "sync-internals";
const char kChromeUISyncResourcesHost[] = "syncresources";
const char kChromeUITextfieldsHost[] = "textfields";
const char kChromeUIThemePath[] = "theme";
......@@ -164,6 +167,8 @@ const char kCloudPrintSetupHost[] = "cloudprintsetup";
const char kNetworkViewInternalsURL[] = "chrome://net-internals/";
const char kNetworkViewCacheURL[] = "chrome://view-http-cache/";
const char kSyncViewInternalsURL[] = "chrome://sync-internals/";
// GPU sub pages
const char kGpuInternalsURL[] = "chrome://gpu-internals/";
......
......@@ -57,6 +57,8 @@ extern const char kAboutMemoryURL[];
extern const char kAboutNetInternalsURL[];
extern const char kAboutPluginsURL[];
extern const char kAboutShorthangURL[];
extern const char kAboutSyncURL[];
extern const char kAboutSyncInternalsURL[];
extern const char kAboutTermsURL[];
extern const char kAboutVaporwareURL[];
extern const char kAboutVersionURL[];
......@@ -123,6 +125,7 @@ extern const char kChromeUIRemotingResourcesHost[];
extern const char kChromeUIResourcesHost[];
extern const char kChromeUIScreenshotPath[];
extern const char kChromeUISettingsHost[];
extern const char kChromeUISyncInternalsHost[];
extern const char kChromeUISyncResourcesHost[];
extern const char kChromeUITextfieldsHost[];
extern const char kChromeUIThemePath[];
......@@ -160,6 +163,9 @@ extern const char kCloudPrintSetupHost[];
extern const char kNetworkViewCacheURL[];
extern const char kNetworkViewInternalsURL[];
// Sync related URLs.
extern const char kSyncViewInternalsURL[];
// GPU related URLs
extern const char kGpuInternalsURL[];
......
......@@ -127,4 +127,7 @@
"chrome/browser/autofill/autofill_resources.grd": {
"messages": [19500],
},
"chrome/browser/resources/sync_internals_resources.grd": {
"includes": [20000],
},
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment