sync_engine_event.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 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/internal_api/public/sessions/sync_session_snapshot.h"
12
13namespace syncable {
14class Id;
15}
16
17namespace syncer {
18
19struct SyncEngineEvent {
20  enum EventCause {
21    ////////////////////////////////////////////////////////////////
22    // Sent on entry of Syncer state machine
23    SYNC_CYCLE_BEGIN,
24
25    // SyncerCommand generated events.
26    STATUS_CHANGED,
27
28    // We have reached the SYNCER_END state in the main sync loop.
29    SYNC_CYCLE_ENDED,
30
31    ////////////////////////////////////////////////////////////////
32    // Generated in response to specific protocol actions or events.
33
34    // New token in updated_token.
35    UPDATED_TOKEN,
36
37    // This is sent after the Syncer (and SyncerThread) have initiated self
38    // halt due to no longer being permitted to communicate with the server.
39    // The listener should sever the sync / browser connections and delete sync
40    // data (i.e. as if the user clicked 'Stop Syncing' in the browser.
41    STOP_SYNCING_PERMANENTLY,
42
43    // This event is sent when we receive an actionable error. It is upto
44    // the listeners to figure out the action to take using the snapshot sent.
45    ACTIONABLE_ERROR,
46  };
47
48  explicit SyncEngineEvent(EventCause cause);
49  ~SyncEngineEvent();
50
51  EventCause what_happened;
52
53  // The last session used for syncing.
54  sessions::SyncSessionSnapshot snapshot;
55
56  // Update-Client-Auth returns a new token for sync use.
57  std::string updated_token;
58};
59
60class SyncEngineEventListener {
61 public:
62  // TODO(tim): Consider splitting this up to multiple callbacks, rather than
63  // have to do Event e(type); OnSyncEngineEvent(e); at all callsites,
64  virtual void OnSyncEngineEvent(const SyncEngineEvent& event) = 0;
65 protected:
66  virtual ~SyncEngineEventListener() {}
67};
68
69}  // namespace syncer
70
71#endif  // SYNC_ENGINE_SYNC_ENGINE_EVENT_H_
72