Skip to content

Commit

Permalink
Switch to standard integer types in rlz/.
Browse files Browse the repository at this point in the history
BUG=138542
TBR=thakis@chromium.org

Review URL: https://codereview.chromium.org/1547683004

Cr-Commit-Position: refs/heads/master@{#366614}
  • Loading branch information
avi authored and Commit bot committed Dec 22, 2015
1 parent 3984dea commit d41cf18
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 51 deletions.
4 changes: 2 additions & 2 deletions rlz/chromeos/lib/rlz_value_store_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ bool RlzValueStoreChromeOS::HasAccess(AccessType type) {
return type == kReadAccess || !read_only_;
}

bool RlzValueStoreChromeOS::WritePingTime(Product product, int64 time) {
bool RlzValueStoreChromeOS::WritePingTime(Product product, int64_t time) {
DCHECK(CalledOnValidThread());
rlz_store_->SetString(GetKeyName(kPingTimeKey, product),
base::Int64ToString(time));
return true;
}

bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64* time) {
bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64_t* time) {
DCHECK(CalledOnValidThread());
std::string ping_time;
return rlz_store_->GetString(GetKeyName(kPingTimeKey, product), &ping_time) &&
Expand Down
8 changes: 6 additions & 2 deletions rlz/chromeos/lib/rlz_value_store_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#ifndef RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
#define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_

#include <stddef.h>
#include <stdint.h>

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/threading/non_thread_safe.h"
#include "base/values.h"
#include "rlz/lib/rlz_value_store.h"
Expand Down Expand Up @@ -33,8 +37,8 @@ class RlzValueStoreChromeOS : public RlzValueStore,
// RlzValueStore overrides:
bool HasAccess(AccessType type) override;

bool WritePingTime(Product product, int64 time) override;
bool ReadPingTime(Product product, int64* time) override;
bool WritePingTime(Product product, int64_t time) override;
bool ReadPingTime(Product product, int64_t* time) override;
bool ClearPingTime(Product product) override;

bool WriteAccessPointRlz(AccessPoint access_point,
Expand Down
2 changes: 2 additions & 0 deletions rlz/lib/crc8_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// Uniitest for data encryption functions.

#include <stddef.h>

#include "base/logging.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down
17 changes: 10 additions & 7 deletions rlz/lib/financial_ping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

#include "rlz/lib/financial_ping.h"

#include <stdint.h>

#include "base/atomicops.h"
#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/machine_id.h"
Expand Down Expand Up @@ -64,7 +67,7 @@ namespace {
// Returns the time relative to a fixed point in the past in multiples of
// 100 ns stepts. The point in the past is arbitrary but can't change, as the
// result of this value is stored on disk.
int64 GetSystemTimeAsInt64() {
int64_t GetSystemTimeAsInt64() {
#if defined(OS_WIN)
FILETIME now_as_file_time;
// Relative to Jan 1, 1601 (UTC).
Expand All @@ -77,7 +80,7 @@ int64 GetSystemTimeAsInt64() {
#else
// Seconds since epoch (Jan 1, 1970).
double now_seconds = base::Time::Now().ToDoubleT();
return static_cast<int64>(now_seconds * 1000 * 1000 * 10);
return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10);
#endif
}

Expand Down Expand Up @@ -354,12 +357,12 @@ bool FinancialPing::IsPingTime(Product product, bool no_delay) {
if (!store || !store->HasAccess(RlzValueStore::kReadAccess))
return false;

int64 last_ping = 0;
int64_t last_ping = 0;
if (!store->ReadPingTime(product, &last_ping))
return true;

uint64 now = GetSystemTimeAsInt64();
int64 interval = now - last_ping;
uint64_t now = GetSystemTimeAsInt64();
int64_t interval = now - last_ping;

// If interval is negative, clock was probably reset. So ping.
if (interval < 0)
Expand All @@ -382,7 +385,7 @@ bool FinancialPing::UpdateLastPingTime(Product product) {
if (!store || !store->HasAccess(RlzValueStore::kWriteAccess))
return false;

uint64 now = GetSystemTimeAsInt64();
uint64_t now = GetSystemTimeAsInt64();
return store->WritePingTime(product, now);
}

Expand Down
26 changes: 14 additions & 12 deletions rlz/lib/financial_ping_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

#include "rlz/lib/financial_ping.h"

#include "base/basictypes.h"
#include <stdint.h>

#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/machine_id.h"
#include "rlz/lib/rlz_lib.h"
Expand All @@ -38,7 +41,7 @@
namespace {

// Must match the implementation in file_time.cc.
int64 GetSystemTimeAsInt64() {
int64_t GetSystemTimeAsInt64() {
#if defined(OS_WIN)
FILETIME now_as_file_time;
GetSystemTimeAsFileTime(&now_as_file_time);
Expand All @@ -48,12 +51,12 @@ int64 GetSystemTimeAsInt64() {
return integer.QuadPart;
#else
double now_seconds = base::Time::Now().ToDoubleT();
return static_cast<int64>(now_seconds * 1000 * 1000 * 10);
return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10);
#endif
}

// Ping times in 100-nanosecond intervals.
const int64 k1MinuteInterval = 60LL * 10000000LL; // 1 minute
const int64_t k1MinuteInterval = 60LL * 10000000LL; // 1 minute

} // namespace anonymous

Expand Down Expand Up @@ -178,8 +181,7 @@ TEST_F(FinancialPingTest, FormRequestBadBrand) {
EXPECT_EQ(rlz_lib::SupplementaryBranding::GetBrand().empty(), ok);
}


static void SetLastPingTime(int64 time, rlz_lib::Product product) {
static void SetLastPingTime(int64_t time, rlz_lib::Product product) {
rlz_lib::ScopedRlzValueStoreLock lock;
rlz_lib::RlzValueStore* store = lock.GetStore();
ASSERT_TRUE(store);
Expand All @@ -188,8 +190,8 @@ static void SetLastPingTime(int64 time, rlz_lib::Product product) {
}

TEST_F(FinancialPingTest, IsPingTime) {
int64 now = GetSystemTimeAsInt64();
int64 last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
int64_t now = GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);

// No events, last ping just over a day ago.
Expand Down Expand Up @@ -240,8 +242,8 @@ TEST_F(FinancialPingTest, BrandingIsPingTime) {
if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
return;

int64 now = GetSystemTimeAsInt64();
int64 last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
int64_t now = GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);

// Has events, last ping just over a day ago.
Expand Down Expand Up @@ -275,8 +277,8 @@ TEST_F(FinancialPingTest, BrandingIsPingTime) {
}

TEST_F(FinancialPingTest, ClearLastPingTime) {
int64 now = GetSystemTimeAsInt64();
int64 last_ping = now - rlz_lib::kEventsPingInterval + k1MinuteInterval;
int64_t now = GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval + k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);

// Has events, last ping just under a day ago.
Expand Down
4 changes: 2 additions & 2 deletions rlz/lib/lib_values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const char kFinancialServer[] = "clients1.google.com";
const int kFinancialPort = 80;

// Ping times in 100-nanosecond intervals.
const int64 kEventsPingInterval = 24LL * 3600LL * 10000000LL; // 1 day
const int64 kNoEventsPingInterval = kEventsPingInterval * 7LL; // 1 week
const int64_t kEventsPingInterval = 24LL * 3600LL * 10000000LL; // 1 day
const int64_t kNoEventsPingInterval = kEventsPingInterval * 7LL; // 1 week

const char kFinancialPingUserAgent[] = "Mozilla/4.0 (compatible; Win32)";
const char* kFinancialPingResponseObjects[] = { "text/*", NULL };
Expand Down
7 changes: 4 additions & 3 deletions rlz/lib/lib_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#ifndef RLZ_LIB_LIB_VALUES_H_
#define RLZ_LIB_LIB_VALUES_H_

#include "base/basictypes.h"
#include <stdint.h>

#include "rlz/lib/rlz_enums.h"

namespace rlz_lib {
Expand Down Expand Up @@ -75,8 +76,8 @@ extern const char kFinancialServer[];

extern const int kFinancialPort;

extern const int64 kEventsPingInterval;
extern const int64 kNoEventsPingInterval;
extern const int64_t kEventsPingInterval;
extern const int64_t kNoEventsPingInterval;

extern const char kFinancialPingUserAgent[];
extern const char* kFinancialPingResponseObjects[];
Expand Down
2 changes: 2 additions & 0 deletions rlz/lib/machine_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "rlz/lib/machine_id.h"

#include <stddef.h>

#include "base/sha1.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/crc8.h"
Expand Down
2 changes: 2 additions & 0 deletions rlz/lib/rlz_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#include <algorithm>

#include "base/macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/crc32.h"
#include "rlz/lib/financial_ping.h"
Expand Down
1 change: 1 addition & 0 deletions rlz/lib/rlz_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef RLZ_LIB_RLZ_LIB_H_
#define RLZ_LIB_RLZ_LIB_H_

#include <stddef.h>
#include <stdio.h>
#include <string>

Expand Down
5 changes: 4 additions & 1 deletion rlz/lib/rlz_lib_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// The "GGLA" brand is used to test the normal code flow of the code, and the
// "TEST" brand is used to test the supplementary brand code code flow.

#include "base/posix/eintr_wrapper.h"
#include <stddef.h>

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/posix/eintr_wrapper.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down
16 changes: 9 additions & 7 deletions rlz/lib/rlz_value_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
#ifndef RLZ_VALUE_STORE_H_
#define RLZ_VALUE_STORE_H_

#include "base/basictypes.h"
#include <stddef.h>
#include <stdint.h>

#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "rlz/lib/rlz_enums.h"

#if defined(OS_WIN)
Expand All @@ -17,10 +23,6 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#endif


#include <string>
#include <vector>

namespace base {
class FilePath;
}
Expand All @@ -37,8 +39,8 @@ class RlzValueStore {
virtual bool HasAccess(AccessType type) = 0;

// Ping times.
virtual bool WritePingTime(Product product, int64 time) = 0;
virtual bool ReadPingTime(Product product, int64* time) = 0;
virtual bool WritePingTime(Product product, int64_t time) = 0;
virtual bool ReadPingTime(Product product, int64_t* time) = 0;
virtual bool ClearPingTime(Product product) = 0;

// Access point RLZs.
Expand Down
4 changes: 3 additions & 1 deletion rlz/lib/string_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

#include "rlz/lib/string_utils.h"

#include "base/basictypes.h"
#include <stddef.h>

#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "rlz/lib/assert.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down
2 changes: 2 additions & 0 deletions rlz/mac/lib/machine_id_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <IOKit/network/IONetworkInterface.h>
#include <stddef.h>
#include <stdint.h>

#include "base/logging.h"
#include "base/mac/foundation_util.h"
Expand Down
8 changes: 6 additions & 2 deletions rlz/mac/lib/rlz_value_store_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#ifndef RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_
#define RLZ_MAC_LIB_RLZ_VALUE_STORE_MAC_H_

#include <stddef.h>
#include <stdint.h>

#include "base/compiler_specific.h"
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "rlz/lib/rlz_value_store.h"

@class NSDictionary;
Expand All @@ -20,8 +24,8 @@ class RlzValueStoreMac : public RlzValueStore {
public:
bool HasAccess(AccessType type) override;

bool WritePingTime(Product product, int64 time) override;
bool ReadPingTime(Product product, int64* time) override;
bool WritePingTime(Product product, int64_t time) override;
bool ReadPingTime(Product product, int64_t* time) override;
bool ClearPingTime(Product product) override;

bool WriteAccessPointRlz(AccessPoint access_point,
Expand Down
4 changes: 2 additions & 2 deletions rlz/mac/lib/rlz_value_store_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
}
}

bool RlzValueStoreMac::WritePingTime(Product product, int64 time) {
bool RlzValueStoreMac::WritePingTime(Product product, int64_t time) {
NSNumber* n = [NSNumber numberWithLongLong:time];
[ProductDict(product) setObject:n forKey:kPingTimeKey];
return true;
}

bool RlzValueStoreMac::ReadPingTime(Product product, int64* time) {
bool RlzValueStoreMac::ReadPingTime(Product product, int64_t* time) {
if (NSNumber* n =
ObjCCast<NSNumber>([ProductDict(product) objectForKey:kPingTimeKey])) {
*time = [n longLongValue];
Expand Down
8 changes: 6 additions & 2 deletions rlz/test/rlz_test_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include "rlz_test_helpers.h"

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <vector>

#include "base/strings/string16.h"
#include "build/build_config.h"
#include "rlz/lib/rlz_lib.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -35,7 +39,7 @@ const wchar_t kHKLMAccessProviders[] =
struct RegistryValue {
base::string16 name;
DWORD type;
std::vector<uint8> data;
std::vector<uint8_t> data;
};

struct RegistryKeyData {
Expand All @@ -52,7 +56,7 @@ void ReadRegistryTree(const base::win::RegKey& src, RegistryKeyData* data) {
for (; i.Valid(); ++i) {
RegistryValue& value = *data->values.insert(data->values.end(),
RegistryValue());
const uint8* data = reinterpret_cast<const uint8*>(i.Value());
const uint8_t* data = reinterpret_cast<const uint8_t*>(i.Value());
value.name.assign(i.Name());
value.type = i.Type();
value.data.assign(data, data + i.ValueSize());
Expand Down
Loading

0 comments on commit d41cf18

Please sign in to comment.