OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "sync/engine/commit.h" | 5 #include "sync/engine/commit.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "sync/engine/commit_util.h" | 8 #include "sync/engine/commit_util.h" |
9 #include "sync/engine/sync_directory_commit_contribution.h" | 9 #include "sync/engine/sync_directory_commit_contribution.h" |
10 #include "sync/engine/syncer.h" | 10 #include "sync/engine/syncer.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 extensions_activity_buffer_(extensions_activity_buffer), | 23 extensions_activity_buffer_(extensions_activity_buffer), |
24 cleaned_up_(false) { | 24 cleaned_up_(false) { |
25 } | 25 } |
26 | 26 |
27 Commit::~Commit() { | 27 Commit::~Commit() { |
28 DCHECK(cleaned_up_); | 28 DCHECK(cleaned_up_); |
29 } | 29 } |
30 | 30 |
31 Commit* Commit::Init( | 31 Commit* Commit::Init( |
32 ModelTypeSet requested_types, | 32 ModelTypeSet requested_types, |
| 33 ModelTypeSet enabled_types, |
33 size_t max_entries, | 34 size_t max_entries, |
34 const std::string& account_name, | 35 const std::string& account_name, |
35 const std::string& cache_guid, | 36 const std::string& cache_guid, |
36 CommitContributorMap* contributor_map, | 37 CommitterList* committer_list, |
37 ExtensionsActivity* extensions_activity) { | 38 ExtensionsActivity* extensions_activity) { |
38 // Gather per-type contributions. | 39 // Gather per-type contributions. |
39 ContributionMap contributions; | 40 ContributionMap contributions; |
40 size_t num_entries = 0; | 41 committer_list->GatherCommitContributions( |
41 for (ModelTypeSet::Iterator it = requested_types.First(); | 42 requested_types, |
42 it.Good(); it.Inc()) { | 43 max_entries, |
43 CommitContributorMap::iterator cm_it = contributor_map->find(it.Get()); | 44 &contributions); |
44 if (cm_it == contributor_map->end()) { | |
45 NOTREACHED() | |
46 << "Could not find requested type " << ModelTypeToString(it.Get()) | |
47 << " in contributor map."; | |
48 continue; | |
49 } | |
50 size_t spaces_remaining = max_entries - num_entries; | |
51 SyncDirectoryCommitContribution* contribution = | |
52 cm_it->second->GetContribution(spaces_remaining); | |
53 if (contribution) { | |
54 num_entries += contribution->GetNumEntries(); | |
55 contributions.insert(std::make_pair(it.Get(), contribution)); | |
56 } | |
57 if (num_entries == max_entries) { | |
58 break; // No point in continuting to iterate in this case. | |
59 } | |
60 } | |
61 | 45 |
62 // Give up if no one had anything to commit. | 46 // Give up if no one had anything to commit. |
63 if (contributions.empty()) | 47 if (contributions.empty()) |
64 return NULL; | 48 return NULL; |
65 | 49 |
66 sync_pb::ClientToServerMessage message; | 50 sync_pb::ClientToServerMessage message; |
67 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); | 51 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); |
68 message.set_share(account_name); | 52 message.set_share(account_name); |
69 | 53 |
70 sync_pb::CommitMessage* commit_message = message.mutable_commit(); | 54 sync_pb::CommitMessage* commit_message = message.mutable_commit(); |
71 commit_message->set_cache_guid(cache_guid); | 55 commit_message->set_cache_guid(cache_guid); |
72 | 56 |
73 // Set extensions activity if bookmark commits are present. | 57 // Set extensions activity if bookmark commits are present. |
74 ExtensionsActivity::Records extensions_activity_buffer; | 58 ExtensionsActivity::Records extensions_activity_buffer; |
75 ContributionMap::iterator it = contributions.find(syncer::BOOKMARKS); | 59 ContributionMap::iterator it = contributions.find(syncer::BOOKMARKS); |
76 if (it != contributions.end() && it->second->GetNumEntries() != 0) { | 60 if (it != contributions.end() && it->second->GetNumEntries() != 0) { |
77 commit_util::AddExtensionsActivityToMessage( | 61 commit_util::AddExtensionsActivityToMessage( |
78 extensions_activity, | 62 extensions_activity, |
79 &extensions_activity_buffer, | 63 &extensions_activity_buffer, |
80 commit_message); | 64 commit_message); |
81 } | 65 } |
82 | 66 |
83 // Set the client config params. | 67 // Set the client config params. |
84 ModelTypeSet enabled_types; | 68 commit_util::AddClientConfigParamsToMessage( |
85 for (CommitContributorMap::iterator it = contributor_map->begin(); | 69 enabled_types, |
86 it != contributor_map->end(); ++it) { | 70 commit_message); |
87 enabled_types.Put(it->first); | |
88 } | |
89 commit_util::AddClientConfigParamsToMessage(enabled_types, | |
90 commit_message); | |
91 | 71 |
92 // Finally, serialize all our contributions. | 72 // Finally, serialize all our contributions. |
93 for (std::map<ModelType, SyncDirectoryCommitContribution*>::iterator it = | 73 for (std::map<ModelType, SyncDirectoryCommitContribution*>::iterator it = |
94 contributions.begin(); it != contributions.end(); ++it) { | 74 contributions.begin(); it != contributions.end(); ++it) { |
95 it->second->AddToCommitMessage(&message); | 75 it->second->AddToCommitMessage(&message); |
96 } | 76 } |
97 | 77 |
98 // If we made it this far, then we've successfully prepared a commit message. | 78 // If we made it this far, then we've successfully prepared a commit message. |
99 return new Commit(contributions, message, extensions_activity_buffer); | 79 return new Commit(contributions, message, extensions_activity_buffer); |
100 } | 80 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 151 |
172 void Commit::CleanUp() { | 152 void Commit::CleanUp() { |
173 for (ContributionMap::iterator it = contributions_.begin(); | 153 for (ContributionMap::iterator it = contributions_.begin(); |
174 it != contributions_.end(); ++it) { | 154 it != contributions_.end(); ++it) { |
175 it->second->CleanUp(); | 155 it->second->CleanUp(); |
176 } | 156 } |
177 cleaned_up_ = true; | 157 cleaned_up_ = true; |
178 } | 158 } |
179 | 159 |
180 } // namespace syncer | 160 } // namespace syncer |
OLD | NEW |