| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/engine/clear_data_command.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "chrome/browser/sync/engine/syncer.h" | |
| 10 #include "chrome/browser/sync/engine/syncer_proto_util.h" | |
| 11 #include "chrome/browser/sync/engine/syncproto.h" | |
| 12 #include "chrome/browser/sync/sessions/sync_session.h" | |
| 13 | |
| 14 namespace browser_sync { | |
| 15 | |
| 16 using sessions::StatusController; | |
| 17 using sessions::SyncSession; | |
| 18 using std::string; | |
| 19 using syncable::FIRST_REAL_MODEL_TYPE; | |
| 20 using syncable::MODEL_TYPE_COUNT; | |
| 21 | |
| 22 | |
| 23 ClearDataCommand::ClearDataCommand() {} | |
| 24 ClearDataCommand::~ClearDataCommand() {} | |
| 25 | |
| 26 SyncerError ClearDataCommand::ExecuteImpl(SyncSession* session) { | |
| 27 ClientToServerMessage client_to_server_message; | |
| 28 ClientToServerResponse client_to_server_response; | |
| 29 | |
| 30 client_to_server_message.set_share(session->context()->account_name()); | |
| 31 client_to_server_message.set_message_contents( | |
| 32 ClientToServerMessage::CLEAR_DATA); | |
| 33 | |
| 34 client_to_server_message.mutable_clear_user_data(); | |
| 35 | |
| 36 SyncerProtoUtil::AddRequestBirthday(session->context()->directory(), | |
| 37 &client_to_server_message); | |
| 38 | |
| 39 DVLOG(1) << "Clearing server data"; | |
| 40 | |
| 41 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( | |
| 42 client_to_server_message, | |
| 43 &client_to_server_response, | |
| 44 session); | |
| 45 | |
| 46 DVLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( | |
| 47 client_to_server_response); | |
| 48 | |
| 49 // TODO(lipalani): This code is wrong. The response error codes it checks | |
| 50 // have been obsoleted. The only reason it hasn't caused problems is that | |
| 51 // this code is unreachable. We should do something to clean up this mess. | |
| 52 // See also: crbug.com/71616. | |
| 53 // | |
| 54 // Clear pending indicates that the server has received our clear message | |
| 55 if (result != SYNCER_OK || !client_to_server_response.has_error_code() || | |
| 56 client_to_server_response.error_code() != sync_pb::SyncEnums::SUCCESS) { | |
| 57 // On failure, subsequent requests to the server will cause it to attempt | |
| 58 // to resume the clear. The client will handle disabling of sync in | |
| 59 // response to a store birthday error from the server. | |
| 60 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_FAILED); | |
| 61 session->context()->NotifyListeners(event); | |
| 62 | |
| 63 LOG(ERROR) << "Error posting ClearData."; | |
| 64 | |
| 65 return result; | |
| 66 } | |
| 67 | |
| 68 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED); | |
| 69 session->context()->NotifyListeners(event); | |
| 70 | |
| 71 session->delegate()->OnShouldStopSyncingPermanently(); | |
| 72 | |
| 73 DVLOG(1) << "ClearData succeeded."; | |
| 74 return SYNCER_OK; | |
| 75 } | |
| 76 | |
| 77 } // namespace browser_sync | |
| OLD | NEW |