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

Unified Diff: chrome/browser/ui/webui/sync_internals_message_handler.cc

Issue 162283002: Move towards event-driven JS on about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes and rebase Created 6 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/sync_internals_message_handler.cc
diff --git a/chrome/browser/ui/webui/sync_internals_message_handler.cc b/chrome/browser/ui/webui/sync_internals_message_handler.cc
index ecd38eb94f842d4560b457c28b8da54731e1de50..264f24d5eb978438323540e29b64d06fe291951f 100644
--- a/chrome/browser/ui/webui/sync_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/sync_internals_message_handler.cc
@@ -34,21 +34,25 @@ SyncInternalsMessageHandler::~SyncInternalsMessageHandler() {
void SyncInternalsMessageHandler::RegisterMessages() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- // Init our link to the JsController.
+ // Register for ProfileSyncService events.
ProfileSyncService* service = GetProfileSyncService();
if (service)
+ service->AddObserver(this);
Dan Beam 2014/02/14 22:22:40 nit: seems like you could combine this code into:
+
+ // Init our link to the JsController.
+ if (service)
js_controller_ = service->GetJsController();
if (js_controller_)
js_controller_->AddJsEventHandler(this);
web_ui()->RegisterMessageCallback(
- "getAboutInfo",
- base::Bind(&SyncInternalsMessageHandler::OnGetAboutInfo,
+ "requestUpdatedAboutInfo",
+ base::Bind(&SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "getListOfTypes",
- base::Bind(&SyncInternalsMessageHandler::OnGetListOfTypes,
+ "requestListOfTypes",
+ base::Bind(&SyncInternalsMessageHandler::HandleRequestListOfTypes,
base::Unretained(this)));
RegisterJsControllerCallback("getNotificationState");
@@ -57,27 +61,27 @@ void SyncInternalsMessageHandler::RegisterMessages() {
RegisterJsControllerCallback("getClientServerTraffic");
}
-void SyncInternalsMessageHandler::OnGetAboutInfo(const base::ListValue* args) {
- // TODO(rlarocque): We should DCHECK(!args) here. See crbug.com/334431.
- scoped_ptr<base::DictionaryValue> value =
- sync_ui_util::ConstructAboutInformation(GetProfileSyncService());
- web_ui()->CallJavascriptFunction(
- "chrome.sync.getAboutInfo.handleReply",
- *value);
+void SyncInternalsMessageHandler::HandleRequestUpdatedAboutInfo(
+ const base::ListValue* args) {
+ DCHECK(args->empty());
+ SendAboutInfo();
}
-void SyncInternalsMessageHandler::OnGetListOfTypes(
+void SyncInternalsMessageHandler::HandleRequestListOfTypes(
const base::ListValue* args) {
- // TODO(rlarocque): We should DCHECK(!args) here. See crbug.com/334431.
- base::ListValue type_list;
+ DCHECK(args->empty());
+ base::DictionaryValue event_details;
+ scoped_ptr<base::ListValue> type_list(new base::ListValue());
ModelTypeSet protocol_types = syncer::ProtocolTypes();
for (ModelTypeSet::Iterator it = protocol_types.First();
it.Good(); it.Inc()) {
- type_list.Append(new base::StringValue(ModelTypeToString(it.Get())));
+ type_list->Append(new base::StringValue(ModelTypeToString(it.Get())));
}
+ event_details.Set("types", type_list.release());
web_ui()->CallJavascriptFunction(
- "chrome.sync.getListOfTypes.handleReply",
- type_list);
+ "chrome.sync.dispatchEvent",
+ base::StringValue("onReceivedListOfTypes"),
+ event_details);
}
void SyncInternalsMessageHandler::HandleJsReply(
@@ -90,6 +94,10 @@ void SyncInternalsMessageHandler::HandleJsReply(
web_ui()->CallJavascriptFunction(reply_handler, arg_list);
}
+void SyncInternalsMessageHandler::OnStateChanged() {
+ SendAboutInfo();
+}
+
void SyncInternalsMessageHandler::HandleJsEvent(
const std::string& name,
const JsEventDetails& details) {
@@ -109,6 +117,15 @@ void SyncInternalsMessageHandler::RegisterJsControllerCallback(
name));
}
+void SyncInternalsMessageHandler::SendAboutInfo() {
+ scoped_ptr<base::DictionaryValue> value =
+ sync_ui_util::ConstructAboutInformation(GetProfileSyncService());
+ web_ui()->CallJavascriptFunction(
+ "chrome.sync.dispatchEvent",
+ base::StringValue("onAboutInfoUpdated"),
+ *value);
+}
+
void SyncInternalsMessageHandler::ForwardToJsController(
const std::string& name,
const base::ListValue* args) {
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698