summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/engine/syncer_status.h
blob: 8301b56e2018ba776c8187aefa4c580d02056295 (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TODO(sync): We eventually want to fundamentally change how we represent
// status and inform the UI about the ways in which our status has changed.
// Right now, we're just trying to keep the various command classes from having
// to worry about this class.
//
// The UI will request that we fill this struct so it can show the current sync
// state.
//
// THIS CLASS PROVIDES NO SYNCHRONIZATION GUARANTEES.

#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_STATUS_H_
#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_STATUS_H_

#include "base/atomicops.h"
#include "base/port.h"
#include "chrome/browser/sync/engine/sync_cycle_state.h"
#include "chrome/browser/sync/engine/sync_process_state.h"

namespace browser_sync {

class SyncerSession;

class SyncerStatus {
 public:
   SyncerStatus(SyncCycleState* cycle_state, SyncProcessState* state)
       : sync_cycle_state_(cycle_state),
         sync_process_state_(state) {}
   explicit SyncerStatus(SyncerSession* s);
   ~SyncerStatus();

  bool invalid_store() const {
    return sync_process_state_->invalid_store();
  }

  void set_invalid_store(const bool val) {
    sync_process_state_->set_invalid_store(val);
  }

  bool syncer_stuck() const {
    return sync_process_state_->syncer_stuck();
  }

  void set_syncer_stuck(const bool val) {
    sync_process_state_->set_syncer_stuck(val);
  }

  bool syncing() const {
    return sync_process_state_->syncing();
  }

  void set_syncing(const bool val) {
    sync_process_state_->set_syncing(val);
  }

  bool IsShareUsable() const {
    return sync_process_state_->IsShareUsable();
  }

  // During initial sync these two members can be used to measure sync
  // progress.
  int64 current_sync_timestamp() const {
    return sync_process_state_->current_sync_timestamp();
  }

  void set_current_sync_timestamp(const int64 val) {
    sync_process_state_->set_current_sync_timestamp(val);
  }

  int64 servers_latest_timestamp() const {
    return sync_process_state_->servers_latest_timestamp();
  }

  void set_servers_latest_timestamp(const int64 val) {
    sync_process_state_->set_servers_latest_timestamp(val);
  }

  int64 unsynced_count() const {
    return sync_cycle_state_->unsynced_count();
  }

  int conflicting_updates() const {
    return sync_process_state_->conflicting_updates();
  }

  int conflicting_commits() const {
    return sync_process_state_->conflicting_commits();
  }

  void set_conflicting_commits(const int val) {
    sync_process_state_->set_conflicting_commits(val);
  }

  int BlockedItemsSize() const {
    return sync_process_state_->BlockedItemsSize();
  }

  int stalled_updates() const {
    return sync_process_state_->BlockedItemsSize();
  }

  int error_commits() const {
    return sync_process_state_->error_commits();
  }

  void set_error_commits(const int val) {
    sync_process_state_->set_error_commits(val);
  }

  // WEIRD COUNTER manipulation functions.
  int consecutive_problem_get_updates() const {
    return sync_process_state_->consecutive_problem_get_updates();
  }

  void increment_consecutive_problem_get_updates() {
    sync_process_state_->increment_consecutive_problem_get_updates();
  }

  void zero_consecutive_problem_get_updates() {
    sync_process_state_->zero_consecutive_problem_get_updates();
  }

  int consecutive_problem_commits() const {
    return sync_process_state_->consecutive_problem_commits();
  }

  void increment_consecutive_problem_commits() {
    sync_process_state_->increment_consecutive_problem_commits();
  }

  void zero_consecutive_problem_commits() {
    sync_process_state_->zero_consecutive_problem_commits();
  }

  int consecutive_transient_error_commits() const {
    return sync_process_state_->consecutive_transient_error_commits();
  }

  void increment_consecutive_transient_error_commits_by(int value) {
    sync_process_state_->increment_consecutive_transient_error_commits_by(
        value);
  }

  void zero_consecutive_transient_error_commits() {
    sync_process_state_->zero_consecutive_transient_error_commits();
  }

  int consecutive_errors() const {
    return sync_process_state_->consecutive_errors();
  }

  void increment_consecutive_errors() {
    increment_consecutive_errors_by(1);
  }

  void increment_consecutive_errors_by(int value) {
    sync_process_state_->increment_consecutive_errors_by(value);
  }

  void zero_consecutive_errors() {
    sync_process_state_->zero_consecutive_errors();
  }

  int successful_commits() const {
    return sync_process_state_->successful_commits();
  }

  void increment_successful_commits() {
    sync_process_state_->increment_successful_commits();
  }

  void zero_successful_commits() {
    sync_process_state_->zero_successful_commits();
  }
  // End WEIRD COUNTER manipulation functions.

  bool over_quota() const { return sync_cycle_state_->over_quota(); }

  // Methods for managing error rate tracking in sync_process_state.
  void TallyNewError() {
    sync_process_state_->TallyNewError();
  }

  void TallyBigNewError() {
    sync_process_state_->TallyBigNewError();
  }

  void ForgetOldError() {
    sync_process_state_->ForgetOldError();
  }

  void CheckErrorRateTooHigh() {
    sync_process_state_->CheckErrorRateTooHigh();
  }

  void AuthFailed() { sync_process_state_->AuthFailed(); }

  void AuthSucceeded() { sync_process_state_->AuthSucceeded(); }

  // Returns true if this object has been modified since last SetClean() call.
  bool IsDirty() const {
    return sync_cycle_state_->IsDirty() || sync_process_state_->IsDirty();
  }

  // Returns true if auth status has been modified since last SetClean() call.
  bool IsAuthDirty() const { return sync_process_state_->IsAuthDirty(); }

  // Call to tell this status object that its new state has been seen.
  void SetClean() {
    sync_process_state_->SetClean();
    sync_cycle_state_->SetClean();
  }

  // Call to tell this status object that its auth state has been seen.
  void SetAuthClean() { sync_process_state_->SetAuthClean(); }

  void DumpStatusInfo() const {
    LOG(INFO) << "Dumping status info: " << (IsDirty() ? "DIRTY" : "CLEAN");

    LOG(INFO) << "invalid store = " << invalid_store();
    LOG(INFO) << "syncer_stuck = " << syncer_stuck();
    LOG(INFO) << "syncing = " << syncing();
    LOG(INFO) << "over_quota = " << over_quota();

    LOG(INFO) << "current_sync_timestamp = " << current_sync_timestamp();
    LOG(INFO) << "servers_latest_timestamp = " << servers_latest_timestamp();
    LOG(INFO) << "unsynced_count = " << unsynced_count();
    LOG(INFO) << "conflicting_updates = " << conflicting_updates();
    LOG(INFO) << "conflicting_commits = " << conflicting_commits();
    LOG(INFO) << "BlockedItemsSize = " << BlockedItemsSize();
    LOG(INFO) << "stalled_updates = " << stalled_updates();
    LOG(INFO) << "error_commits = " << error_commits();

    LOG(INFO) << "consecutive_problem_get_updates = "
              << consecutive_problem_get_updates();
    LOG(INFO) << "consecutive_problem_commits = "
              << consecutive_problem_commits();
    LOG(INFO) << "consecutive_transient_error_commits = "
              << consecutive_transient_error_commits();
    LOG(INFO) << "consecutive_errors = " << consecutive_errors();
    LOG(INFO) << "successful_commits = " << successful_commits();
  }

 private:
  SyncCycleState* sync_cycle_state_;
  SyncProcessState* sync_process_state_;
};

}  // namespace browser_sync

#endif  // CHROME_BROWSER_SYNC_ENGINE_SYNCER_STATUS_H_