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

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

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 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 "components/sync/engine_impl/non_blocking_type_commit_contribution.h" 5 #include "components/sync/engine_impl/non_blocking_type_commit_contribution.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/sync/core/non_blocking_sync_common.h" 10 #include "components/sync/core/non_blocking_sync_common.h"
11 #include "components/sync/engine_impl/model_type_worker.h" 11 #include "components/sync/engine_impl/model_type_worker.h"
12 #include "components/sync/protocol/proto_value_conversions.h" 12 #include "components/sync/protocol/proto_value_conversions.h"
13 13
14 namespace syncer { 14 namespace syncer_v2 {
15 15
16 NonBlockingTypeCommitContribution::NonBlockingTypeCommitContribution( 16 NonBlockingTypeCommitContribution::NonBlockingTypeCommitContribution(
17 const sync_pb::DataTypeContext& context, 17 const sync_pb::DataTypeContext& context,
18 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, 18 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities,
19 ModelTypeWorker* worker) 19 ModelTypeWorker* worker)
20 : worker_(worker), 20 : worker_(worker),
21 context_(context), 21 context_(context),
22 entities_(entities), 22 entities_(entities),
23 cleaned_up_(false) {} 23 cleaned_up_(false) {}
24 24
25 NonBlockingTypeCommitContribution::~NonBlockingTypeCommitContribution() { 25 NonBlockingTypeCommitContribution::~NonBlockingTypeCommitContribution() {
26 DCHECK(cleaned_up_); 26 DCHECK(cleaned_up_);
27 } 27 }
28 28
29 void NonBlockingTypeCommitContribution::AddToCommitMessage( 29 void NonBlockingTypeCommitContribution::AddToCommitMessage(
30 sync_pb::ClientToServerMessage* msg) { 30 sync_pb::ClientToServerMessage* msg) {
31 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); 31 sync_pb::CommitMessage* commit_message = msg->mutable_commit();
32 entries_start_index_ = commit_message->entries_size(); 32 entries_start_index_ = commit_message->entries_size();
33 33
34 std::copy(entities_.begin(), entities_.end(), 34 std::copy(entities_.begin(), entities_.end(),
35 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); 35 RepeatedPtrFieldBackInserter(commit_message->mutable_entries()));
36 if (!context_.context().empty()) 36 if (!context_.context().empty())
37 commit_message->add_client_contexts()->CopyFrom(context_); 37 commit_message->add_client_contexts()->CopyFrom(context_);
38 } 38 }
39 39
40 SyncerError NonBlockingTypeCommitContribution::ProcessCommitResponse( 40 syncer::SyncerError NonBlockingTypeCommitContribution::ProcessCommitResponse(
41 const sync_pb::ClientToServerResponse& response, 41 const sync_pb::ClientToServerResponse& response,
42 StatusController* status) { 42 syncer::StatusController* status) {
43 const sync_pb::CommitResponse& commit_response = response.commit(); 43 const sync_pb::CommitResponse& commit_response = response.commit();
44 44
45 bool transient_error = false; 45 bool transient_error = false;
46 bool commit_conflict = false; 46 bool commit_conflict = false;
47 bool unknown_error = false; 47 bool unknown_error = false;
48 48
49 CommitResponseDataList response_list; 49 CommitResponseDataList response_list;
50 50
51 for (int i = 0; i < entities_.size(); ++i) { 51 for (int i = 0; i < entities_.size(); ++i) {
52 const sync_pb::CommitResponse_EntryResponse& entry_response = 52 const sync_pb::CommitResponse_EntryResponse& entry_response =
53 commit_response.entryresponse(entries_start_index_ + i); 53 commit_response.entryresponse(entries_start_index_ + i);
54 54
55 switch (entry_response.response_type()) { 55 switch (entry_response.response_type()) {
56 case sync_pb::CommitResponse::INVALID_MESSAGE: 56 case sync_pb::CommitResponse::INVALID_MESSAGE:
57 LOG(ERROR) << "Server reports commit message is invalid."; 57 LOG(ERROR) << "Server reports commit message is invalid.";
58 DLOG(ERROR) << "Message was: " 58 DLOG(ERROR) << "Message was: "
59 << SyncEntityToValue(entities_.Get(i), false).get(); 59 << syncer::SyncEntityToValue(entities_.Get(i), false).get();
60 unknown_error = true; 60 unknown_error = true;
61 break; 61 break;
62 case sync_pb::CommitResponse::CONFLICT: 62 case sync_pb::CommitResponse::CONFLICT:
63 DVLOG(1) << "Server reports conflict for commit message."; 63 DVLOG(1) << "Server reports conflict for commit message.";
64 DVLOG(1) << "Message was: " 64 DVLOG(1) << "Message was: "
65 << SyncEntityToValue(entities_.Get(i), false).get(); 65 << syncer::SyncEntityToValue(entities_.Get(i), false).get();
66 commit_conflict = true; 66 commit_conflict = true;
67 break; 67 break;
68 case sync_pb::CommitResponse::SUCCESS: { 68 case sync_pb::CommitResponse::SUCCESS: {
69 CommitResponseData response_data; 69 CommitResponseData response_data;
70 response_data.id = entry_response.id_string(); 70 response_data.id = entry_response.id_string();
71 response_data.client_tag_hash = 71 response_data.client_tag_hash =
72 entities_.Get(i).client_defined_unique_tag(); 72 entities_.Get(i).client_defined_unique_tag();
73 response_data.response_version = entry_response.version(); 73 response_data.response_version = entry_response.version();
74 response_list.push_back(response_data); 74 response_list.push_back(response_data);
75 break; 75 break;
76 } 76 }
77 case sync_pb::CommitResponse::OVER_QUOTA: 77 case sync_pb::CommitResponse::OVER_QUOTA:
78 case sync_pb::CommitResponse::RETRY: 78 case sync_pb::CommitResponse::RETRY:
79 case sync_pb::CommitResponse::TRANSIENT_ERROR: 79 case sync_pb::CommitResponse::TRANSIENT_ERROR:
80 DLOG(WARNING) << "Entity commit blocked by transient error."; 80 DLOG(WARNING) << "Entity commit blocked by transient error.";
81 transient_error = true; 81 transient_error = true;
82 break; 82 break;
83 default: 83 default:
84 LOG(ERROR) << "Bad return from ProcessSingleCommitResponse."; 84 LOG(ERROR) << "Bad return from ProcessSingleCommitResponse.";
85 unknown_error = true; 85 unknown_error = true;
86 } 86 }
87 } 87 }
88 88
89 // Send whatever successful responses we did get back to our parent. 89 // Send whatever successful responses we did get back to our parent.
90 // It's the schedulers job to handle the failures. 90 // It's the schedulers job to handle the failures.
91 worker_->OnCommitResponse(&response_list); 91 worker_->OnCommitResponse(&response_list);
92 92
93 // Let the scheduler know about the failures. 93 // Let the scheduler know about the failures.
94 if (unknown_error) { 94 if (unknown_error) {
95 return SERVER_RETURN_UNKNOWN_ERROR; 95 return syncer::SERVER_RETURN_UNKNOWN_ERROR;
96 } else if (transient_error) { 96 } else if (transient_error) {
97 return SERVER_RETURN_TRANSIENT_ERROR; 97 return syncer::SERVER_RETURN_TRANSIENT_ERROR;
98 } else if (commit_conflict) { 98 } else if (commit_conflict) {
99 return SERVER_RETURN_CONFLICT; 99 return syncer::SERVER_RETURN_CONFLICT;
100 } else { 100 } else {
101 return SYNCER_OK; 101 return syncer::SYNCER_OK;
102 } 102 }
103 } 103 }
104 104
105 void NonBlockingTypeCommitContribution::CleanUp() { 105 void NonBlockingTypeCommitContribution::CleanUp() {
106 cleaned_up_ = true; 106 cleaned_up_ = true;
107 107
108 // We could inform our parent NonBlockingCommitContributor that a commit is 108 // We could inform our parent NonBlockingCommitContributor that a commit is
109 // no longer in progress. The current implementation doesn't really care 109 // no longer in progress. The current implementation doesn't really care
110 // either way, so we don't bother sending the signal. 110 // either way, so we don't bother sending the signal.
111 } 111 }
112 112
113 size_t NonBlockingTypeCommitContribution::GetNumEntries() const { 113 size_t NonBlockingTypeCommitContribution::GetNumEntries() const {
114 return entities_.size(); 114 return entities_.size();
115 } 115 }
116 116
117 } // namespace syncer 117 } // namespace syncer_v2
OLDNEW
« no previous file with comments | « components/sync/engine_impl/non_blocking_type_commit_contribution.h ('k') | components/sync/engine_impl/nudge_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698