summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/engine/syncer_types.h
blob: 5a3f68afbb769ea194fc2f7601a329d76a02b6a4 (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
// 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.

#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_
#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_

#include <map>
#include <vector>

#include "chrome/browser/sync/util/channel.h"

namespace syncable {
class BaseTransaction;
class Id;
}

// The intent of this is to keep all shared data types and enums for the syncer
// in a single place without having dependencies between other files.
namespace browser_sync {

namespace sessions {
struct SyncSessionSnapshot;
}
class Syncer;

enum UpdateAttemptResponse {
  // Update was applied or safely ignored.
  SUCCESS,

  // Conflicts with the local data representation. This can also mean that the
  // entry doesn't currently make sense if we applied it.
  CONFLICT,
};

enum ServerUpdateProcessingResult {
  // Success. Update applied and stored in SERVER_* fields or dropped if
  // irrelevant.
  SUCCESS_PROCESSED,

  // Success. Update details stored in SERVER_* fields, but wasn't applied.
  SUCCESS_STORED,

  // Update is illegally inconsistent with earlier updates. e.g. A bookmark
  // becoming a folder.
  FAILED_INCONSISTENT,

  // Update is illegal when considered alone. e.g. broken UTF-8 in the name.
  FAILED_CORRUPT,

  // Only used by VerifyUpdate. Indicates that an update is valid. As
  // VerifyUpdate cannot return SUCCESS_STORED, we reuse the value.
  SUCCESS_VALID = SUCCESS_STORED
};

// Different results from the verify phase will yield different methods of
// processing in the ProcessUpdates phase. The SKIP result means the entry
// doesn't go to the ProcessUpdates phase.
enum VerifyResult {
  VERIFY_FAIL,
  VERIFY_SUCCESS,
  VERIFY_UNDELETE,
  VERIFY_SKIP,
  VERIFY_UNDECIDED
};

enum VerifyCommitResult {
  VERIFY_UNSYNCABLE,
  VERIFY_OK,
};

struct SyncerEvent {
  typedef SyncerEvent EventType;

  enum EventCause {
    COMMITS_SUCCEEDED,  // Count is stored in successful_commit_count.

    STATUS_CHANGED,

    // Take care not to wait in shutdown handlers for the syncer to stop as it
    // causes a race in the event system. Use SyncerShutdownEvent instead.
    SHUTDOWN_USE_WITH_CARE,

    // We're over our quota.
    OVER_QUOTA,

    // This event is how the syncer requests that it be synced.
    REQUEST_SYNC_NUDGE,

    // We have reached the SYNCER_END state in the main sync loop.
    // Check the SyncerSession for information like whether we need to continue
    // syncing (SyncerSession::HasMoreToSync).
    SYNC_CYCLE_ENDED,

    // This event is sent when the thread is paused in response to a
    // pause request.
    PAUSED,

    // This event is sent when the thread is resumed in response to a
    // resume request.
    RESUMED,

    // This event is sent when the thread is waiting for a connection
    // to be established.
    WAITING_FOR_CONNECTION,

    // This event is sent when a connection has been established and
    // the thread continues.
    CONNECTED,
  };

  explicit SyncerEvent(EventCause cause) : what_happened(cause),
                                           snapshot(NULL),
                                           successful_commit_count(0),
                                           nudge_delay_milliseconds(0) {}

  static bool IsChannelShutdownEvent(const SyncerEvent& e) {
    return SHUTDOWN_USE_WITH_CARE == e.what_happened;
  }

  // This is used to put SyncerEvents into sorted STL structures.
  bool operator < (const SyncerEvent& r) const {
    return this->what_happened < r.what_happened;
  }

  EventCause what_happened;

  // The last session used for syncing.
  const sessions::SyncSessionSnapshot* snapshot;

  int successful_commit_count;

  // How many milliseconds later should the syncer kick in? For
  // REQUEST_SYNC_NUDGE only.
  int nudge_delay_milliseconds;
};

struct SyncerShutdownEvent {
  SyncerShutdownEvent(Syncer *syncer_ptr) : syncer(syncer_ptr) {}
  Syncer* syncer;
  static bool IsChannelShutdownEvent(Syncer* syncer) {
    return true;
  }
};

typedef Channel<SyncerEvent> SyncerEventChannel;

typedef Channel<SyncerShutdownEvent> ShutdownChannel;

// This struct is passed between parts of the syncer during the processing of
// one sync loop. It lives on the stack. We don't expose the number of
// conflicts during SyncShare as the conflicts may be solved automatically
// by the conflict resolver.
typedef std::vector<syncable::Id> ConflictSet;

typedef std::map<syncable::Id, ConflictSet*> IdToConflictSetMap;

}  // namespace browser_sync

#endif  // CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_