1 // Copyright (c) 2010 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 #include "chrome/browser/sync/syncable/directory_manager.h" 14 15 using syncable::ScopedDirLookup; 16 17 namespace browser_sync { 18 19 using sessions::StatusController; 20 using sessions::SyncSession; 21 using std::string; 22 using syncable::FIRST_REAL_MODEL_TYPE; 23 using syncable::MODEL_TYPE_COUNT; 24 25 ClearDataCommand()26ClearDataCommand::ClearDataCommand() {} ~ClearDataCommand()27ClearDataCommand::~ClearDataCommand() {} 28 ExecuteImpl(SyncSession * session)29void ClearDataCommand::ExecuteImpl(SyncSession* session) { 30 ClientToServerMessage client_to_server_message; 31 ClientToServerResponse client_to_server_response; 32 33 client_to_server_message.set_share(session->context()->account_name()); 34 client_to_server_message.set_message_contents( 35 ClientToServerMessage::CLEAR_DATA); 36 37 client_to_server_message.mutable_clear_user_data(); 38 39 ScopedDirLookup dir(session->context()->directory_manager(), 40 session->context()->account_name()); 41 if (!dir.good()) { 42 LOG(ERROR) << "Scoped dir lookup failed!"; 43 return; 44 } 45 46 SyncerProtoUtil::AddRequestBirthday(dir, &client_to_server_message); 47 48 VLOG(1) << "Clearing server data"; 49 50 bool ok = SyncerProtoUtil::PostClientToServerMessage( 51 client_to_server_message, 52 &client_to_server_response, 53 session); 54 55 DVLOG(1) << SyncerProtoUtil::ClientToServerResponseDebugString( 56 client_to_server_response); 57 58 // Clear pending indicates that the server has received our clear message 59 if (!ok || !client_to_server_response.has_error_code() || 60 client_to_server_response.error_code() != 61 sync_pb::ClientToServerResponse::SUCCESS) { 62 // On failure, subsequent requests to the server will cause it to attempt 63 // to resume the clear. The client will handle disabling of sync in 64 // response to a store birthday error from the server. 65 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_FAILED); 66 session->context()->NotifyListeners(event); 67 68 LOG(ERROR) << "Error posting ClearData."; 69 70 return; 71 } 72 73 SyncEngineEvent event(SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED); 74 session->context()->NotifyListeners(event); 75 76 session->delegate()->OnShouldStopSyncingPermanently(); 77 78 VLOG(1) << "ClearData succeeded."; 79 } 80 81 } // namespace browser_sync 82 83