| OLD | NEW |
| 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_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "components/sync/driver/sync_driver_switches.h" | 13 #include "components/sync/driver/sync_driver_switches.h" |
| 14 #include "components/sync/driver/sync_service.h" | 14 #include "components/sync/driver/sync_service.h" |
| 15 #include "components/sync/model/model_type_sync_bridge.h" | 15 #include "components/sync/model/model_type_sync_bridge.h" |
| 16 #include "components/sync/user_events/user_event_sync_bridge.h" | 16 #include "components/sync/user_events/user_event_sync_bridge.h" |
| 17 | 17 |
| 18 using sync_pb::UserEventSpecifics; | 18 using sync_pb::UserEventSpecifics; |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 | 21 |
| 22 UserEventService::UserEventService(SyncService* sync_service, | 22 UserEventServiceImpl::UserEventServiceImpl( |
| 23 std::unique_ptr<UserEventSyncBridge> bridge) | 23 SyncService* sync_service, |
| 24 std::unique_ptr<UserEventSyncBridge> bridge) |
| 24 : sync_service_(sync_service), | 25 : sync_service_(sync_service), |
| 25 bridge_(std::move(bridge)), | 26 bridge_(std::move(bridge)), |
| 26 session_id_(base::RandUint64()) { | 27 session_id_(base::RandUint64()) { |
| 27 // TODO(skym): Subscribe to events about field trial membership changing. | 28 // TODO(skym): Subscribe to events about field trial membership changing. |
| 28 } | 29 } |
| 29 | 30 |
| 30 UserEventService::~UserEventService() {} | 31 UserEventServiceImpl::~UserEventServiceImpl() {} |
| 31 | 32 |
| 32 void UserEventService::Shutdown() {} | 33 void UserEventServiceImpl::Shutdown() {} |
| 33 | 34 |
| 34 void UserEventService::RecordUserEvent( | 35 void UserEventServiceImpl::RecordUserEvent( |
| 35 std::unique_ptr<UserEventSpecifics> specifics) { | 36 std::unique_ptr<UserEventSpecifics> specifics) { |
| 36 if (CanRecordEvent(*specifics)) { | 37 if (ShouldRecordEvent(*specifics)) { |
| 37 DCHECK(!specifics->has_session_id()); | 38 DCHECK(!specifics->has_session_id()); |
| 38 specifics->set_session_id(session_id_); | 39 specifics->set_session_id(session_id_); |
| 39 bridge_->RecordUserEvent(std::move(specifics)); | 40 bridge_->RecordUserEvent(std::move(specifics)); |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 | 43 |
| 43 void UserEventService::RecordUserEvent(const UserEventSpecifics& specifics) { | 44 void UserEventServiceImpl::RecordUserEvent( |
| 45 const UserEventSpecifics& specifics) { |
| 44 RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics)); | 46 RecordUserEvent(base::MakeUnique<UserEventSpecifics>(specifics)); |
| 45 } | 47 } |
| 46 | 48 |
| 47 base::WeakPtr<ModelTypeSyncBridge> UserEventService::GetSyncBridge() { | 49 base::WeakPtr<ModelTypeSyncBridge> UserEventServiceImpl::GetSyncBridge() { |
| 48 return bridge_->AsWeakPtr(); | 50 return bridge_->AsWeakPtr(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 bool UserEventService::CanRecordEvent(const UserEventSpecifics& specifics) { | 53 bool UserEventServiceImpl::ShouldRecordEvent( |
| 54 const UserEventSpecifics& specifics) { |
| 52 // We only record events if the user is syncing history and has not enabled | 55 // 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 | 56 // a custom passphrase. The type HISTORY_DELETE_DIRECTIVES is enabled in and |
| 54 // only in this exact scenario. | 57 // only in this exact scenario. |
| 55 return base::FeatureList::IsEnabled(switches::kSyncUserEvents) && | 58 return base::FeatureList::IsEnabled(switches::kSyncUserEvents) && |
| 56 sync_service_ != nullptr && sync_service_->IsEngineInitialized() && | 59 sync_service_ != nullptr && sync_service_->IsEngineInitialized() && |
| 57 sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES); | 60 sync_service_->GetPreferredDataTypes().Has(HISTORY_DELETE_DIRECTIVES); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void RegisterDependentFieldTrial(const std::string& trial_name, | 63 void UserEventServiceImpl::RegisterDependentFieldTrial( |
| 61 UserEventSpecifics::EventCase event_case) { | 64 const std::string& trial_name, |
| 65 UserEventSpecifics::EventCase event_case) { |
| 62 // TODO(skym): Implementation. | 66 // TODO(skym): Implementation. |
| 63 } | 67 } |
| 64 | 68 |
| 65 } // namespace syncer | 69 } // namespace syncer |
| OLD | NEW |