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

Side by Side Diff: components/sync/user_events/user_event_service.cc

Issue 2909283003: [Sync] Split UserEventService into interface and impl, add fake impl, add unit tests. (Closed)
Patch Set: Added a NoOp service to handle OffTheRecord. Created 3 years, 6 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/user_events/user_event_service.h" 5 #include "components/sync/user_events/user_event_service.h"
6 6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/feature_list.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/rand_util.h"
13 #include "components/sync/driver/sync_driver_switches.h"
14 #include "components/sync/driver/sync_service.h"
15 #include "components/sync/model/model_type_sync_bridge.h"
16 #include "components/sync/user_events/user_event_sync_bridge.h"
17
18 using sync_pb::UserEventSpecifics;
19
20 namespace syncer { 7 namespace syncer {
21 8
22 UserEventService::UserEventService(SyncService* sync_service, 9 UserEventService::UserEventService() {}
23 std::unique_ptr<UserEventSyncBridge> bridge)
24 : sync_service_(sync_service),
25 bridge_(std::move(bridge)),
26 session_id_(base::RandUint64()) {
27 // TODO(skym): Subscribe to events about field trial membership changing.
28 }
29 10
30 UserEventService::~UserEventService() {} 11 UserEventService::~UserEventService() {}
31 12
32 void UserEventService::Shutdown() {}
33
34 void UserEventService::RecordUserEvent(
35 std::unique_ptr<UserEventSpecifics> specifics) {
36 if (CanRecordEvent(*specifics)) {
37 DCHECK(!specifics->has_session_id());
38 specifics->set_session_id(session_id_);
39 bridge_->RecordUserEvent(std::move(specifics));
40 }
41 }
42
43 void UserEventService::RecordUserEvent(const UserEventSpecifics& specifics) {
44 RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics));
45 }
46
47 base::WeakPtr<ModelTypeSyncBridge> UserEventService::GetSyncBridge() {
48 return bridge_->AsWeakPtr();
49 }
50
51 bool UserEventService::CanRecordEvent(const UserEventSpecifics& specifics) {
52 // We only record events if the user is syncing history and has not enabled
53 // a custom passphrase. The type HISTORY_DELETE_DIRECTIVES is enabled in and
54 // only in this exact scenario.
55 return base::FeatureList::IsEnabled(switches::kSyncUserEvents) &&
56 sync_service_ != nullptr && sync_service_->IsEngineInitialized() &&
57 sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES);
58 }
59
60 void RegisterDependentFieldTrial(const std::string& trial_name,
61 UserEventSpecifics::EventCase event_case) {
62 // TODO(skym): Implementation.
63 }
64
65 } // namespace syncer 13 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/user_events/user_event_service.h ('k') | components/sync/user_events/user_event_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698