1 // Copyright 2015 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.
5 #include "sync/engine/clear_server_data.h"
7 #include "base/trace_event/trace_event.h"
8 #include "sync/engine/syncer.h"
9 #include "sync/engine/syncer_proto_util.h"
10 #include "sync/internal_api/public/events/clear_server_data_request_event.h"
11 #include "sync/internal_api/public/events/clear_server_data_response_event.h"
12 #include "sync/sessions/sync_session.h"
16 ClearServerData::ClearServerData(const std::string
& account_name
) {
17 request_
.set_share(account_name
);
18 request_
.set_message_contents(
19 sync_pb::ClientToServerMessage::CLEAR_SERVER_DATA
);
20 request_
.mutable_clear_server_data();
23 ClearServerData::~ClearServerData() {}
25 SyncerError
ClearServerData::SendRequest(sessions::SyncSession
* session
) {
26 if (session
->context()->debug_info_getter()) {
27 sync_pb::DebugInfo
* debug_info
= request_
.mutable_debug_info();
28 session
->context()->debug_info_getter()->GetDebugInfo(debug_info
);
31 DVLOG(1) << "Sending ClearServerData message.";
33 const ClearServerDataRequestEvent
request_event(base::Time::Now(), request_
);
34 session
->SendProtocolEvent(request_event
);
36 sync_pb::ClientToServerResponse response
;
38 TRACE_EVENT_BEGIN0("sync", "PostClearServerData");
39 const SyncerError post_result
= SyncerProtoUtil::PostClientToServerMessage(
40 &request_
, &response
, session
, nullptr);
41 TRACE_EVENT_END0("sync", "PostClearServerData");
43 const ClearServerDataResponseEvent
response_event(base::Time::Now(),
44 post_result
, response
);
45 session
->SendProtocolEvent(response_event
);
47 if (post_result
!= SYNCER_OK
) {
48 DVLOG(1) << "Post ClearServerData failed";
52 if (!response
.has_clear_server_data()) {
53 DVLOG(1) << "ClearServerData response has no ClearServerData body!";
54 return SERVER_RESPONSE_VALIDATION_FAILED
;
57 if (session
->context()->debug_info_getter()) {
58 DVLOG(1) << "Clearing client debug info.";
59 session
->context()->debug_info_getter()->ClearDebugInfo();