| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/syncer_proto_util.h" | 5 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 7 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 8 #include "chrome/browser/sync/engine/syncer.h" | 8 #include "chrome/browser/sync/engine/syncer.h" |
| 9 #include "chrome/browser/sync/engine/syncer_util.h" | 9 #include "chrome/browser/sync/engine/syncer_util.h" |
| 10 #include "chrome/browser/sync/protocol/service_constants.h" | 10 #include "chrome/browser/sync/protocol/service_constants.h" |
| 11 #include "chrome/browser/sync/sessions/sync_session.h" |
| 11 #include "chrome/browser/sync/syncable/directory_manager.h" | 12 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 12 #include "chrome/browser/sync/syncable/syncable-inl.h" | 13 #include "chrome/browser/sync/syncable/syncable-inl.h" |
| 13 #include "chrome/browser/sync/syncable/syncable.h" | 14 #include "chrome/browser/sync/syncable/syncable.h" |
| 14 | 15 |
| 15 using std::string; | 16 using std::string; |
| 16 using std::stringstream; | 17 using std::stringstream; |
| 17 using syncable::BASE_VERSION; | 18 using syncable::BASE_VERSION; |
| 18 using syncable::CTIME; | 19 using syncable::CTIME; |
| 19 using syncable::ID; | 20 using syncable::ID; |
| 20 using syncable::IS_DEL; | 21 using syncable::IS_DEL; |
| 21 using syncable::IS_DIR; | 22 using syncable::IS_DIR; |
| 22 using syncable::IS_UNSYNCED; | 23 using syncable::IS_UNSYNCED; |
| 23 using syncable::MTIME; | 24 using syncable::MTIME; |
| 24 using syncable::PARENT_ID; | 25 using syncable::PARENT_ID; |
| 25 using syncable::ScopedDirLookup; | 26 using syncable::ScopedDirLookup; |
| 26 using syncable::SyncName; | 27 using syncable::SyncName; |
| 27 | 28 |
| 28 namespace browser_sync { | 29 namespace browser_sync { |
| 30 using sessions::SyncSession; |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Time to backoff syncing after receiving a throttled response. | 34 // Time to backoff syncing after receiving a throttled response. |
| 33 static const int kSyncDelayAfterThrottled = 2 * 60 * 60; // 2 hours | 35 static const int kSyncDelayAfterThrottled = 2 * 60 * 60; // 2 hours |
| 34 | 36 |
| 35 // Verifies the store birthday, alerting/resetting as appropriate if there's a | 37 // Verifies the store birthday, alerting/resetting as appropriate if there's a |
| 36 // mismatch. | 38 // mismatch. |
| 37 bool VerifyResponseBirthday(const ScopedDirLookup& dir, | 39 bool VerifyResponseBirthday(const ScopedDirLookup& dir, |
| 38 const ClientToServerResponse* response) { | 40 const ClientToServerResponse* response) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 response.profiling_data().total_request_time() << "ms"; | 88 response.profiling_data().total_request_time() << "ms"; |
| 87 } | 89 } |
| 88 LOG(INFO) << response_trace.str(); | 90 LOG(INFO) << response_trace.str(); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace | 94 } // namespace |
| 93 | 95 |
| 94 // static | 96 // static |
| 95 bool SyncerProtoUtil::PostClientToServerMessage(ClientToServerMessage* msg, | 97 bool SyncerProtoUtil::PostClientToServerMessage(ClientToServerMessage* msg, |
| 96 ClientToServerResponse* response, SyncerSession* session) { | 98 ClientToServerResponse* response, SyncSession* session) { |
| 97 bool rv = false; | 99 bool rv = false; |
| 98 string tx, rx; | 100 string tx, rx; |
| 99 CHECK(response); | 101 CHECK(response); |
| 100 | 102 |
| 101 ScopedDirLookup dir(session->dirman(), session->account_name()); | 103 ScopedDirLookup dir(session->context()->directory_manager(), |
| 104 session->context()->account_name()); |
| 102 if (!dir.good()) | 105 if (!dir.good()) |
| 103 return false; | 106 return false; |
| 104 string birthday = dir->store_birthday(); | 107 string birthday = dir->store_birthday(); |
| 105 if (!birthday.empty()) { | 108 if (!birthday.empty()) { |
| 106 msg->set_store_birthday(birthday); | 109 msg->set_store_birthday(birthday); |
| 107 } else { | 110 } else { |
| 108 LOG(INFO) << "no birthday set"; | 111 LOG(INFO) << "no birthday set"; |
| 109 } | 112 } |
| 110 | 113 |
| 111 msg->SerializeToString(&tx); | 114 msg->SerializeToString(&tx); |
| 112 HttpResponse http_response; | 115 HttpResponse http_response; |
| 113 ServerConnectionManager::PostBufferParams params = { | 116 ServerConnectionManager::PostBufferParams params = { |
| 114 tx, &rx, &http_response | 117 tx, &rx, &http_response |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 if (!session->connection_manager()->PostBufferWithCachedAuth(¶ms)) { | 120 ServerConnectionManager* scm = session->context()->connection_manager(); |
| 121 if (!scm->PostBufferWithCachedAuth(¶ms)) { |
| 118 LOG(WARNING) << "Error posting from syncer:" << http_response; | 122 LOG(WARNING) << "Error posting from syncer:" << http_response; |
| 119 } else { | 123 } else { |
| 120 rv = response->ParseFromString(rx); | 124 rv = response->ParseFromString(rx); |
| 121 } | 125 } |
| 122 SyncerStatus status(session); | |
| 123 if (rv) { | 126 if (rv) { |
| 124 if (!VerifyResponseBirthday(dir, response)) { | 127 if (!VerifyResponseBirthday(dir, response)) { |
| 125 // TODO(ncarter): Add a unit test for the case where the syncer becomes | 128 // TODO(ncarter): Add a unit test for the case where the syncer becomes |
| 126 // stuck due to a bad birthday. | 129 // stuck due to a bad birthday. |
| 127 status.set_syncer_stuck(true); | 130 session->status_controller()->set_syncer_stuck(true); |
| 128 return false; | 131 return false; |
| 129 } | 132 } |
| 130 | 133 |
| 131 switch (response->error_code()) { | 134 switch (response->error_code()) { |
| 132 case ClientToServerResponse::SUCCESS: | 135 case ClientToServerResponse::SUCCESS: |
| 133 if (!response->has_store_birthday() && birthday.empty()) { | 136 if (!response->has_store_birthday() && birthday.empty()) { |
| 134 LOG(ERROR) << | 137 LOG(ERROR) << |
| 135 "Server didn't provide birthday in proto buffer response."; | 138 "Server didn't provide birthday in proto buffer response."; |
| 136 rv = false; | 139 rv = false; |
| 137 } | 140 } |
| 138 LogResponseProfilingData(*response); | 141 LogResponseProfilingData(*response); |
| 139 break; | 142 break; |
| 140 case ClientToServerResponse::USER_NOT_ACTIVATED: | 143 case ClientToServerResponse::USER_NOT_ACTIVATED: |
| 141 case ClientToServerResponse::AUTH_INVALID: | 144 case ClientToServerResponse::AUTH_INVALID: |
| 142 case ClientToServerResponse::ACCESS_DENIED: | 145 case ClientToServerResponse::ACCESS_DENIED: |
| 143 LOG(INFO) << "Authentication expired, re-requesting"; | 146 LOG(INFO) << "Authentication expired, re-requesting"; |
| 144 LOG(INFO) << "Not implemented in syncer yet!!!"; | 147 LOG(INFO) << "Not implemented in syncer yet!!!"; |
| 145 status.AuthFailed(); | 148 session->set_auth_failure_occurred(); |
| 146 rv = false; | 149 rv = false; |
| 147 break; | 150 break; |
| 148 case ClientToServerResponse::NOT_MY_BIRTHDAY: | 151 case ClientToServerResponse::NOT_MY_BIRTHDAY: |
| 149 LOG(WARNING) << "Not my birthday return."; | 152 LOG(WARNING) << "Not my birthday return."; |
| 150 rv = false; | 153 rv = false; |
| 151 break; | 154 break; |
| 152 case ClientToServerResponse::THROTTLED: | 155 case ClientToServerResponse::THROTTLED: |
| 153 LOG(WARNING) << "Client silenced by server."; | 156 LOG(WARNING) << "Client silenced by server."; |
| 154 session->set_silenced_until(base::TimeTicks::Now() + | 157 session->delegate()->OnSilencedUntil(base::TimeTicks::Now() + |
| 155 base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled)); | 158 base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled)); |
| 156 rv = false; | 159 rv = false; |
| 157 break; | 160 break; |
| 158 default: | 161 default: |
| 159 NOTREACHED(); | 162 NOTREACHED(); |
| 160 break; | 163 break; |
| 161 } | 164 } |
| 162 | 165 |
| 163 } | 166 } |
| 164 return rv; | 167 return rv; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 const CommitResponse_EntryResponse& entry) { | 253 const CommitResponse_EntryResponse& entry) { |
| 251 | 254 |
| 252 if (entry.has_non_unique_name()) { | 255 if (entry.has_non_unique_name()) { |
| 253 return entry.non_unique_name(); | 256 return entry.non_unique_name(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 return entry.name(); | 259 return entry.name(); |
| 257 } | 260 } |
| 258 | 261 |
| 259 } // namespace browser_sync | 262 } // namespace browser_sync |
| OLD | NEW |