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