Home | History | Annotate | Download | only in engine
      1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_
      6 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_
      7 #pragma once
      8 
      9 #include <map>
     10 #include <vector>
     11 
     12 #include "base/observer_list.h"
     13 #include "chrome/browser/sync/syncable/model_type.h"
     14 
     15 namespace syncable {
     16 class BaseTransaction;
     17 class Id;
     18 }
     19 
     20 // The intent of this is to keep all shared data types and enums for the syncer
     21 // in a single place without having dependencies between other files.
     22 namespace browser_sync {
     23 
     24 namespace sessions {
     25 struct SyncSessionSnapshot;
     26 }
     27 class Syncer;
     28 
     29 enum UpdateAttemptResponse {
     30   // Update was applied or safely ignored.
     31   SUCCESS,
     32 
     33   // Conflicts with the local data representation. This can also mean that the
     34   // entry doesn't currently make sense if we applied it.
     35   CONFLICT,
     36 };
     37 
     38 enum ServerUpdateProcessingResult {
     39   // Success. Update applied and stored in SERVER_* fields or dropped if
     40   // irrelevant.
     41   SUCCESS_PROCESSED,
     42 
     43   // Success. Update details stored in SERVER_* fields, but wasn't applied.
     44   SUCCESS_STORED,
     45 
     46   // Update is illegally inconsistent with earlier updates. e.g. A bookmark
     47   // becoming a folder.
     48   FAILED_INCONSISTENT,
     49 
     50   // Update is illegal when considered alone. e.g. broken UTF-8 in the name.
     51   FAILED_CORRUPT,
     52 
     53   // Only used by VerifyUpdate. Indicates that an update is valid. As
     54   // VerifyUpdate cannot return SUCCESS_STORED, we reuse the value.
     55   SUCCESS_VALID = SUCCESS_STORED
     56 };
     57 
     58 // Different results from the verify phase will yield different methods of
     59 // processing in the ProcessUpdates phase. The SKIP result means the entry
     60 // doesn't go to the ProcessUpdates phase.
     61 enum VerifyResult {
     62   VERIFY_FAIL,
     63   VERIFY_SUCCESS,
     64   VERIFY_UNDELETE,
     65   VERIFY_SKIP,
     66   VERIFY_UNDECIDED
     67 };
     68 
     69 enum VerifyCommitResult {
     70   VERIFY_UNSYNCABLE,
     71   VERIFY_OK,
     72 };
     73 
     74 struct SyncEngineEvent {
     75   enum EventCause {
     76     ////////////////////////////////////////////////////////////////
     77     // SyncerCommand generated events.
     78     STATUS_CHANGED,
     79 
     80     // We have reached the SYNCER_END state in the main sync loop.
     81     // Check the SyncerSession for information like whether we need to continue
     82     // syncing (SyncerSession::HasMoreToSync).
     83     SYNC_CYCLE_ENDED,
     84 
     85     ////////////////////////////////////////////////////////////////
     86     // Generated in response to specific protocol actions or events.
     87 
     88     // New token in updated_token.
     89     UPDATED_TOKEN,
     90 
     91     // This is sent after the Syncer (and SyncerThread) have initiated self
     92     // halt due to no longer being permitted to communicate with the server.
     93     // The listener should sever the sync / browser connections and delete sync
     94     // data (i.e. as if the user clicked 'Stop Syncing' in the browser.
     95     STOP_SYNCING_PERMANENTLY,
     96 
     97     // These events are sent to indicate when we know the clearing of
     98     // server data have failed or succeeded.
     99     CLEAR_SERVER_DATA_SUCCEEDED,
    100     CLEAR_SERVER_DATA_FAILED,
    101   };
    102 
    103   explicit SyncEngineEvent(EventCause cause);
    104   ~SyncEngineEvent();
    105 
    106   EventCause what_happened;
    107 
    108   // The last session used for syncing.
    109   const sessions::SyncSessionSnapshot* snapshot;
    110 
    111   // Update-Client-Auth returns a new token for sync use.
    112   std::string updated_token;
    113 };
    114 
    115 class SyncEngineEventListener {
    116  public:
    117   // TODO(tim): Consider splitting this up to multiple callbacks, rather than
    118   // have to do Event e(type); OnSyncEngineEvent(e); at all callsites,
    119   virtual void OnSyncEngineEvent(const SyncEngineEvent& event) = 0;
    120  protected:
    121   virtual ~SyncEngineEventListener() {}
    122 };
    123 
    124 // This struct is passed between parts of the syncer during the processing of
    125 // one sync loop. It lives on the stack. We don't expose the number of
    126 // conflicts during SyncShare as the conflicts may be solved automatically
    127 // by the conflict resolver.
    128 typedef std::vector<syncable::Id> ConflictSet;
    129 
    130 typedef std::map<syncable::Id, ConflictSet*> IdToConflictSetMap;
    131 
    132 }  // namespace browser_sync
    133 
    134 #endif  // CHROME_BROWSER_SYNC_ENGINE_SYNCER_TYPES_H_
    135