File: sync_cycle_snapshot.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (142 lines) | stat: -rw-r--r-- 4,536 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sync/engine/cycle/sync_cycle_snapshot.h"

#include <string>
#include <utility>

#include "base/base64.h"
#include "base/i18n/time_formatting.h"
#include "base/json/json_writer.h"
#include "base/values.h"
#include "components/sync/protocol/proto_enum_conversions.h"

namespace syncer {

namespace {

std::u16string FormatTimeDelta(base::TimeDelta delta) {
  std::u16string value;
  bool ok =
      base::TimeDurationFormat(delta, base::DURATION_WIDTH_NARROW, &value);
  DCHECK(ok);
  return value;
}

}  // namespace

SyncCycleSnapshot::SyncCycleSnapshot()
    : is_silenced_(false),
      num_server_conflicts_(0),
      notifications_enabled_(false),
      has_remaining_local_changes_(false),
      is_initialized_(false) {}

SyncCycleSnapshot::SyncCycleSnapshot(
    const std::string& birthday,
    const std::string& bag_of_chips,
    const ModelNeutralState& model_neutral_state,
    const ProgressMarkerMap& download_progress_markers,
    bool is_silenced,
    int num_server_conflicts,
    bool notifications_enabled,
    base::Time sync_start_time,
    base::Time poll_finish_time,
    sync_pb::SyncEnums::GetUpdatesOrigin get_updates_origin,
    base::TimeDelta poll_interval,
    bool has_remaining_local_changes)
    : birthday_(birthday),
      bag_of_chips_(bag_of_chips),
      model_neutral_state_(model_neutral_state),
      download_progress_markers_(download_progress_markers),
      is_silenced_(is_silenced),
      num_server_conflicts_(num_server_conflicts),
      notifications_enabled_(notifications_enabled),
      sync_start_time_(sync_start_time),
      poll_finish_time_(poll_finish_time),
      get_updates_origin_(get_updates_origin),
      poll_interval_(poll_interval),
      has_remaining_local_changes_(has_remaining_local_changes),
      is_initialized_(true) {}

SyncCycleSnapshot::SyncCycleSnapshot(const SyncCycleSnapshot& other) = default;

SyncCycleSnapshot::~SyncCycleSnapshot() = default;

base::Value::Dict SyncCycleSnapshot::ToValue() const {
  std::string encoded_bag_of_chips = base::Base64Encode(bag_of_chips_);

  return base::Value::Dict()
      .Set("birthday", birthday_)
      .Set("bagOfChips", encoded_bag_of_chips)
      .Set("numSuccessfulCommits", model_neutral_state_.num_successful_commits)
      .Set("numSuccessfulBookmarkCommits",
           model_neutral_state_.num_successful_bookmark_commits)
      .Set("numUpdatesDownloadedTotal",
           model_neutral_state_.num_updates_downloaded_total)
      .Set("numTombstoneUpdatesDownloadedTotal",
           model_neutral_state_.num_tombstone_updates_downloaded_total)
      .Set("downloadProgressMarkers",
           ProgressMarkerMapToValueDict(download_progress_markers_))
      .Set("isSilenced", is_silenced_)
      // We don't care too much if we lose precision here, also.
      .Set("numServerConflicts", num_server_conflicts_)
      .Set("getUpdatesOrigin", ProtoEnumToString(get_updates_origin_))
      .Set("notificationsEnabled", notifications_enabled_)
      .Set("hasRemainingLocalChanges", has_remaining_local_changes_)
      .Set("poll_interval", FormatTimeDelta(poll_interval_))
      .Set("poll_finish_time",
           base::TimeFormatShortDateAndTimeWithTimeZone(poll_finish_time_));
}

std::string SyncCycleSnapshot::ToString() const {
  std::string json;
  base::JSONWriter::WriteWithOptions(
      ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
  return json;
}

const ProgressMarkerMap& SyncCycleSnapshot::download_progress_markers() const {
  return download_progress_markers_;
}

bool SyncCycleSnapshot::is_silenced() const {
  return is_silenced_;
}

int SyncCycleSnapshot::num_server_conflicts() const {
  return num_server_conflicts_;
}

bool SyncCycleSnapshot::notifications_enabled() const {
  return notifications_enabled_;
}

base::Time SyncCycleSnapshot::sync_start_time() const {
  return sync_start_time_;
}

base::Time SyncCycleSnapshot::poll_finish_time() const {
  return poll_finish_time_;
}

bool SyncCycleSnapshot::has_remaining_local_changes() const {
  return has_remaining_local_changes_;
}

bool SyncCycleSnapshot::is_initialized() const {
  return is_initialized_;
}

sync_pb::SyncEnums::GetUpdatesOrigin SyncCycleSnapshot::get_updates_origin()
    const {
  return get_updates_origin_;
}

base::TimeDelta SyncCycleSnapshot::poll_interval() const {
  return poll_interval_;
}

}  // namespace syncer