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

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

Issue 2872023002: [Sync] Add a simple UI to sync-internals to create UserEvents. (Closed)
Patch Set: Rebase Created 3 years, 7 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
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 3a68db41789f4ca9e129e3fed8c5468fd2d34065..5979034d19cda2d3c647cf2f241f45841a2e9a7b 100644
--- a/chrome/browser/ui/webui/sync_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/sync_internals_message_handler.cc
@@ -9,20 +9,26 @@
#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/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"
@@ -35,6 +41,21 @@ using syncer::ModelTypeSet;
using syncer::SyncService;
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;
+}
+
+} // namespace
+
SyncInternalsMessageHandler::SyncInternalsMessageHandler()
: SyncInternalsMessageHandler(
base::BindRepeating(
@@ -87,6 +108,17 @@ void SyncInternalsMessageHandler::RegisterMessages() {
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)));
+
+ web_ui()->RegisterMessageCallback(
syncer::sync_ui_util::kGetAllNodes,
base::Bind(&SyncInternalsMessageHandler::HandleGetAllNodes,
base::Unretained(this)));
@@ -172,6 +204,31 @@ void SyncInternalsMessageHandler::HandleGetAllNodes(const ListValue* args) {
}
}
+void SyncInternalsMessageHandler::HandleRequestUserEventsVisibility(
+ const base::ListValue* args) {
+ DCHECK(args->empty());
+ AllowJavascript();
+ CallJavascriptFunction(
+ syncer::sync_ui_util::kUserEventsVisibilityCallback,
+ Value(base::FeatureList::IsEnabled(switches::kSyncUserEvents)));
+}
+
+void SyncInternalsMessageHandler::HandleWriteUserEvent(
+ const base::ListValue* args) {
+ DCHECK_EQ(2U, args->GetSize());
+ AllowJavascript();
+
+ 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<ListValue> nodes) {

Powered by Google App Engine
This is Rietveld 408576698