| 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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/sync/engine/auth_watcher.h" | |
| 10 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 9 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 11 #include "chrome/browser/sync/engine/syncer.h" | 10 #include "chrome/browser/sync/engine/syncer.h" |
| 11 #include "chrome/browser/sync/engine/syncer_types.h" |
| 12 #include "chrome/browser/sync/engine/syncer_util.h" | 12 #include "chrome/browser/sync/engine/syncer_util.h" |
| 13 #include "chrome/browser/sync/protocol/service_constants.h" | 13 #include "chrome/browser/sync/protocol/service_constants.h" |
| 14 #include "chrome/browser/sync/sessions/sync_session.h" | 14 #include "chrome/browser/sync/sessions/sync_session.h" |
| 15 #include "chrome/browser/sync/syncable/directory_manager.h" | 15 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 16 #include "chrome/browser/sync/syncable/syncable-inl.h" | 16 #include "chrome/browser/sync/syncable/syncable-inl.h" |
| 17 #include "chrome/browser/sync/syncable/syncable.h" | 17 #include "chrome/browser/sync/syncable/syncable.h" |
| 18 | 18 |
| 19 using std::string; | 19 using std::string; |
| 20 using std::stringstream; | 20 using std::stringstream; |
| 21 using syncable::BASE_VERSION; | 21 using syncable::BASE_VERSION; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // static | 117 // static |
| 118 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, | 118 void SyncerProtoUtil::AddRequestBirthday(syncable::Directory* dir, |
| 119 ClientToServerMessage* msg) { | 119 ClientToServerMessage* msg) { |
| 120 if (!dir->store_birthday().empty()) { | 120 if (!dir->store_birthday().empty()) { |
| 121 msg->set_store_birthday(dir->store_birthday()); | 121 msg->set_store_birthday(dir->store_birthday()); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 // static | 125 // static |
| 126 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, | 126 bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, |
| 127 AuthWatcher* auth_watcher, | 127 sessions::SyncSession* session, |
| 128 const ClientToServerMessage& msg, | 128 const ClientToServerMessage& msg, |
| 129 ClientToServerResponse* response) { | 129 ClientToServerResponse* response) { |
| 130 | 130 |
| 131 std::string tx, rx; | 131 std::string tx, rx; |
| 132 msg.SerializeToString(&tx); | 132 msg.SerializeToString(&tx); |
| 133 | 133 |
| 134 HttpResponse http_response; | 134 HttpResponse http_response; |
| 135 ServerConnectionManager::PostBufferParams params = { | 135 ServerConnectionManager::PostBufferParams params = { |
| 136 tx, &rx, &http_response | 136 tx, &rx, &http_response |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 ScopedServerStatusWatcher server_status_watcher(scm, &http_response); | 139 ScopedServerStatusWatcher server_status_watcher(scm, &http_response); |
| 140 if (!scm->PostBufferWithCachedAuth(¶ms, &server_status_watcher)) { | 140 if (!scm->PostBufferWithCachedAuth(¶ms, &server_status_watcher)) { |
| 141 LOG(WARNING) << "Error posting from syncer:" << http_response; | 141 LOG(WARNING) << "Error posting from syncer:" << http_response; |
| 142 return false; | 142 return false; |
| 143 } else { | 143 } else { |
| 144 std::string new_token = | 144 std::string new_token = |
| 145 http_response.update_client_auth_header; | 145 http_response.update_client_auth_header; |
| 146 if (!new_token.empty()) { | 146 if (!new_token.empty()) { |
| 147 // We could also do this in the SCM's PostBufferWithAuth. | 147 SyncerEvent event(SyncerEvent::UPDATED_TOKEN); |
| 148 // But then we could be in the middle of authentication, which seems | 148 event.updated_token = new_token; |
| 149 // like a bad time to update the token. A consequence of this is that | 149 session->context()->syncer_event_channel()->Notify(event); |
| 150 // we can't reset the cookie in response to auth attempts, but this | |
| 151 // should be OK. | |
| 152 auth_watcher->RenewAuthToken(new_token); | |
| 153 } | 150 } |
| 154 | 151 |
| 155 if (response->ParseFromString(rx)) { | 152 if (response->ParseFromString(rx)) { |
| 156 // TODO(tim): This is an egregious layering violation (bug 35060). | 153 // TODO(tim): This is an egregious layering violation (bug 35060). |
| 157 switch (response->error_code()) { | 154 switch (response->error_code()) { |
| 158 case ClientToServerResponse::ACCESS_DENIED: | 155 case ClientToServerResponse::ACCESS_DENIED: |
| 159 case ClientToServerResponse::AUTH_INVALID: | 156 case ClientToServerResponse::AUTH_INVALID: |
| 160 case ClientToServerResponse::USER_NOT_ACTIVATED: | 157 case ClientToServerResponse::USER_NOT_ACTIVATED: |
| 161 // Fires on ScopedServerStatusWatcher | 158 // Fires on ScopedServerStatusWatcher |
| 162 http_response.server_status = HttpResponse::SYNC_AUTH_ERROR; | 159 http_response.server_status = HttpResponse::SYNC_AUTH_ERROR; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 182 msg.get_updates().from_timestamp() == 0)) | 179 msg.get_updates().from_timestamp() == 0)) |
| 183 << "Must call AddRequestBirthday to set birthday."; | 180 << "Must call AddRequestBirthday to set birthday."; |
| 184 | 181 |
| 185 ScopedDirLookup dir(session->context()->directory_manager(), | 182 ScopedDirLookup dir(session->context()->directory_manager(), |
| 186 session->context()->account_name()); | 183 session->context()->account_name()); |
| 187 if (!dir.good()) { | 184 if (!dir.good()) { |
| 188 return false; | 185 return false; |
| 189 } | 186 } |
| 190 | 187 |
| 191 if (!PostAndProcessHeaders(session->context()->connection_manager(), | 188 if (!PostAndProcessHeaders(session->context()->connection_manager(), |
| 192 session->context()->auth_watcher(), | 189 session, |
| 193 msg, | 190 msg, |
| 194 response)) { | 191 response)) { |
| 195 return false; | 192 return false; |
| 196 } | 193 } |
| 197 | 194 |
| 198 if (!VerifyResponseBirthday(dir, response)) { | 195 if (!VerifyResponseBirthday(dir, response)) { |
| 199 session->status_controller()->set_syncer_stuck(true); | 196 session->status_controller()->set_syncer_stuck(true); |
| 200 session->delegate()->OnShouldStopSyncingPermanently(); | 197 session->delegate()->OnShouldStopSyncingPermanently(); |
| 201 return false; | 198 return false; |
| 202 } | 199 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 const sync_pb::ClientToServerResponse& response) { | 344 const sync_pb::ClientToServerResponse& response) { |
| 348 // Add more handlers as needed. | 345 // Add more handlers as needed. |
| 349 std::string output; | 346 std::string output; |
| 350 if (response.has_get_updates()) { | 347 if (response.has_get_updates()) { |
| 351 output.append(GetUpdatesResponseString(response.get_updates())); | 348 output.append(GetUpdatesResponseString(response.get_updates())); |
| 352 } | 349 } |
| 353 return output; | 350 return output; |
| 354 } | 351 } |
| 355 | 352 |
| 356 } // namespace browser_sync | 353 } // namespace browser_sync |
| OLD | NEW |