Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: components/sync/engine_impl/directory_commit_contribution.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "sync/engine/directory_commit_contribution.h" 5 #include "components/sync/engine_impl/directory_commit_contribution.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <set> 11 #include <set>
12 12
13 #include "sync/engine/commit_util.h" 13 #include "components/sync/engine_impl/commit_util.h"
14 #include "sync/engine/get_commit_ids.h" 14 #include "components/sync/engine_impl/get_commit_ids.h"
15 #include "sync/engine/syncer_util.h" 15 #include "components/sync/engine_impl/syncer_util.h"
16 #include "sync/internal_api/public/sessions/commit_counters.h" 16 #include "components/sync/sessions/commit_counters.h"
17 #include "sync/syncable/model_neutral_mutable_entry.h" 17 #include "components/sync/syncable/model_neutral_mutable_entry.h"
18 #include "sync/syncable/syncable_model_neutral_write_transaction.h" 18 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h"
19 19
20 namespace syncer { 20 namespace syncer {
21 21
22 using syncable::GET_BY_HANDLE; 22 using syncable::GET_BY_HANDLE;
23 using syncable::SYNCER; 23 using syncable::SYNCER;
24 24
25 DirectoryCommitContribution::~DirectoryCommitContribution() { 25 DirectoryCommitContribution::~DirectoryCommitContribution() {
26 DCHECK(!syncing_bits_set_); 26 DCHECK(!syncing_bits_set_);
27 } 27 }
28 28
(...skipping 28 matching lines...) Expand all
57 return std::unique_ptr<DirectoryCommitContribution>( 57 return std::unique_ptr<DirectoryCommitContribution>(
58 new DirectoryCommitContribution(metahandles, entities, context, dir, 58 new DirectoryCommitContribution(metahandles, entities, context, dir,
59 debug_info_emitter)); 59 debug_info_emitter));
60 } 60 }
61 61
62 void DirectoryCommitContribution::AddToCommitMessage( 62 void DirectoryCommitContribution::AddToCommitMessage(
63 sync_pb::ClientToServerMessage* msg) { 63 sync_pb::ClientToServerMessage* msg) {
64 DCHECK(syncing_bits_set_); 64 DCHECK(syncing_bits_set_);
65 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); 65 sync_pb::CommitMessage* commit_message = msg->mutable_commit();
66 entries_start_index_ = commit_message->entries_size(); 66 entries_start_index_ = commit_message->entries_size();
67 std::copy(entities_.begin(), 67 std::copy(entities_.begin(), entities_.end(),
68 entities_.end(),
69 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); 68 RepeatedPtrFieldBackInserter(commit_message->mutable_entries()));
70 if (!context_.context().empty()) 69 if (!context_.context().empty())
71 commit_message->add_client_contexts()->Swap(&context_); 70 commit_message->add_client_contexts()->Swap(&context_);
72 71
73 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters(); 72 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters();
74 counters->num_commits_attempted += entities_.size(); 73 counters->num_commits_attempted += entities_.size();
75 } 74 }
76 75
77 SyncerError DirectoryCommitContribution::ProcessCommitResponse( 76 SyncerError DirectoryCommitContribution::ProcessCommitResponse(
78 const sync_pb::ClientToServerResponse& response, 77 const sync_pb::ClientToServerResponse& response,
79 sessions::StatusController* status) { 78 sessions::StatusController* status) {
80 DCHECK(syncing_bits_set_); 79 DCHECK(syncing_bits_set_);
81 const sync_pb::CommitResponse& commit_response = response.commit(); 80 const sync_pb::CommitResponse& commit_response = response.commit();
82 81
83 int transient_error_commits = 0; 82 int transient_error_commits = 0;
84 int conflicting_commits = 0; 83 int conflicting_commits = 0;
85 int error_commits = 0; 84 int error_commits = 0;
86 int successes = 0; 85 int successes = 0;
87 86
88 std::set<syncable::Id> deleted_folders; 87 std::set<syncable::Id> deleted_folders;
89 { 88 {
90 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); 89 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_);
91 for (size_t i = 0; i < metahandles_.size(); ++i) { 90 for (size_t i = 0; i < metahandles_.size(); ++i) {
92 sync_pb::CommitResponse::ResponseType response_type = 91 sync_pb::CommitResponse::ResponseType response_type =
93 commit_util::ProcessSingleCommitResponse( 92 commit_util::ProcessSingleCommitResponse(
94 &trans, 93 &trans, commit_response.entryresponse(entries_start_index_ + i),
95 commit_response.entryresponse(entries_start_index_ + i), 94 entities_.Get(i), metahandles_[i], &deleted_folders);
96 entities_.Get(i),
97 metahandles_[i],
98 &deleted_folders);
99 switch (response_type) { 95 switch (response_type) {
100 case sync_pb::CommitResponse::INVALID_MESSAGE: 96 case sync_pb::CommitResponse::INVALID_MESSAGE:
101 ++error_commits; 97 ++error_commits;
102 break; 98 break;
103 case sync_pb::CommitResponse::CONFLICT: 99 case sync_pb::CommitResponse::CONFLICT:
104 ++conflicting_commits; 100 ++conflicting_commits;
105 status->increment_num_server_conflicts(); 101 status->increment_num_server_conflicts();
106 break; 102 break;
107 case sync_pb::CommitResponse::SUCCESS: 103 case sync_pb::CommitResponse::SUCCESS:
108 ++successes; 104 ++successes;
109 { 105 {
110 syncable::Entry e(&trans, GET_BY_HANDLE, metahandles_[i]); 106 syncable::Entry e(&trans, GET_BY_HANDLE, metahandles_[i]);
111 if (e.GetModelType() == BOOKMARKS) 107 if (e.GetModelType() == BOOKMARKS)
112 status->increment_num_successful_bookmark_commits(); 108 status->increment_num_successful_bookmark_commits();
113 } 109 }
114 status->increment_num_successful_commits(); 110 status->increment_num_successful_commits();
115 break; 111 break;
116 case sync_pb::CommitResponse::OVER_QUOTA: 112 case sync_pb::CommitResponse::OVER_QUOTA:
117 // We handle over quota like a retry, which is same as transient. 113 // We handle over quota like a retry, which is same as transient.
118 case sync_pb::CommitResponse::RETRY: 114 case sync_pb::CommitResponse::RETRY:
119 case sync_pb::CommitResponse::TRANSIENT_ERROR: 115 case sync_pb::CommitResponse::TRANSIENT_ERROR:
120 ++transient_error_commits; 116 ++transient_error_commits;
121 break; 117 break;
122 default: 118 default:
123 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; 119 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse";
124 } 120 }
125 } 121 }
126 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders); 122 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders);
127 } 123 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // complete but the Cleanup method is called anyways. It appears these are 186 // complete but the Cleanup method is called anyways. It appears these are
191 // unset on the assumption that the sync cycle must have finished properly, 187 // unset on the assumption that the sync cycle must have finished properly,
192 // although that's actually up to the commit response handling logic. 188 // although that's actually up to the commit response handling logic.
193 entry.PutDirtySync(false); 189 entry.PutDirtySync(false);
194 entry.PutSyncing(false); 190 entry.PutSyncing(false);
195 } 191 }
196 syncing_bits_set_ = false; 192 syncing_bits_set_ = false;
197 } 193 }
198 194
199 } // namespace syncer 195 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698