Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/sync/api/sync_data.h

Issue 6995008: Implement new SyncAPI and convert Preferences to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and fix compile Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/api/sync_change_unittest.cc ('k') | chrome/browser/sync/api/sync_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_API_SYNC_DATA_H_
6 #define CHROME_BROWSER_SYNC_API_SYNC_DATA_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/sync/syncable/model_type.h"
15
16 namespace sync_pb {
17 class EntitySpecifics;
18 class SyncEntity;
19 }
20
21 typedef syncable::ModelType SyncDataType;
22
23 // A light-weight container for immutable sync data. Pass-by-value and storage
24 // in STL containers are supported and encouraged if helpful.
25 class SyncData {
26 public:
27 // Creates an empty and invalid SyncData.
28 SyncData();
29 ~SyncData();
30
31 // Default copy and assign welcome.
32
33 // Helper methods for creating SyncData objects for local data.
34 // Local sync data must always at least set the sync tag.
35 static SyncData CreateLocalData(const std::string& sync_tag);
36 static SyncData CreateLocalData(
37 const std::string& sync_tag,
38 const sync_pb::EntitySpecifics& specifics);
39
40 // Helper method for creating SyncData objects originating from the syncer.
41 static SyncData CreateRemoteData(
42 const sync_pb::SyncEntity& entity);
43 static SyncData CreateRemoteData(
44 const sync_pb::EntitySpecifics& specifics);
45
46 // Whether this SyncData holds valid data. The only way to have a SyncData
47 // without valid data is to use the default constructor.
48 bool IsValid() const;
49 // Return the datatype we're holding information about. Derived from the sync
50 // datatype specifics.
51 SyncDataType GetDataType() const;
52 // Return the current sync datatype specifics.
53 const sync_pb::EntitySpecifics& GetSpecifics() const;
54 // Returns the value of the unique client tag. This is only set for data going
55 // TO the syncer, not coming from.
56 const std::string& GetTag() const;
57 // Whether this sync data is for local data or data coming from the syncer.
58 bool IsLocal() const;
59
60 // TODO(zea): Query methods for other sync properties: title, parent,
61 // successor, etc. Possibly support for hashed tag and sync id?
62
63 private:
64 // A reference counted immutable SyncEntity.
65 class SharedSyncEntity : public
66 base::RefCountedThreadSafe<SharedSyncEntity> {
67 public:
68 // Takes ownership of |sync_entity|'s contents.
69 explicit SharedSyncEntity(sync_pb::SyncEntity* sync_entity);
70
71 // Returns immutable reference to local sync entity.
72 const sync_pb::SyncEntity& sync_entity() const;
73
74 private:
75 friend class base::RefCountedThreadSafe<SharedSyncEntity>;
76
77 // Private due to ref counting.
78 ~SharedSyncEntity();
79
80 scoped_ptr<sync_pb::SyncEntity> sync_entity_;
81 };
82
83 // The actual shared sync entity being held.
84 scoped_refptr<SharedSyncEntity> shared_entity_;
85
86 // Whether this data originated locally or from the syncer (remote data).
87 bool is_local_;
88 };
89
90 #endif // CHROME_BROWSER_SYNC_API_SYNC_DATA_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/api/sync_change_unittest.cc ('k') | chrome/browser/sync/api/sync_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698