OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/build_commit_command.h" | 5 #include "chrome/browser/sync/engine/build_commit_command.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 11 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
12 #include "chrome/browser/sync/engine/syncer_session.h" | 12 #include "chrome/browser/sync/engine/syncer_session.h" |
13 #include "chrome/browser/sync/engine/syncer_util.h" | 13 #include "chrome/browser/sync/engine/syncer_util.h" |
14 #include "chrome/browser/sync/engine/syncproto.h" | 14 #include "chrome/browser/sync/engine/syncproto.h" |
15 #include "chrome/browser/sync/syncable/syncable.h" | 15 #include "chrome/browser/sync/syncable/syncable.h" |
16 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 16 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
17 #include "chrome/browser/sync/util/character_set_converters.h" | |
18 #include "chrome/browser/sync/util/sync_types.h" | 17 #include "chrome/browser/sync/util/sync_types.h" |
19 | 18 |
20 using std::set; | 19 using std::set; |
21 using std::string; | 20 using std::string; |
22 using std::vector; | 21 using std::vector; |
23 using syncable::ExtendedAttribute; | 22 using syncable::ExtendedAttribute; |
24 using syncable::Id; | 23 using syncable::Id; |
25 using syncable::MutableEntry; | 24 using syncable::MutableEntry; |
26 using syncable::Name; | 25 using syncable::Name; |
27 | 26 |
(...skipping 11 matching lines...) Expand all Loading... |
39 sync_pb::CommitMessage_ChromiumExtensionsActivity* activity_message = | 38 sync_pb::CommitMessage_ChromiumExtensionsActivity* activity_message = |
40 message->add_extensions_activity(); | 39 message->add_extensions_activity(); |
41 activity_message->set_extension_id(it->second.extension_id); | 40 activity_message->set_extension_id(it->second.extension_id); |
42 activity_message->set_bookmark_writes_since_last_commit( | 41 activity_message->set_bookmark_writes_since_last_commit( |
43 it->second.bookmark_write_count); | 42 it->second.bookmark_write_count); |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
47 void BuildCommitCommand::ExecuteImpl(SyncerSession* session) { | 46 void BuildCommitCommand::ExecuteImpl(SyncerSession* session) { |
48 ClientToServerMessage message; | 47 ClientToServerMessage message; |
49 message.set_share(ToUTF8(session->account_name()).get_string()); | 48 message.set_share(session->account_name()); |
50 message.set_message_contents(ClientToServerMessage::COMMIT); | 49 message.set_message_contents(ClientToServerMessage::COMMIT); |
51 | 50 |
52 CommitMessage* commit_message = message.mutable_commit(); | 51 CommitMessage* commit_message = message.mutable_commit(); |
53 commit_message->set_cache_guid( | 52 commit_message->set_cache_guid( |
54 session->write_transaction()->directory()->cache_guid()); | 53 session->write_transaction()->directory()->cache_guid()); |
55 AddExtensionsActivityToMessage(session, commit_message); | 54 AddExtensionsActivityToMessage(session, commit_message); |
56 | 55 |
57 const vector<Id>& commit_ids = session->commit_ids(); | 56 const vector<Id>& commit_ids = session->commit_ids(); |
58 for (size_t i = 0; i < commit_ids.size(); i++) { | 57 for (size_t i = 0; i < commit_ids.size(); i++) { |
59 Id id = commit_ids[i]; | 58 Id id = commit_ids[i]; |
60 SyncEntity* sync_entry = | 59 SyncEntity* sync_entry = |
61 static_cast<SyncEntity*>(commit_message->add_entries()); | 60 static_cast<SyncEntity*>(commit_message->add_entries()); |
62 sync_entry->set_id(id); | 61 sync_entry->set_id(id); |
63 MutableEntry meta_entry(session->write_transaction(), | 62 MutableEntry meta_entry(session->write_transaction(), |
64 syncable::GET_BY_ID, | 63 syncable::GET_BY_ID, |
65 id); | 64 id); |
66 CHECK(meta_entry.good()); | 65 CHECK(meta_entry.good()); |
67 // This is the only change we make to the entry in this function. | 66 // This is the only change we make to the entry in this function. |
68 meta_entry.Put(syncable::SYNCING, true); | 67 meta_entry.Put(syncable::SYNCING, true); |
69 | 68 |
70 Name name = meta_entry.GetName(); | 69 Name name = meta_entry.GetName(); |
71 CHECK(!name.value().empty()); // Make sure this isn't an update. | 70 CHECK(!name.value().empty()); // Make sure this isn't an update. |
72 sync_entry->set_name(ToUTF8(name.value()).get_string()); | 71 sync_entry->set_name(name.value()); |
73 // Set the non_unique_name if we have one. If we do, the server ignores | 72 // Set the non_unique_name if we have one. If we do, the server ignores |
74 // the |name| value (using |non_unique_name| instead), and will return | 73 // the |name| value (using |non_unique_name| instead), and will return |
75 // in the CommitResponse a unique name if one is generated. Even though | 74 // in the CommitResponse a unique name if one is generated. Even though |
76 // we could get away with only sending |name|, we send both because it | 75 // we could get away with only sending |name|, we send both because it |
77 // may aid in logging. | 76 // may aid in logging. |
78 if (name.value() != name.non_unique_value()) { | 77 if (name.value() != name.non_unique_value()) { |
79 sync_entry->set_non_unique_name( | 78 sync_entry->set_non_unique_name(name.non_unique_value()); |
80 ToUTF8(name.non_unique_value()).get_string()); | |
81 } | 79 } |
82 // Deleted items with negative parent ids can be a problem so we set the | 80 // Deleted items with negative parent ids can be a problem so we set the |
83 // parent to 0. (TODO(sync): Still true in protocol?). | 81 // parent to 0. (TODO(sync): Still true in protocol?). |
84 Id new_parent_id; | 82 Id new_parent_id; |
85 if (meta_entry.Get(syncable::IS_DEL) && | 83 if (meta_entry.Get(syncable::IS_DEL) && |
86 !meta_entry.Get(syncable::PARENT_ID).ServerKnows()) { | 84 !meta_entry.Get(syncable::PARENT_ID).ServerKnows()) { |
87 new_parent_id = session->write_transaction()->root_id(); | 85 new_parent_id = session->write_transaction()->root_id(); |
88 } else { | 86 } else { |
89 new_parent_id = meta_entry.Get(syncable::PARENT_ID); | 87 new_parent_id = meta_entry.Get(syncable::PARENT_ID); |
90 } | 88 } |
(...skipping 28 matching lines...) Expand all Loading... |
119 set<ExtendedAttribute> extended_attributes; | 117 set<ExtendedAttribute> extended_attributes; |
120 meta_entry.GetAllExtendedAttributes( | 118 meta_entry.GetAllExtendedAttributes( |
121 session->write_transaction(), &extended_attributes); | 119 session->write_transaction(), &extended_attributes); |
122 set<ExtendedAttribute>::iterator iter; | 120 set<ExtendedAttribute>::iterator iter; |
123 sync_pb::ExtendedAttributes* mutable_extended_attributes = | 121 sync_pb::ExtendedAttributes* mutable_extended_attributes = |
124 sync_entry->mutable_extended_attributes(); | 122 sync_entry->mutable_extended_attributes(); |
125 for (iter = extended_attributes.begin(); iter != extended_attributes.end(); | 123 for (iter = extended_attributes.begin(); iter != extended_attributes.end(); |
126 ++iter) { | 124 ++iter) { |
127 sync_pb::ExtendedAttributes_ExtendedAttribute *extended_attribute = | 125 sync_pb::ExtendedAttributes_ExtendedAttribute *extended_attribute = |
128 mutable_extended_attributes->add_extendedattribute(); | 126 mutable_extended_attributes->add_extendedattribute(); |
129 extended_attribute->set_key(ToUTF8(iter->key()).get_string()); | 127 extended_attribute->set_key(iter->key()); |
130 SyncerProtoUtil::CopyBlobIntoProtoBytes(iter->value(), | 128 SyncerProtoUtil::CopyBlobIntoProtoBytes(iter->value(), |
131 extended_attribute->mutable_value()); | 129 extended_attribute->mutable_value()); |
132 } | 130 } |
133 | 131 |
134 // Deletion is final on the server, let's move things and then delete them. | 132 // Deletion is final on the server, let's move things and then delete them. |
135 if (meta_entry.Get(syncable::IS_DEL)) { | 133 if (meta_entry.Get(syncable::IS_DEL)) { |
136 sync_entry->set_deleted(true); | 134 sync_entry->set_deleted(true); |
137 } else if (meta_entry.Get(syncable::IS_BOOKMARK_OBJECT)) { | 135 } else if (meta_entry.Get(syncable::IS_BOOKMARK_OBJECT)) { |
138 sync_pb::SyncEntity_BookmarkData* bookmark = | 136 sync_pb::SyncEntity_BookmarkData* bookmark = |
139 sync_entry->mutable_bookmarkdata(); | 137 sync_entry->mutable_bookmarkdata(); |
140 bookmark->set_bookmark_folder(meta_entry.Get(syncable::IS_DIR)); | 138 bookmark->set_bookmark_folder(meta_entry.Get(syncable::IS_DIR)); |
141 const Id& prev_id = meta_entry.Get(syncable::PREV_ID); | 139 const Id& prev_id = meta_entry.Get(syncable::PREV_ID); |
142 string prev_string = prev_id.IsRoot() ? string() : prev_id.GetServerId(); | 140 string prev_string = prev_id.IsRoot() ? string() : prev_id.GetServerId(); |
143 sync_entry->set_insert_after_item_id(prev_string); | 141 sync_entry->set_insert_after_item_id(prev_string); |
144 | 142 |
145 if (!meta_entry.Get(syncable::IS_DIR)) { | 143 if (!meta_entry.Get(syncable::IS_DIR)) { |
146 string bookmark_url = ToUTF8(meta_entry.Get(syncable::BOOKMARK_URL)); | 144 string bookmark_url = meta_entry.Get(syncable::BOOKMARK_URL); |
147 bookmark->set_bookmark_url(bookmark_url); | 145 bookmark->set_bookmark_url(bookmark_url); |
148 SyncerProtoUtil::CopyBlobIntoProtoBytes( | 146 SyncerProtoUtil::CopyBlobIntoProtoBytes( |
149 meta_entry.Get(syncable::BOOKMARK_FAVICON), | 147 meta_entry.Get(syncable::BOOKMARK_FAVICON), |
150 bookmark->mutable_bookmark_favicon()); | 148 bookmark->mutable_bookmark_favicon()); |
151 } | 149 } |
152 } | 150 } |
153 } | 151 } |
154 session->set_commit_message(message); | 152 session->set_commit_message(message); |
155 } | 153 } |
156 | 154 |
157 } // namespace browser_sync | 155 } // namespace browser_sync |
OLD | NEW |