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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/sync/user_events/user_event_service.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/rand_util.h"
12 #include "components/sync/driver/sync_service.h"
13 #include "components/sync/model/model_type_sync_bridge.h"
14 #include "components/sync/protocol/sync.pb.h"
15 #include "components/sync/user_events/user_event_sync_bridge.h"
16
17 using sync_pb::UserEventSpecifics;
18
19 namespace syncer {
20
21 namespace {} // namespace
22
23 UserEventService::UserEventService(SyncService* sync_service,
24 std::unique_ptr<UserEventSyncBridge> bridge)
25 : sync_service_(sync_service),
26 bridge_(std::move(bridge)),
27 session_id_(base::RandUint64()) {}
28
29 UserEventService::~UserEventService() {}
30
31 void UserEventService::Shutdown() {}
32
33 void UserEventService::RecordUserEvent(
34 std::unique_ptr<UserEventSpecifics> specifics) {
35 if (CanRecordEvent(*specifics)) {
36 DCHECK(!specifics->has_session_id());
37 specifics->set_session_id(session_id_);
38 bridge_->RecordUserEvent(std::move(specifics));
39 }
40 }
41
42 void UserEventService::RecordUserEvent(const UserEventSpecifics& specifics) {
43 RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics));
44 }
45
46 base::WeakPtr<ModelTypeSyncBridge> UserEventService::GetSyncBridge() {
47 return bridge_->AsWeakPtr();
48 }
49
50 bool UserEventService::CanRecordEvent(const UserEventSpecifics& specifics) {
51 // We only record events if the user is syncing history and has not enabled
52 // a custom passphrase. The type HISTORY_DELETE_DIRECTIVES is enabled in and
53 // only in this exact scenario.
54 return sync_service_ != nullptr && sync_service_->IsEngineInitialized() &&
55 sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES);
56 }
57
58 } // namespace syncer
OLDNEW
« 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