• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 "sync/internal_api/public/events/get_updates_response_event.h"
6 
7 #include "base/strings/stringprintf.h"
8 #include "sync/protocol/proto_value_conversions.h"
9 
10 namespace syncer {
11 
GetUpdatesResponseEvent(base::Time timestamp,const sync_pb::ClientToServerResponse & response,SyncerError error)12 GetUpdatesResponseEvent::GetUpdatesResponseEvent(
13       base::Time timestamp,
14       const sync_pb::ClientToServerResponse& response,
15       SyncerError error)
16   : timestamp_(timestamp),
17     response_(response),
18     error_(error) {
19 }
20 
~GetUpdatesResponseEvent()21 GetUpdatesResponseEvent::~GetUpdatesResponseEvent() {}
22 
GetTimestamp() const23 base::Time GetUpdatesResponseEvent::GetTimestamp() const {
24   return timestamp_;
25 }
26 
GetType() const27 std::string GetUpdatesResponseEvent::GetType() const {
28   return "GetUpdates Response";
29 }
30 
GetDetails() const31 std::string GetUpdatesResponseEvent::GetDetails() const {
32   switch (error_) {
33     case SYNCER_OK:
34       return base::StringPrintf("Received %d update(s).",
35                                 response_.get_updates().entries_size());
36     case SERVER_MORE_TO_DOWNLOAD:
37       return base::StringPrintf("Received %d update(s).  Some updates remain.",
38                                 response_.get_updates().entries_size());
39     default:
40       return base::StringPrintf("Received error: %s",
41                                 GetSyncerErrorString(error_));
42   }
43 }
44 
45 scoped_ptr<base::DictionaryValue>
GetProtoMessage() const46 GetUpdatesResponseEvent::GetProtoMessage() const {
47   return scoped_ptr<base::DictionaryValue>(
48       ClientToServerResponseToValue(response_, false));
49 }
50 
Clone() const51 scoped_ptr<ProtocolEvent> GetUpdatesResponseEvent::Clone() const {
52   return scoped_ptr<ProtocolEvent>(
53       new GetUpdatesResponseEvent(
54           timestamp_,
55           response_,
56           error_));
57 }
58 
59 }  // namespace syncer
60