Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 UserEventService::UserEventService(SyncService* sync_service, | |
| 22 std::unique_ptr<UserEventSyncBridge> bridge) | |
| 23 : sync_service_(sync_service), | |
| 24 bridge_(std::move(bridge)), | |
| 25 session_id_(base::RandUint64()) {} | |
| 26 | |
| 27 UserEventService::~UserEventService() {} | |
| 28 | |
| 29 void UserEventService::Shutdown() {} | |
| 30 | |
| 31 void UserEventService::RecordUserEvent( | |
| 32 std::unique_ptr<UserEventSpecifics> specifics) { | |
| 33 if (CanRecordEvent(*specifics)) { | |
| 34 DCHECK(!specifics->has_session_id()); | |
| 35 specifics->set_session_id(session_id_); | |
| 36 bridge_->RecordUserEvent(std::move(specifics)); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 void UserEventService::RecordUserEvent(const UserEventSpecifics& specifics) { | |
| 41 RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics)); | |
| 42 } | |
| 43 | |
| 44 base::WeakPtr<ModelTypeSyncBridge> UserEventService::GetSyncBridge() { | |
| 45 return bridge_->AsWeakPtr(); | |
| 46 } | |
| 47 | |
| 48 bool UserEventService::CanRecordEvent(const UserEventSpecifics& specifics) { | |
| 49 return sync_service_ != nullptr && sync_service_->IsEngineInitialized() && | |
| 50 sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES); | |
|
Patrick Noland
2017/05/08 22:42:37
Can you make HISTORY_DELETE_DIRECTIVES a constant
skym
2017/05/08 23:35:27
How about a comment right here? It already is a co
Patrick Noland
2017/05/08 23:41:29
That's fine, as long as you give context for its s
| |
| 51 } | |
| 52 | |
| 53 } // namespace syncer | |
| OLD | NEW |