| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/sync/engine/syncer_proto_util.h" | 5 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/sync/engine/auth_watcher.h" | 9 #include "chrome/browser/sync/engine/auth_watcher.h" |
| 10 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 10 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, | 112 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, |
| 113 ClientToServerMessage* msg) { | 113 ClientToServerMessage* msg) { |
| 114 if (!dir->store_birthday().empty()) { | 114 if (!dir->store_birthday().empty()) { |
| 115 msg->set_store_birthday(dir->store_birthday()); | 115 msg->set_store_birthday(dir->store_birthday()); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 // static | 119 // static |
| 120 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, | 120 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, |
| 121 AuthWatcher* auth_watcher, | 121 AuthWatcher* auth_watcher, |
| 122 ClientToServerMessage* msg, | 122 const ClientToServerMessage& msg, |
| 123 ClientToServerResponse* response) { | 123 ClientToServerResponse* response) { |
| 124 | 124 |
| 125 std::string tx, rx; | 125 std::string tx, rx; |
| 126 msg->SerializeToString(&tx); | 126 msg.SerializeToString(&tx); |
| 127 | 127 |
| 128 HttpResponse http_response; | 128 HttpResponse http_response; |
| 129 ServerConnectionManager::PostBufferParams params = { | 129 ServerConnectionManager::PostBufferParams params = { |
| 130 tx, &rx, &http_response | 130 tx, &rx, &http_response |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 ScopedServerStatusWatcher server_status_watcher(scm, &http_response); | 133 ScopedServerStatusWatcher server_status_watcher(scm, &http_response); |
| 134 if (!scm->PostBufferWithCachedAuth(¶ms, &server_status_watcher)) { | 134 if (!scm->PostBufferWithCachedAuth(¶ms, &server_status_watcher)) { |
| 135 LOG(WARNING) << "Error posting from syncer:" << http_response; | 135 LOG(WARNING) << "Error posting from syncer:" << http_response; |
| 136 return false; | 136 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 158 default: | 158 default: |
| 159 return true; | 159 return true; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 // static | 167 // static |
| 168 bool SyncerProtoUtil::PostClientToServerMessage(ClientToServerMessage* msg, | 168 bool SyncerProtoUtil::PostClientToServerMessage( |
| 169 ClientToServerResponse* response, SyncSession* session) { | 169 const ClientToServerMessage& msg, |
| 170 ClientToServerResponse* response, |
| 171 SyncSession* session) { |
| 170 | 172 |
| 171 CHECK(response); | 173 CHECK(response); |
| 174 DCHECK(msg.has_store_birthday() || (msg.has_get_updates() && |
| 175 msg.get_updates().has_from_timestamp() && |
| 176 msg.get_updates().from_timestamp() == 0)) |
| 177 << "Must call AddRequestBirthday to set birthday."; |
| 172 | 178 |
| 173 ScopedDirLookup dir(session->context()->directory_manager(), | 179 ScopedDirLookup dir(session->context()->directory_manager(), |
| 174 session->context()->account_name()); | 180 session->context()->account_name()); |
| 175 if (!dir.good()) { | 181 if (!dir.good()) { |
| 176 return false; | 182 return false; |
| 177 } | 183 } |
| 178 | 184 |
| 179 AddRequestBirthday(dir, msg); | |
| 180 | |
| 181 if (!PostAndProcessHeaders(session->context()->connection_manager(), | 185 if (!PostAndProcessHeaders(session->context()->connection_manager(), |
| 182 session->context()->auth_watcher(), | 186 session->context()->auth_watcher(), |
| 183 msg, | 187 msg, |
| 184 response)) { | 188 response)) { |
| 185 return false; | 189 return false; |
| 186 } | 190 } |
| 187 | 191 |
| 188 if (!VerifyResponseBirthday(dir, response)) { | 192 if (!VerifyResponseBirthday(dir, response)) { |
| 189 // TODO(ncarter): Add a unit test for the case where the syncer becomes | 193 // TODO(ncarter): Add a unit test for the case where the syncer becomes |
| 190 // stuck due to a bad birthday. | 194 // stuck due to a bad birthday. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 284 |
| 281 // static | 285 // static |
| 282 void SyncerProtoUtil::CopyBlobIntoProtoBytes(const syncable::Blob& blob, | 286 void SyncerProtoUtil::CopyBlobIntoProtoBytes(const syncable::Blob& blob, |
| 283 std::string* proto_bytes) { | 287 std::string* proto_bytes) { |
| 284 std::string blob_string(blob.begin(), blob.end()); | 288 std::string blob_string(blob.begin(), blob.end()); |
| 285 proto_bytes->swap(blob_string); | 289 proto_bytes->swap(blob_string); |
| 286 } | 290 } |
| 287 | 291 |
| 288 // static | 292 // static |
| 289 const std::string& SyncerProtoUtil::NameFromSyncEntity( | 293 const std::string& SyncerProtoUtil::NameFromSyncEntity( |
| 290 const SyncEntity& entry) { | 294 const sync_pb::SyncEntity& entry) { |
| 291 | 295 |
| 292 if (entry.has_non_unique_name()) { | 296 if (entry.has_non_unique_name()) { |
| 293 return entry.non_unique_name(); | 297 return entry.non_unique_name(); |
| 294 } | 298 } |
| 295 | 299 |
| 296 return entry.name(); | 300 return entry.name(); |
| 297 } | 301 } |
| 298 | 302 |
| 299 // static | 303 // static |
| 300 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( | 304 const std::string& SyncerProtoUtil::NameFromCommitEntryResponse( |
| 301 const CommitResponse_EntryResponse& entry) { | 305 const CommitResponse_EntryResponse& entry) { |
| 302 | 306 |
| 303 if (entry.has_non_unique_name()) { | 307 if (entry.has_non_unique_name()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 const sync_pb::ClientToServerResponse& response) { | 345 const sync_pb::ClientToServerResponse& response) { |
| 342 // Add more handlers as needed. | 346 // Add more handlers as needed. |
| 343 std::string output; | 347 std::string output; |
| 344 if (response.has_get_updates()) { | 348 if (response.has_get_updates()) { |
| 345 output.append(GetUpdatesResponseString(response.get_updates())); | 349 output.append(GetUpdatesResponseString(response.get_updates())); |
| 346 } | 350 } |
| 347 return output; | 351 return output; |
| 348 } | 352 } |
| 349 | 353 |
| 350 } // namespace browser_sync | 354 } // namespace browser_sync |
| OLD | NEW |