| 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 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ |
| 6 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class ServerConnectionManager; | 35 class ServerConnectionManager; |
| 36 class SyncEntity; | 36 class SyncEntity; |
| 37 class CommitResponse_EntryResponse; | 37 class CommitResponse_EntryResponse; |
| 38 | 38 |
| 39 class SyncerProtoUtil { | 39 class SyncerProtoUtil { |
| 40 public: | 40 public: |
| 41 // Posts the given message and fills the buffer with the returned value. | 41 // Posts the given message and fills the buffer with the returned value. |
| 42 // Returns true on success. Also handles store birthday verification: | 42 // Returns true on success. Also handles store birthday verification: |
| 43 // session->status()->syncer_stuck_ is set true if the birthday is | 43 // session->status()->syncer_stuck_ is set true if the birthday is |
| 44 // incorrect. A false value will always be returned if birthday is bad. | 44 // incorrect. A false value will always be returned if birthday is bad. |
| 45 static bool PostClientToServerMessage(ClientToServerMessage* msg, | 45 static bool PostClientToServerMessage( |
| 46 const ClientToServerMessage& msg, |
| 46 sync_pb::ClientToServerResponse* response, | 47 sync_pb::ClientToServerResponse* response, |
| 47 sessions::SyncSession* session); | 48 sessions::SyncSession* session); |
| 48 | 49 |
| 49 // Compares a syncable Entry to SyncEntity, returns true iff the data is | 50 // Compares a syncable Entry to SyncEntity, returns true iff the data is |
| 50 // identical. | 51 // identical. |
| 51 // | 52 // |
| 52 // TODO(sync): The places where this function is used are arguable big causes | 53 // TODO(sync): The places where this function is used are arguable big causes |
| 53 // of the fragility, because there's a tendency to freak out the moment the | 54 // of the fragility, because there's a tendency to freak out the moment the |
| 54 // local and server values diverge. However, this almost always indicates a | 55 // local and server values diverge. However, this almost always indicates a |
| 55 // sync bug somewhere earlier in the sync cycle. | 56 // sync bug somewhere earlier in the sync cycle. |
| 56 static bool Compare(const syncable::Entry& local_entry, | 57 static bool Compare(const syncable::Entry& local_entry, |
| 57 const SyncEntity& server_entry); | 58 const SyncEntity& server_entry); |
| 58 | 59 |
| 59 // Utility methods for converting between syncable::Blobs and protobuf byte | 60 // Utility methods for converting between syncable::Blobs and protobuf byte |
| 60 // fields. | 61 // fields. |
| 61 static void CopyProtoBytesIntoBlob(const std::string& proto_bytes, | 62 static void CopyProtoBytesIntoBlob(const std::string& proto_bytes, |
| 62 syncable::Blob* blob); | 63 syncable::Blob* blob); |
| 63 static bool ProtoBytesEqualsBlob(const std::string& proto_bytes, | 64 static bool ProtoBytesEqualsBlob(const std::string& proto_bytes, |
| 64 const syncable::Blob& blob); | 65 const syncable::Blob& blob); |
| 65 static void CopyBlobIntoProtoBytes(const syncable::Blob& blob, | 66 static void CopyBlobIntoProtoBytes(const syncable::Blob& blob, |
| 66 std::string* proto_bytes); | 67 std::string* proto_bytes); |
| 67 | 68 |
| 68 // Extract the name field from a sync entity. | 69 // Extract the name field from a sync entity. |
| 69 static const std::string& NameFromSyncEntity(const SyncEntity& entry); | 70 static const std::string& NameFromSyncEntity( |
| 70 | 71 const sync_pb::SyncEntity& entry); |
| 71 | 72 |
| 72 // Extract the name field from a commit entry response. | 73 // Extract the name field from a commit entry response. |
| 73 static const std::string& NameFromCommitEntryResponse( | 74 static const std::string& NameFromCommitEntryResponse( |
| 74 const CommitResponse_EntryResponse& entry); | 75 const CommitResponse_EntryResponse& entry); |
| 75 | 76 |
| 76 // EntitySpecifics is used as a filter for the GetUpdates message to tell | 77 // EntitySpecifics is used as a filter for the GetUpdates message to tell |
| 77 // the server which datatypes to send back. This adds a datatype so that | 78 // the server which datatypes to send back. This adds a datatype so that |
| 78 // it's included in the filter. | 79 // it's included in the filter. |
| 79 static void AddToEntitySpecificDatatypesFilter(syncable::ModelType datatype, | 80 static void AddToEntitySpecificDatatypesFilter(syncable::ModelType datatype, |
| 80 sync_pb::EntitySpecifics* filter); | 81 sync_pb::EntitySpecifics* filter); |
| 81 | 82 |
| 82 // Get a debug string representation of the client to server response. | 83 // Get a debug string representation of the client to server response. |
| 83 static std::string ClientToServerResponseDebugString( | 84 static std::string ClientToServerResponseDebugString( |
| 84 const sync_pb::ClientToServerResponse& response); | 85 const sync_pb::ClientToServerResponse& response); |
| 85 | 86 |
| 86 // Get update contents as a string. Intended for logging, and intended | 87 // Get update contents as a string. Intended for logging, and intended |
| 87 // to have a smaller footprint than the protobuf's built-in pretty printer. | 88 // to have a smaller footprint than the protobuf's built-in pretty printer. |
| 88 static std::string SyncEntityDebugString(const sync_pb::SyncEntity& entry); | 89 static std::string SyncEntityDebugString(const sync_pb::SyncEntity& entry); |
| 89 | 90 |
| 91 // Pull the birthday from the dir and put it into the msg. |
| 92 static void AddRequestBirthday(syncable::Directory* dir, |
| 93 ClientToServerMessage* msg); |
| 94 |
| 90 private: | 95 private: |
| 91 SyncerProtoUtil() {} | 96 SyncerProtoUtil() {} |
| 92 | 97 |
| 93 // Helper functions for PostClientToServerMessage. | 98 // Helper functions for PostClientToServerMessage. |
| 94 | 99 |
| 95 // Verifies the store birthday, alerting/resetting as appropriate if there's a | 100 // Verifies the store birthday, alerting/resetting as appropriate if there's a |
| 96 // mismatch. Return false if the syncer should be stuck. | 101 // mismatch. Return false if the syncer should be stuck. |
| 97 static bool VerifyResponseBirthday(syncable::Directory* dir, | 102 static bool VerifyResponseBirthday(syncable::Directory* dir, |
| 98 const sync_pb::ClientToServerResponse* response); | 103 const sync_pb::ClientToServerResponse* response); |
| 99 | 104 |
| 100 // Pull the birthday from the dir and put it into the msg. | |
| 101 static void AddRequestBirthday(syncable::Directory* dir, | |
| 102 ClientToServerMessage* msg); | |
| 103 | |
| 104 // Post the message using the scm, and do some processing on the returned | 105 // Post the message using the scm, and do some processing on the returned |
| 105 // headers. Decode the server response. | 106 // headers. Decode the server response. |
| 106 static bool PostAndProcessHeaders(browser_sync::ServerConnectionManager* scm, | 107 static bool PostAndProcessHeaders(browser_sync::ServerConnectionManager* scm, |
| 107 browser_sync::AuthWatcher* authwatcher, | 108 browser_sync::AuthWatcher* authwatcher, |
| 108 ClientToServerMessage* msg, | 109 const ClientToServerMessage& msg, |
| 109 sync_pb::ClientToServerResponse* response); | 110 sync_pb::ClientToServerResponse* response); |
| 110 | 111 |
| 111 friend class SyncerProtoUtilTest; | 112 friend class SyncerProtoUtilTest; |
| 112 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, AddRequestBirthday); | 113 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, AddRequestBirthday); |
| 113 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, PostAndProcessHeaders); | 114 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, PostAndProcessHeaders); |
| 114 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, VerifyResponseBirthday); | 115 FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, VerifyResponseBirthday); |
| 115 | 116 |
| 116 DISALLOW_COPY_AND_ASSIGN(SyncerProtoUtil); | 117 DISALLOW_COPY_AND_ASSIGN(SyncerProtoUtil); |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 } // namespace browser_sync | 120 } // namespace browser_sync |
| 120 | 121 |
| 121 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ | 122 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_PROTO_UTIL_H_ |
| OLD | NEW |