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 eab283ce9c0900b839ff0dc880bc56ffa0c1c0f0..276dcf9b7bb8526e4db5eefa8a831e71547fe05a 100644 |
--- a/chrome/browser/ui/webui/sync_internals_message_handler.cc |
+++ b/chrome/browser/ui/webui/sync_internals_message_handler.cc |
@@ -4,33 +4,55 @@ |
#include "chrome/browser/ui/webui/sync_internals_message_handler.h" |
+#include <stdint.h> |
+ |
#include <utility> |
#include <vector> |
+#include "base/feature_list.h" |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
+#include "base/strings/string_number_conversions.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
+#include "chrome/browser/sync/user_event_service_factory.h" |
#include "chrome/common/channel_info.h" |
#include "components/browser_sync/profile_sync_service.h" |
#include "components/signin/core/browser/signin_manager_base.h" |
#include "components/sync/base/weak_handle.h" |
#include "components/sync/driver/about_sync_util.h" |
+#include "components/sync/driver/sync_driver_switches.h" |
#include "components/sync/driver/sync_service.h" |
#include "components/sync/engine/cycle/commit_counters.h" |
#include "components/sync/engine/cycle/status_counters.h" |
#include "components/sync/engine/cycle/update_counters.h" |
#include "components/sync/engine/events/protocol_event.h" |
#include "components/sync/js/js_event_details.h" |
+#include "components/sync/protocol/sync.pb.h" |
+#include "components/sync/user_events/user_event_service.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_ui.h" |
+using base::Value; |
using browser_sync::ProfileSyncService; |
using syncer::JsEventDetails; |
using syncer::ModelTypeSet; |
using syncer::WeakHandle; |
namespace { |
+ |
+// Converts the string at |index| in |list| to an int, defaulting to 0 on error. |
+int64_t StringAtIndexToInt64(const base::ListValue* list, int index) { |
+ std::string str; |
+ if (list->GetString(index, &str)) { |
+ int64_t integer = 0; |
+ if (base::StringToInt64(str, &integer)) { |
+ return integer; |
+ } |
+ } |
+ return 0; |
+} |
+ |
class UtilAboutSyncDataExtractor : public AboutSyncDataExtractor { |
public: |
std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( |
@@ -40,6 +62,7 @@ class UtilAboutSyncDataExtractor : public AboutSyncDataExtractor { |
service, signin, chrome::GetChannel()); |
} |
}; |
+ |
} // namespace |
SyncInternalsMessageHandler::SyncInternalsMessageHandler() |
@@ -93,6 +116,17 @@ void SyncInternalsMessageHandler::RegisterMessages() { |
syncer::sync_ui_util::kGetAllNodes, |
base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes, |
base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ syncer::sync_ui_util::kRequestUserEventsVisibility, |
+ base::Bind( |
+ &SyncInternalsMessageHandler::HandleRequestUserEventsVisibility, |
+ base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ syncer::sync_ui_util::kWriteUserEvent, |
+ base::Bind(&SyncInternalsMessageHandler::HandleWriteUserEvent, |
+ base::Unretained(this))); |
} |
void SyncInternalsMessageHandler::HandleRegisterForEvents( |
@@ -147,7 +181,7 @@ void SyncInternalsMessageHandler::HandleRequestListOfTypes( |
event_details.Set(syncer::sync_ui_util::kTypes, type_list.release()); |
web_ui()->CallJavascriptFunctionUnsafe( |
syncer::sync_ui_util::kDispatchEvent, |
- base::Value(syncer::sync_ui_util::kOnReceivedListOfTypes), event_details); |
+ Value(syncer::sync_ui_util::kOnReceivedListOfTypes), event_details); |
} |
void SyncInternalsMessageHandler::HandleGetAllNodes( |
@@ -165,10 +199,33 @@ void SyncInternalsMessageHandler::HandleGetAllNodes( |
} |
} |
+void SyncInternalsMessageHandler::HandleRequestUserEventsVisibility( |
+ const base::ListValue* args) { |
+ DCHECK(args->empty()); |
+ web_ui()->CallJavascriptFunctionUnsafe( |
Dan Beam
2017/05/16 03:35:51
can we use the safe version instead?
skym
2017/05/16 19:26:49
Done. And switched all the other invocations in th
|
+ syncer::sync_ui_util::kUserEventsVisibilityCallback, |
+ Value(base::FeatureList::IsEnabled(switches::kSyncUserEvents))); |
+} |
+ |
+void SyncInternalsMessageHandler::HandleWriteUserEvent( |
+ const base::ListValue* args) { |
+ DCHECK_EQ(2U, args->GetSize()); |
+ |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ syncer::UserEventService* user_event_service = |
+ browser_sync::UserEventServiceFactory::GetForProfile( |
+ profile->GetOriginalProfile()); |
+ |
+ sync_pb::UserEventSpecifics event_specifics; |
+ event_specifics.set_event_time_usec(StringAtIndexToInt64(args, 0)); |
+ event_specifics.set_navigation_id(StringAtIndexToInt64(args, 1)); |
+ user_event_service->RecordUserEvent(event_specifics); |
+} |
+ |
void SyncInternalsMessageHandler::OnReceivedAllNodes( |
int request_id, |
std::unique_ptr<base::ListValue> nodes) { |
- base::Value id(request_id); |
+ Value id(request_id); |
web_ui()->CallJavascriptFunctionUnsafe( |
syncer::sync_ui_util::kGetAllNodesCallback, id, *nodes); |
} |
@@ -183,7 +240,7 @@ void SyncInternalsMessageHandler::OnProtocolEvent( |
syncer::ProtocolEvent::ToValue(event)); |
web_ui()->CallJavascriptFunctionUnsafe( |
syncer::sync_ui_util::kDispatchEvent, |
- base::Value(syncer::sync_ui_util::kOnProtocolEvent), *value); |
+ Value(syncer::sync_ui_util::kOnProtocolEvent), *value); |
} |
void SyncInternalsMessageHandler::OnCommitCountersUpdated( |
@@ -214,7 +271,7 @@ void SyncInternalsMessageHandler::EmitCounterUpdate( |
details->Set(syncer::sync_ui_util::kCounters, value.release()); |
web_ui()->CallJavascriptFunctionUnsafe( |
syncer::sync_ui_util::kDispatchEvent, |
- base::Value(syncer::sync_ui_util::kOnCountersUpdated), *details); |
+ Value(syncer::sync_ui_util::kOnCountersUpdated), *details); |
} |
void SyncInternalsMessageHandler::HandleJsEvent( |
@@ -223,7 +280,7 @@ void SyncInternalsMessageHandler::HandleJsEvent( |
DVLOG(1) << "Handling event: " << name |
<< " with details " << details.ToString(); |
web_ui()->CallJavascriptFunctionUnsafe(syncer::sync_ui_util::kDispatchEvent, |
- base::Value(name), details.Get()); |
+ Value(name), details.Get()); |
} |
void SyncInternalsMessageHandler::SendAboutInfo() { |
@@ -234,7 +291,7 @@ void SyncInternalsMessageHandler::SendAboutInfo() { |
signin); |
web_ui()->CallJavascriptFunctionUnsafe( |
syncer::sync_ui_util::kDispatchEvent, |
- base::Value(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); |
+ Value(syncer::sync_ui_util::kOnAboutInfoUpdated), *value); |
} |
// Gets the ProfileSyncService of the underlying original profile. |