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

Side by Side Diff: components/invalidation/public/ack_handle.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/invalidation/public/ack_handle.h" 5 #include "components/invalidation/public/ack_handle.h"
6 6
7 #include <cstddef> 7 #include <stddef.h>
8 #include <stdint.h>
9
8 #include "base/rand_util.h" 10 #include "base/rand_util.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 13
12 namespace syncer { 14 namespace syncer {
13 15
14 namespace { 16 namespace {
15 // Hopefully enough bytes for uniqueness. 17 // Hopefully enough bytes for uniqueness.
16 const size_t kBytesInHandle = 16; 18 const size_t kBytesInHandle = 16;
17 } // namespace 19 } // namespace
18 20
19 AckHandle AckHandle::CreateUnique() { 21 AckHandle AckHandle::CreateUnique() {
20 // This isn't a valid UUID, so we don't attempt to format it like one. 22 // This isn't a valid UUID, so we don't attempt to format it like one.
21 uint8 random_bytes[kBytesInHandle]; 23 uint8_t random_bytes[kBytesInHandle];
22 base::RandBytes(random_bytes, sizeof(random_bytes)); 24 base::RandBytes(random_bytes, sizeof(random_bytes));
23 return AckHandle(base::HexEncode(random_bytes, sizeof(random_bytes)), 25 return AckHandle(base::HexEncode(random_bytes, sizeof(random_bytes)),
24 base::Time::Now()); 26 base::Time::Now());
25 } 27 }
26 28
27 AckHandle AckHandle::InvalidAckHandle() { 29 AckHandle AckHandle::InvalidAckHandle() {
28 return AckHandle(std::string(), base::Time()); 30 return AckHandle(std::string(), base::Time());
29 } 31 }
30 32
31 bool AckHandle::Equals(const AckHandle& other) const { 33 bool AckHandle::Equals(const AckHandle& other) const {
32 return state_ == other.state_ && timestamp_ == other.timestamp_; 34 return state_ == other.state_ && timestamp_ == other.timestamp_;
33 } 35 }
34 36
35 scoped_ptr<base::DictionaryValue> AckHandle::ToValue() const { 37 scoped_ptr<base::DictionaryValue> AckHandle::ToValue() const {
36 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 38 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
37 value->SetString("state", state_); 39 value->SetString("state", state_);
38 value->SetString("timestamp", 40 value->SetString("timestamp",
39 base::Int64ToString(timestamp_.ToInternalValue())); 41 base::Int64ToString(timestamp_.ToInternalValue()));
40 return value.Pass(); 42 return value.Pass();
41 } 43 }
42 44
43 bool AckHandle::ResetFromValue(const base::DictionaryValue& value) { 45 bool AckHandle::ResetFromValue(const base::DictionaryValue& value) {
44 if (!value.GetString("state", &state_)) 46 if (!value.GetString("state", &state_))
45 return false; 47 return false;
46 std::string timestamp_as_string; 48 std::string timestamp_as_string;
47 if (!value.GetString("timestamp", &timestamp_as_string)) 49 if (!value.GetString("timestamp", &timestamp_as_string))
48 return false; 50 return false;
49 int64 timestamp_value; 51 int64_t timestamp_value;
50 if (!base::StringToInt64(timestamp_as_string, &timestamp_value)) 52 if (!base::StringToInt64(timestamp_as_string, &timestamp_value))
51 return false; 53 return false;
52 timestamp_ = base::Time::FromInternalValue(timestamp_value); 54 timestamp_ = base::Time::FromInternalValue(timestamp_value);
53 return true; 55 return true;
54 } 56 }
55 57
56 bool AckHandle::IsValid() const { 58 bool AckHandle::IsValid() const {
57 return !state_.empty(); 59 return !state_.empty();
58 } 60 }
59 61
60 AckHandle::AckHandle(const std::string& state, base::Time timestamp) 62 AckHandle::AckHandle(const std::string& state, base::Time timestamp)
61 : state_(state), timestamp_(timestamp) { 63 : state_(state), timestamp_(timestamp) {
62 } 64 }
63 65
64 AckHandle::~AckHandle() { 66 AckHandle::~AckHandle() {
65 } 67 }
66 68
67 } // namespace syncer 69 } // namespace syncer
OLDNEW
« no previous file with comments | « components/invalidation/public/ack_handle.h ('k') | components/invalidation/public/invalidation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698