Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_INTERNAL_API_PUBLIC_TEST_FAKE_SERVER_H_ | |
| 6 #define SYNC_INTERNAL_API_PUBLIC_TEST_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 // An in-process implementation of the Sync server used for testing. | |
|
Raghu Simha
2013/12/18 22:37:12
Desktop in-process browser tests already have the
pval...(no longer on Chromium)
2013/12/19 01:16:56
I modified this comment to remove the mention of r
| |
| 19 class FakeServer { | |
|
rlarocque
2013/12/18 20:22:01
General comment:
I think you'll find it easier in
pval...(no longer on Chromium)
2013/12/19 01:16:56
This makes sense. For this CL, I'll keep this as i
| |
| 20 public: | |
| 21 FakeServer(); | |
| 22 virtual ~FakeServer(); | |
| 23 | |
| 24 // Initializes the fake server. The server is not able to process requests | |
| 25 // before this is called and returns true. | |
| 26 bool Init(); | |
| 27 | |
| 28 // Handles a /command POST to the server and returns the response as a string. | |
| 29 // |error_code| and |response_code| are also set. | |
| 30 std::string HandleCommand(std::string request, int* error_code, | |
|
rlarocque
2013/12/18 20:22:01
nit: one parameter per line.
http://www.chromium.
pval...(no longer on Chromium)
2013/12/19 01:16:56
Done.
| |
| 31 int* response_code); | |
| 32 | |
| 33 private: | |
| 34 // A filter used during GetUpdates calls to determine what information to | |
| 35 // send back to the client. There is a 1:1 correspondence between any given | |
| 36 // GetUpdates call and an UpdateSieve instance. | |
| 37 class UpdateSieve { | |
|
rlarocque
2013/12/18 20:22:01
I see few advantages to using inner-classes in C++
pval...(no longer on Chromium)
2013/12/19 01:16:56
Done.
| |
| 38 public: | |
| 39 // Populates |state_| based on |get_updates_message|. | |
| 40 UpdateSieve(const sync_pb::GetUpdatesMessage& get_updates_message); | |
| 41 | |
| 42 ~UpdateSieve(); | |
| 43 | |
| 44 // Sets the progress markers in |get_updates_response| given the progress | |
| 45 // markers from |get_updates_message_| and |new_version| (the latest | |
| 46 // version in the entries sent back). | |
| 47 void UpdateProgressMarkers( | |
| 48 int64 new_version, | |
| 49 sync_pb::GetUpdatesResponse* get_updates_response); | |
| 50 | |
| 51 // Determines whether the server should send |entity| to the client based | |
| 52 // on its type and version. | |
| 53 bool ClientWantsItem(const sync_pb::SyncEntity& entity); | |
| 54 | |
| 55 // Returns the mininum version seen across all types. | |
| 56 int64 GetMinVersion(); | |
| 57 | |
| 58 // Returns the data type IDs of types being synced for the first time. | |
| 59 std::vector<int> GetFirstTimeTypes(); | |
| 60 | |
| 61 private: | |
| 62 typedef std::map<int, int64> TypeIdToVersionMap; | |
|
rlarocque
2013/12/18 20:22:01
Since we're in C++ land and you have the classes a
pval...(no longer on Chromium)
2013/12/19 01:16:56
Done.
| |
| 63 | |
| 64 // The GetUpdatesMessage associated with this instance. | |
| 65 const sync_pb::GetUpdatesMessage& get_updates_message_; | |
| 66 | |
| 67 // Maps data type IDs to the latest version seen for that version. | |
|
rlarocque
2013/12/18 20:22:01
"version seen for that version" -> typo?
pval...(no longer on Chromium)
2013/12/19 01:16:56
Done.
| |
| 68 TypeIdToVersionMap state_; | |
|
rlarocque
2013/12/18 20:22:01
state_ is not a very informative name. How about:
pval...(no longer on Chromium)
2013/12/19 01:16:56
how about type_latest_version_?
| |
| 69 | |
| 70 // The minimum version seen among all data types. | |
| 71 int min_version_; | |
| 72 }; | |
| 73 | |
| 74 // The data necessary for the server to create a permanent item. | |
| 75 struct PermanentItemSpec { | |
| 76 std::string tag; | |
| 77 std::string name; | |
| 78 std::string parent_tag; | |
| 79 ModelType sync_type; | |
| 80 bool create_by_default; | |
| 81 }; | |
| 82 | |
| 83 typedef std::map<std::string, sync_pb::SyncEntity> EntityMap; | |
| 84 | |
| 85 // Processes a GetUpdates call. | |
| 86 sync_pb::ClientToServerResponse HandleGetUpdatesRequest( | |
| 87 const sync_pb::ClientToServerMessage& message); | |
| 88 | |
| 89 // Processes a Commit call. | |
| 90 sync_pb::ClientToServerResponse HandleCommitRequest( | |
| 91 const sync_pb::ClientToServerMessage& message); | |
| 92 | |
| 93 // Initializes |permanent_item_specs_|. | |
| 94 bool PopulatePermanentItemSpecs(); | |
| 95 | |
| 96 // Inserts the appropriate permanent items in |entities_|. | |
| 97 void CreateDefaultPermanentItems(const std::vector<int>& first_time_type_ids); | |
| 98 | |
| 99 // Creates and saves a permanent item based on |spec|. | |
| 100 void CreatePermanentItem(const PermanentItemSpec& spec); | |
| 101 | |
| 102 // Saves a |entity| to |entities_|. | |
| 103 void SaveEntity(sync_pb::SyncEntity entity); | |
| 104 | |
| 105 // Commits a client-side |entity| to |entities_|. | |
| 106 sync_pb::SyncEntity CommitEntity(sync_pb::SyncEntity entity, | |
| 107 std::string guid); | |
| 108 | |
| 109 // Whether the server has been initialized and is ready to process requests. | |
| 110 bool initialized_; | |
| 111 | |
| 112 // The collection of PermanentItemSpecs created at runtime. | |
| 113 std::vector<PermanentItemSpec> permanent_item_specs_; | |
| 114 | |
| 115 // This is the last version number assigned to an entity. The next entity will | |
| 116 // have a version number of version_ + 1. | |
| 117 int64 version_; | |
| 118 | |
| 119 // The current birthday value. | |
| 120 std::string birthday_; | |
| 121 | |
| 122 // All SyncEntity objects saved by the server. The key value is the entity's | |
| 123 // id string. | |
| 124 EntityMap entities_; | |
| 125 | |
| 126 // All Keystore keys knwon to the server. | |
| 127 std::vector<std::string> keystore_keys_; | |
| 128 }; | |
| 129 | |
| 130 } // namespace syncer | |
| 131 | |
| 132 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SERVER_H_ | |
| OLD | NEW |