Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/clear_data_command.h" | 5 #include "chrome/browser/sync/engine/clear_data_command.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/browser/sync/engine/syncer.h" | 9 #include "chrome/browser/sync/engine/syncer.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 syncable::ScopedDirLookup; | 15 using syncable::ScopedDirLookup; |
| 16 | 16 |
| 17 namespace browser_sync { | 17 namespace browser_sync { |
| 18 | 18 |
| 19 using sessions::StatusController; | 19 using sessions::StatusController; |
| 20 using sessions::SyncSession; | 20 using sessions::SyncSession; |
| 21 using std::string; | 21 using std::string; |
| 22 using syncable::FIRST_REAL_MODEL_TYPE; | 22 using syncable::FIRST_REAL_MODEL_TYPE; |
| 23 using syncable::MODEL_TYPE_COUNT; | 23 using syncable::MODEL_TYPE_COUNT; |
| 24 | 24 |
| 25 | 25 |
| 26 ClearDataCommand::ClearDataCommand() {} | 26 ClearDataCommand::ClearDataCommand() {} |
| 27 ClearDataCommand::~ClearDataCommand() {} | 27 ClearDataCommand::~ClearDataCommand() {} |
| 28 | 28 |
| 29 void ClearDataCommand::ExecuteImpl(SyncSession* session) { | 29 SyncerError ClearDataCommand::ExecuteImpl(SyncSession* session) { |
| 30 ClientToServerMessage client_to_server_message; | 30 ClientToServerMessage client_to_server_message; |
| 31 ClientToServerResponse client_to_server_response; | 31 ClientToServerResponse client_to_server_response; |
| 32 | 32 |
| 33 client_to_server_message.set_share(session->context()->account_name()); | 33 client_to_server_message.set_share(session->context()->account_name()); |
| 34 client_to_server_message.set_message_contents( | 34 client_to_server_message.set_message_contents( |
| 35 ClientToServerMessage::CLEAR_DATA); | 35 ClientToServerMessage::CLEAR_DATA); |
| 36 | 36 |
| 37 client_to_server_message.mutable_clear_user_data(); | 37 client_to_server_message.mutable_clear_user_data(); |
| 38 | 38 |
| 39 ScopedDirLookup dir(session->context()->directory_manager(), | 39 ScopedDirLookup dir(session->context()->directory_manager(), |
| 40 session->context()->account_name()); | 40 session->context()->account_name()); |
| 41 if (!dir.good()) { | 41 if (!dir.good()) { |
| 42 LOG(ERROR) << "Scoped dir lookup failed!"; | 42 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 43 return; | 43 return DIRECTORY_LOOKUP_FAILED; |
| 44 } | 44 } |
| 45 | 45 |
| 46 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); | 46 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); |
| 47 | 47 |
| 48 DVLOG(1) << "Clearing server data"; | 48 DVLOG(1) << "Clearing server data"; |
| 49 | 49 |
| 50 bool ok = SyncerProtoUtil::PostClientToServerMessage( | 50 bool ok = SyncerProtoUtil::PostClientToServerMessage( |
| 51 client_to_server_message, | 51 client_to_server_message, |
| 52 &client_to_server_response, | 52 &client_to_server_response, |
| 53 session); | 53 session); |
| 54 | 54 |
| 55 DVLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( | 55 DVLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( |
| 56 client_to_server_response); | 56 client_to_server_response); |
| 57 | 57 |
| 58 // TODO(rlarocque): This code is wrong. The response error codes it checks | |
| 59 // have been obsoleted. The only reason it hasn't caused problems is that | |
| 60 // this code is unreachable. We should do something to clean up this mess. | |
|
tim (not reviewing)
2012/01/06 16:33:42
This should be tagged with a bug, such as 71616.
rlarocque
2012/01/06 19:44:21
Done.
| |
| 61 // | |
| 58 // Clear pending indicates that the server has received our clear message | 62 // Clear pending indicates that the server has received our clear message |
| 59 if (!ok || !client_to_server_response.has_error_code() || | 63 if (!ok || !client_to_server_response.has_error_code() || |
| 60 client_to_server_response.error_code() != sync_pb::SyncEnums::SUCCESS) { | 64 client_to_server_response.error_code() != sync_pb::SyncEnums::SUCCESS) { |
| 61 // On failure, subsequent requests to the server will cause it to attempt | 65 // On failure, subsequent requests to the server will cause it to attempt |
| 62 // to resume the clear. The client will handle disabling of sync in | 66 // to resume the clear. The client will handle disabling of sync in |
| 63 // response to a store birthday error from the server. | 67 // response to a store birthday error from the server. |
| 64 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_FAILED); | 68 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_FAILED); |
| 65 session->context()->NotifyListeners(event); | 69 session->context()->NotifyListeners(event); |
| 66 | 70 |
| 67 LOG(ERROR) << "Error posting ClearData."; | 71 LOG(ERROR) << "Error posting ClearData."; |
| 68 | 72 |
| 69 return; | 73 return NO_ERROR; |
| 70 } | 74 } |
| 71 | 75 |
| 72 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED); | 76 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED); |
| 73 session->context()->NotifyListeners(event); | 77 session->context()->NotifyListeners(event); |
| 74 | 78 |
| 75 session->delegate()->OnShouldStopSyncingPermanently(); | 79 session->delegate()->OnShouldStopSyncingPermanently(); |
| 76 | 80 |
| 77 DVLOG(1) << "ClearData succeeded."; | 81 DVLOG(1) << "ClearData succeeded."; |
| 82 return NO_ERROR; | |
| 78 } | 83 } |
| 79 | 84 |
| 80 } // namespace browser_sync | 85 } // namespace browser_sync |
| OLD | NEW |