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

Unified Diff: components/sync/user_events/user_event_service.cc

Issue 2864973002: [Sync] Create UserEventService. (Closed)
Patch Set: Updates for Patrick. 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: components/sync/user_events/user_event_service.cc
diff --git a/components/sync/user_events/user_event_service.cc b/components/sync/user_events/user_event_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac403790078bba75542117c3bd577af1205ebf6d
--- /dev/null
+++ b/components/sync/user_events/user_event_service.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 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 "components/sync/user_events/user_event_service.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "base/rand_util.h"
+#include "components/sync/driver/sync_service.h"
+#include "components/sync/model/model_type_sync_bridge.h"
+#include "components/sync/protocol/sync.pb.h"
+#include "components/sync/user_events/user_event_sync_bridge.h"
+
+using sync_pb::UserEventSpecifics;
+
+namespace syncer {
+
+namespace {} // namespace
+
+UserEventService::UserEventService(SyncService* sync_service,
+ std::unique_ptr<UserEventSyncBridge> bridge)
+ : sync_service_(sync_service),
+ bridge_(std::move(bridge)),
+ session_id_(base::RandUint64()) {}
+
+UserEventService::~UserEventService() {}
+
+void UserEventService::Shutdown() {}
+
+void UserEventService::RecordUserEvent(
+ std::unique_ptr<UserEventSpecifics> specifics) {
+ if (CanRecordEvent(*specifics)) {
+ DCHECK(!specifics->has_session_id());
+ specifics->set_session_id(session_id_);
+ bridge_->RecordUserEvent(std::move(specifics));
+ }
+}
+
+void UserEventService::RecordUserEvent(const UserEventSpecifics& specifics) {
+ RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics));
+}
+
+base::WeakPtr<ModelTypeSyncBridge> UserEventService::GetSyncBridge() {
+ return bridge_->AsWeakPtr();
+}
+
+bool UserEventService::CanRecordEvent(const UserEventSpecifics& specifics) {
+ // We only record events if the user is syncing history and has not enabled
+ // a custom passphrase. The type HISTORY_DELETE_DIRECTIVES is enabled in and
+ // only in this exact scenario.
+ return sync_service_ != nullptr && sync_service_->IsEngineInitialized() &&
+ sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES);
+}
+
+} // namespace syncer
« no previous file with comments | « components/sync/user_events/user_event_service.h ('k') | components/sync/user_events/user_event_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698