| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 #ifndef COMPONENTS_SYNC_DRIVER_DEVICE_INFO_UTIL_H_ | |
| 6 #define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_UTIL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/time/time.h" | |
| 11 | |
| 12 namespace sync_pb { | |
| 13 class DeviceInfoSpecifics; | |
| 14 } | |
| 15 | |
| 16 namespace sync_driver { | |
| 17 | |
| 18 // This class contains constants and static helper functions that are shared | |
| 19 // between DeviceInfoSyncService and DeviceInfoService. | |
| 20 class DeviceInfoUtil { | |
| 21 public: | |
| 22 // The prefix to be appended before the cache guid when creating tags. This is | |
| 23 // needed for backwards compatiblity with all old clients because we need to | |
| 24 // ensure everyone uses the same logic to generate the tag, so that everyone | |
| 25 // can independently hash the tag to the same value. | |
| 26 static const char kClientTagPrefix[]; | |
| 27 | |
| 28 // The delay between periodic updates to the entry corresponding to this | |
| 29 // device. | |
| 30 static const base::TimeDelta kPulseInterval; | |
| 31 | |
| 32 // The amount of time a device can go without an updates before we consider it | |
| 33 // stale/inactive, and start ignoring it for active device counts. | |
| 34 static const base::TimeDelta kActiveThreshold; | |
| 35 | |
| 36 // Determines the amount of time to wait before pulsing something with the | |
| 37 // given |last_update| timestamp. This uses the current time from |now| along | |
| 38 // with |kDeviceInfoPulseInterval|, and will never return a negative delay. | |
| 39 // The smallest delay this function will return, even for something extremely | |
| 40 // old will be a delay of 0 time units. | |
| 41 static base::TimeDelta CalculatePulseDelay(const base::Time last_update, | |
| 42 const base::Time now); | |
| 43 | |
| 44 // Determines if the given |last_update| timestamp should be considerend | |
| 45 // active based on |kStaleDeviceInfoThreshold|, given the current time. | |
| 46 static bool IsActive(const base::Time last_update, const base::Time now); | |
| 47 | |
| 48 // Formats ClientTag from DeviceInfoSpecifics. | |
| 49 static std::string SpecificsToTag( | |
| 50 const sync_pb::DeviceInfoSpecifics& specifics); | |
| 51 | |
| 52 // Extracts cache_guid from ClientTag. | |
| 53 static std::string TagToCacheGuid(const std::string& tag); | |
| 54 }; | |
| 55 | |
| 56 } // namespace sync_driver | |
| 57 | |
| 58 #endif // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_UTIL_H_ | |
| OLD | NEW |