Home | History | Annotate | Download | only in api
      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_API_SYNC_MERGE_RESULT_H_
      6 #define SYNC_API_SYNC_MERGE_RESULT_H_
      7 
      8 #include "sync/api/sync_error.h"
      9 #include "sync/base/sync_export.h"
     10 #include "sync/internal_api/public/base/model_type.h"
     11 
     12 namespace syncer {
     13 
     14 // A model-type-specific view of a sync merge. This class encapsulates the
     15 // state before and after the merge as well as the deltas and any error that
     16 // occurred.
     17 // Note: This class only tracks one side of the merge. In other words, if built
     18 // by the local SyncableService, all values correspond to the local state before
     19 // and after merging, and the delta's applied to that state. Sync's change
     20 // processor will create a separate merge result.
     21 class SYNC_EXPORT SyncMergeResult {
     22  public:
     23   // Initialize an empty merge result for model type |type|.
     24   explicit SyncMergeResult(ModelType type);
     25   ~SyncMergeResult();
     26 
     27   // Default copy and assign welcome.
     28 
     29   // Setters.
     30   // Note: if |error.IsSet()| is true, |error.type()| must match model_type_
     31   void set_error(SyncError error);
     32   void set_num_items_before_association(int num_items_before_association);
     33   void set_num_items_after_association(int num_items_after_association);
     34   void set_num_items_added(int num_items_added);
     35   void set_num_items_deleted(int num_items_deleted);
     36   void set_num_items_modified(int num_items_modified);
     37   void set_pre_association_version(int64 version);
     38 
     39   // Getters.
     40   ModelType model_type() const;
     41   SyncError error() const;
     42   int num_items_before_association() const;
     43   int num_items_after_association() const;
     44   int num_items_added() const;
     45   int num_items_deleted() const;
     46   int num_items_modified() const;
     47   int64 pre_association_version() const;
     48 
     49  private:
     50   // Make |this| into a copy of |other|.
     51   void CopyFrom(const SyncMergeResult& other);
     52 
     53   // The datatype that was associated.
     54   ModelType model_type_;
     55 
     56   // The error encountered during association. Unset if no error was
     57   // encountered.
     58   SyncError error_;
     59 
     60   // The state of the world before association.
     61   int num_items_before_association_;
     62 
     63   // The state of the world after association.
     64   int num_items_after_association_;
     65 
     66   // The changes that took place during association. In a correctly working
     67   // system these should be the deltas between before and after.
     68   int num_items_added_;
     69   int num_items_deleted_;
     70   int num_items_modified_;
     71 
     72   // Version of model before association.
     73   int64 pre_association_version_;
     74 };
     75 
     76 }  // namespace syncer
     77 
     78 #endif  // SYNC_API_SYNC_MERGE_RESULT_H_
     79