OLD | NEW |
---|---|
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/invalidation.h" | 5 #include "components/invalidation/invalidation.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/bind.h" | |
9 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
11 #include "base/location.h" | |
10 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "base/values.h" | 14 #include "base/values.h" |
13 #include "components/invalidation/ack_handler.h" | 15 #include "components/invalidation/ack_handler.h" |
14 #include "components/invalidation/invalidation_util.h" | 16 #include "components/invalidation/invalidation_util.h" |
15 | 17 |
16 namespace syncer { | 18 namespace syncer { |
17 | 19 |
18 namespace { | 20 namespace { |
19 const char kObjectIdKey[] = "objectId"; | 21 const char kObjectIdKey[] = "objectId"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 104 |
103 const std::string& Invalidation::payload() const { | 105 const std::string& Invalidation::payload() const { |
104 DCHECK(!is_unknown_version_); | 106 DCHECK(!is_unknown_version_); |
105 return payload_; | 107 return payload_; |
106 } | 108 } |
107 | 109 |
108 const AckHandle& Invalidation::ack_handle() const { | 110 const AckHandle& Invalidation::ack_handle() const { |
109 return ack_handle_; | 111 return ack_handle_; |
110 } | 112 } |
111 | 113 |
112 void Invalidation::set_ack_handler(syncer::WeakHandle<AckHandler> handler) { | 114 void Invalidation::SetAckHandler( |
115 base::WeakPtr<AckHandler> handler, | |
116 scoped_refptr<base::SequencedTaskRunner> handler_task_runner) { | |
113 ack_handler_ = handler; | 117 ack_handler_ = handler; |
118 ack_handler_task_runner_ = handler_task_runner; | |
114 } | 119 } |
115 | 120 |
116 bool Invalidation::SupportsAcknowledgement() const { | 121 bool Invalidation::SupportsAcknowledgement() const { |
117 return ack_handler_.IsInitialized(); | 122 return !!ack_handler_task_runner_; |
pavely
2014/08/08 20:08:30
I think previous code will return false if ack_han
rlarocque
2014/08/08 21:19:35
This version is actually more correct. SupportsAc
| |
118 } | 123 } |
119 | 124 |
120 void Invalidation::Acknowledge() const { | 125 void Invalidation::Acknowledge() const { |
121 if (SupportsAcknowledgement()) { | 126 if (SupportsAcknowledgement()) { |
122 ack_handler_.Call(FROM_HERE, &AckHandler::Acknowledge, id_, ack_handle_); | 127 ack_handler_task_runner_->PostTask( |
128 FROM_HERE, | |
129 base::Bind(&AckHandler::Acknowledge, ack_handler_, id_, ack_handle_)); | |
123 } | 130 } |
124 } | 131 } |
125 | 132 |
126 void Invalidation::Drop() { | 133 void Invalidation::Drop() { |
127 if (SupportsAcknowledgement()) { | 134 if (SupportsAcknowledgement()) { |
128 ack_handler_.Call(FROM_HERE, &AckHandler::Drop, id_, ack_handle_); | 135 ack_handler_task_runner_->PostTask( |
136 FROM_HERE, | |
137 base::Bind(&AckHandler::Drop, ack_handler_, id_, ack_handle_)); | |
129 } | 138 } |
130 } | 139 } |
131 | 140 |
132 bool Invalidation::Equals(const Invalidation& other) const { | 141 bool Invalidation::Equals(const Invalidation& other) const { |
133 return id_ == other.id_ && is_unknown_version_ == other.is_unknown_version_ && | 142 return id_ == other.id_ && is_unknown_version_ == other.is_unknown_version_ && |
134 version_ == other.version_ && payload_ == other.payload_; | 143 version_ == other.version_ && payload_ == other.payload_; |
135 } | 144 } |
136 | 145 |
137 scoped_ptr<base::DictionaryValue> Invalidation::ToValue() const { | 146 scoped_ptr<base::DictionaryValue> Invalidation::ToValue() const { |
138 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 147 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
(...skipping 22 matching lines...) Expand all Loading... | |
161 const std::string& payload, | 170 const std::string& payload, |
162 AckHandle ack_handle) | 171 AckHandle ack_handle) |
163 : id_(id), | 172 : id_(id), |
164 is_unknown_version_(is_unknown_version), | 173 is_unknown_version_(is_unknown_version), |
165 version_(version), | 174 version_(version), |
166 payload_(payload), | 175 payload_(payload), |
167 ack_handle_(ack_handle) { | 176 ack_handle_(ack_handle) { |
168 } | 177 } |
169 | 178 |
170 } // namespace syncer | 179 } // namespace syncer |
OLD | NEW |