sync_merge_result.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
1fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com// Copyright 2012 The Chromium Authors. All rights reserved.
2fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com// Use of this source code is governed by a BSD-style license that can be
3fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com// found in the LICENSE file.
4fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
5fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#ifndef SYNC_API_SYNC_MERGE_RESULT_H_
6fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#define SYNC_API_SYNC_MERGE_RESULT_H_
7b45a1b46ee25e9b19800b028bb1ca925212ac7b4caryclark@google.com
8fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "sync/api/sync_error.h"
9fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "sync/base/sync_export.h"
10fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com#include "sync/internal_api/public/base/model_type.h"
11fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
1215fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.comnamespace syncer {
1315fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.com
1415fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.com// A model-type-specific view of a sync merge. This class encapsulates the
15b45a1b46ee25e9b19800b028bb1ca925212ac7b4caryclark@google.com// state before and after the merge as well as the deltas and any error that
16b45a1b46ee25e9b19800b028bb1ca925212ac7b4caryclark@google.com// occurred.
1715fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.com// Note: This class only tracks one side of the merge. In other words, if built
1815fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.com// by the local SyncableService, all values correspond to the local state before
1915fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.com// and after merging, and the delta's applied to that state. Sync's change
2047580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com// processor will create a separate merge result.
2115fa138f2276a77679530fb608463ff5b4133f7bcaryclark@google.comclass SYNC_EXPORT SyncMergeResult {
22fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com public:
2347580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  // Initialize an empty merge result for model type |type|.
2447580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  explicit SyncMergeResult(ModelType type);
2547580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  ~SyncMergeResult();
2647580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com
27d0deb4fa612a44adb941025af52c5179c5d11cd7caryclark@google.com  // Default copy and assign welcome.
2847580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com
29f839c0359c308fd06895d9f73fc12c4f3869e399caryclark@google.com  // Setters.
300b7da433fe0eaa2833d1b2900715b013b36d93dacaryclark@google.com  // Note: if |error.IsSet()| is true, |error.type()| must match model_type_
31a461ff0866526bc51dbd4c4f9f066a727ec21510caryclark@google.com  void set_error(SyncError error);
3247580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  void set_num_items_before_association(int num_items_before_association);
33e7bd5f4041701cbab87f6e779eb18fbb9fe74216caryclark@google.com  void set_num_items_after_association(int num_items_after_association);
3447580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  void set_num_items_added(int num_items_added);
3531143cf37fa38dc98f71c71e518ecc21c83b5e27caryclark@google.com  void set_num_items_deleted(int num_items_deleted);
36fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com  void set_num_items_modified(int num_items_modified);
3747580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  void set_pre_association_version(int64 version);
38fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
3947580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  // Getters.
404eeda37a7456876cb8d509a4ea43c7f4c684477acaryclark@google.com  ModelType model_type() const;
41fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com  SyncError error() const;
4247580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  int num_items_before_association() const;
43c899ad9c7fa28234d99479ab09afb6866bbd8dc3caryclark@google.com  int num_items_after_association() const;
44e7bd5f4041701cbab87f6e779eb18fbb9fe74216caryclark@google.com  int num_items_added() const;
4547580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  int num_items_deleted() const;
468dcf114db9762c02d217beba6e29dffa4e92d298caryclark@google.com  int num_items_modified() const;
47e7bd5f4041701cbab87f6e779eb18fbb9fe74216caryclark@google.com  int64 pre_association_version() const;
4847580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com
49f839c0359c308fd06895d9f73fc12c4f3869e399caryclark@google.com private:
50729e1c46cea63dfaa6e4a05608b8f3be41e19dcecaryclark@google.com  // Make |this| into a copy of |other|.
5147580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  void CopyFrom(const SyncMergeResult& other);
52afe56de6361a81eef537ddd8f6d5626c8546d4c7caryclark@google.com
538dcf114db9762c02d217beba6e29dffa4e92d298caryclark@google.com  // The datatype that was associated.
54fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com  ModelType model_type_;
55fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
56fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com  // The error encountered during association. Unset if no error was
5747580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  // encountered.
58fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com  SyncError error_;
59c91dfe417a51f73c28ecf2708df1e0bee942c6eacaryclark@google.com
604eeda37a7456876cb8d509a4ea43c7f4c684477acaryclark@google.com  // The state of the world before association.
616aea33f92c611d6fdc88bc2352c5c966168af83bcaryclark@google.com  int num_items_before_association_;
626aea33f92c611d6fdc88bc2352c5c966168af83bcaryclark@google.com
633350c3c68ab75cd08721da3a938b8d2b10096d70caryclark@google.com  // The state of the world after association.
64e7bd5f4041701cbab87f6e779eb18fbb9fe74216caryclark@google.com  int num_items_after_association_;
653350c3c68ab75cd08721da3a938b8d2b10096d70caryclark@google.com
66534aa5b9460639a09b9dc30d29e77782e44b8fffcaryclark@google.com  // The changes that took place during association. In a correctly working
67e7bd5f4041701cbab87f6e779eb18fbb9fe74216caryclark@google.com  // system these should be the deltas between before and after.
683350c3c68ab75cd08721da3a938b8d2b10096d70caryclark@google.com  int num_items_added_;
6965f9f0a1664a9cb38157ccfbcc3e0e936af0a58ecaryclark@google.com  int num_items_deleted_;
70729e1c46cea63dfaa6e4a05608b8f3be41e19dcecaryclark@google.com  int num_items_modified_;
7147580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com
72afe56de6361a81eef537ddd8f6d5626c8546d4c7caryclark@google.com  // Version of model before association.
7347580694fbe974a065caf7c39c3d2075708c2018caryclark@google.com  int64 pre_association_version_;
74fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com};
75fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com
76fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com}  // namespace syncer
776aea33f92c611d6fdc88bc2352c5c966168af83bcaryclark@google.com
78027de226c144d9e6b7a76acb2e904952b5620a5ecaryclark@google.com#endif  // SYNC_API_SYNC_MERGE_RESULT_H_
79fa0588ff672564af1c235a63589573829035a60bcaryclark@google.com