OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/post_commit_message_command.h" | 5 #include "chrome/browser/sync/engine/post_commit_message_command.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 10 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
11 #include "chrome/browser/sync/engine/syncproto.h" | 11 #include "chrome/browser/sync/engine/syncproto.h" |
12 #include "chrome/browser/sync/sessions/sync_session.h" | 12 #include "chrome/browser/sync/sessions/sync_session.h" |
13 #include "chrome/browser/sync/syncable/directory_manager.h" | 13 #include "chrome/browser/sync/syncable/directory_manager.h" |
14 | 14 |
15 using std::vector; | 15 using std::vector; |
16 | 16 |
17 namespace browser_sync { | 17 namespace browser_sync { |
18 | 18 |
19 PostCommitMessageCommand::PostCommitMessageCommand() {} | 19 PostCommitMessageCommand::PostCommitMessageCommand() {} |
20 PostCommitMessageCommand::~PostCommitMessageCommand() {} | 20 PostCommitMessageCommand::~PostCommitMessageCommand() {} |
21 | 21 |
22 void PostCommitMessageCommand::ExecuteImpl(sessions::SyncSession* session) { | 22 void PostCommitMessageCommand::ExecuteImpl(sessions::SyncSession* session) { |
23 if (session->status_controller()->commit_ids().empty()) | 23 sessions::StatusController* status = session->status_controller(); |
| 24 SyncOperationResult result; |
| 25 if (status->commit_ids().empty()) |
24 return; // Nothing to commit. | 26 return; // Nothing to commit. |
25 ClientToServerResponse response; | 27 ClientToServerResponse response; |
26 syncable::ScopedDirLookup dir(session->context()->directory_manager(), | 28 syncable::ScopedDirLookup dir(session->context()->directory_manager(), |
27 session->context()->account_name()); | 29 session->context()->account_name()); |
28 if (!dir.good()) | 30 if (!dir.good()) { |
| 31 result.error_type = DIRECTORY_LOOKUP_FAILED; |
| 32 status->set_last_post_commit_result(result); |
29 return; | 33 return; |
30 sessions::StatusController* status = session->status_controller(); | 34 } |
31 if (!SyncerProtoUtil::PostClientToServerMessage(status->commit_message(), | 35 result = SyncerProtoUtil::PostClientToServerMessage(status->commit_message(), |
32 &response, session)) { | 36 &response, session); |
| 37 status->set_last_post_commit_result(result); |
| 38 if (result.error_type != OPERATION_SUCCESS) { |
| 39 VLOG(1) << "Post commit message failed with return code: " << |
| 40 GetSyncErrorTypeString(result.error_type); |
33 // None of our changes got through. Clear the SYNCING bit which was | 41 // None of our changes got through. Clear the SYNCING bit which was |
34 // set to true during BuildCommitCommand, and which may still be true. | 42 // set to true during BuildCommitCommand, and which may still be true. |
35 // Not to be confused with IS_UNSYNCED, this bit is used to detect local | 43 // Not to be confused with IS_UNSYNCED, this bit is used to detect local |
36 // changes to items that happen during the server Commit operation. | 44 // changes to items that happen during the server Commit operation. |
37 status->increment_num_consecutive_errors(); | 45 status->increment_num_consecutive_errors(); |
38 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); | 46 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); |
39 const vector<syncable::Id>& commit_ids = status->commit_ids(); | 47 const vector<syncable::Id>& commit_ids = status->commit_ids(); |
40 for (size_t i = 0; i < commit_ids.size(); i++) { | 48 for (size_t i = 0; i < commit_ids.size(); i++) { |
41 syncable::MutableEntry entry(&trans, syncable::GET_BY_ID, commit_ids[i]); | 49 syncable::MutableEntry entry(&trans, syncable::GET_BY_ID, commit_ids[i]); |
42 entry.Put(syncable::SYNCING, false); | 50 entry.Put(syncable::SYNCING, false); |
43 } | 51 } |
44 return; | 52 return; |
45 } else { | 53 } else { |
46 status->set_items_committed(); | 54 status->set_items_committed(); |
47 } | 55 } |
48 status->mutable_commit_response()->CopyFrom(response); | 56 status->mutable_commit_response()->CopyFrom(response); |
49 } | 57 } |
50 | 58 |
51 } // namespace browser_sync | 59 } // namespace browser_sync |
OLD | NEW |