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

Side by Side Diff: sync/test/fake_server/fake_server.h

Issue 115243007: Basic implementation of the Sync C++ fake server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move files Created 6 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2013 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_TEST_FAKE_SERVER_FAKE_SERVER_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "sync/internal_api/public/base/model_type.h"
14 #include "sync/protocol/sync.pb.h"
15
16 namespace syncer {
17
18 // A fake version of the Sync server used for testing.
19 class FakeServer {
20 public:
21 FakeServer();
22 virtual ~FakeServer();
23
24 // Handles a /command POST to the server. If the return value is 0 (success),
25 // |response_code| and |response| will be set. Otherwise, the return value
26 // will be a network error code.
27 int HandleCommand(std::string request,
28 int* response_code,
29 std::string* response);
30
31 private:
32 typedef std::map<std::string, sync_pb::SyncEntity> EntityMap;
33
34 // Processes a GetUpdates call.
35 sync_pb::ClientToServerResponse HandleGetUpdatesRequest(
36 const sync_pb::ClientToServerMessage& message);
37
38 // Processes a Commit call.
39 sync_pb::ClientToServerResponse HandleCommitRequest(
40 const sync_pb::ClientToServerMessage& message);
41
42 // Inserts the appropriate permanent items in |entities_|.
43 void CreateDefaultPermanentItems(
44 const std::vector<ModelType>& first_time_types);
45
46 // Creates and saves a SyncEntity of the given |model_type|. The entity's
47 // id_string and server_defined_unique_tag fields are set to |id|. The
48 // non_unique_name and name fields are set to |name|. Since tags are used as
49 // ids, the parent_id_string field is set to |parent_tag|.
50 void CreateSyncEntity(ModelType model_type,
51 const std::string& id,
52 const std::string& name,
53 const std::string& parent_tag);
54
55 // Saves a |entity| to |entities_|.
56 void SaveEntity(sync_pb::SyncEntity entity);
57
58 // Commits a client-side |entity| to |entities_|.
59 sync_pb::SyncEntity CommitEntity(sync_pb::SyncEntity entity,
60 std::string guid);
61
62 // This is the last version number assigned to an entity. The next entity will
63 // have a version number of version_ + 1.
64 int64 version_;
65
66 // The current birthday value.
67 std::string birthday_;
68
69 // All SyncEntity objects saved by the server. The key value is the entity's
70 // id string.
71 EntityMap entities_;
72
73 // All Keystore keys known to the server.
74 std::vector<std::string> keystore_keys_;
75 };
76
77 } // namespace syncer
78
79 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698