1// Copyright 2012 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#ifndef SYNC_ENGINE_SYNC_ENGINE_EVENT_H_
6#define SYNC_ENGINE_SYNC_ENGINE_EVENT_H_
7
8#include <string>
9
10#include "base/observer_list.h"
11#include "sync/base/sync_export.h"
12#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
13
14namespace syncable {
15class Id;
16}
17
18namespace syncer {
19
20struct SYNC_EXPORT_PRIVATE SyncEngineEvent {
21  enum EventCause {
22    ////////////////////////////////////////////////////////////////
23    // Sent on entry of Syncer state machine
24    SYNC_CYCLE_BEGIN,
25
26    // SyncerCommand generated events.
27    STATUS_CHANGED,
28
29    // We have reached the SYNCER_END state in the main sync loop.
30    SYNC_CYCLE_ENDED,
31
32    ////////////////////////////////////////////////////////////////
33    // Generated in response to specific protocol actions or events.
34
35    // New token in updated_token.
36    UPDATED_TOKEN,
37
38    // This is sent after the Syncer (and SyncerThread) have initiated self
39    // halt due to no longer being permitted to communicate with the server.
40    // The listener should sever the sync / browser connections and delete sync
41    // data (i.e. as if the user clicked 'Stop Syncing' in the browser.
42    STOP_SYNCING_PERMANENTLY,
43
44    // This event is sent when we receive an actionable error. It is upto
45    // the listeners to figure out the action to take using the snapshot sent.
46    ACTIONABLE_ERROR,
47
48    // This event is sent when scheduler decides to wait before next request
49    // either because it gets throttled by server or because it backs off after
50    // request failure. Retry time is passed in retry_time field of event.
51    RETRY_TIME_CHANGED,
52
53    // This event is sent when types are throttled or unthrottled.
54    THROTTLED_TYPES_CHANGED,
55  };
56
57  explicit SyncEngineEvent(EventCause cause);
58  ~SyncEngineEvent();
59
60  EventCause what_happened;
61
62  // The last session used for syncing.
63  sessions::SyncSessionSnapshot snapshot;
64
65  // Update-Client-Auth returns a new token for sync use.
66  std::string updated_token;
67
68  // Time when scheduler will try to send request after backoff.
69  base::Time retry_time;
70
71  // Set of types that are currently throttled.
72  ModelTypeSet throttled_types;
73};
74
75class SYNC_EXPORT_PRIVATE SyncEngineEventListener {
76 public:
77  // TODO(tim): Consider splitting this up to multiple callbacks, rather than
78  // have to do Event e(type); OnSyncEngineEvent(e); at all callsites,
79  virtual void OnSyncEngineEvent(const SyncEngineEvent& event) = 0;
80 protected:
81  virtual ~SyncEngineEventListener() {}
82};
83
84}  // namespace syncer
85
86#endif  // SYNC_ENGINE_SYNC_ENGINE_EVENT_H_
87