Index: sync/test/fake_server/fake_server.h |
diff --git a/sync/test/fake_server/fake_server.h b/sync/test/fake_server/fake_server.h |
index 0621bbc46a10045a77dfe04e84faff659df819bc..6af77abbef9eb8c59d84cc635075ddcfb37900f5 100644 |
--- a/sync/test/fake_server/fake_server.h |
+++ b/sync/test/fake_server/fake_server.h |
@@ -7,10 +7,12 @@ |
#include <map> |
#include <string> |
+#include <vector> |
#include "base/basictypes.h" |
+#include "base/callback.h" |
#include "base/memory/scoped_ptr.h" |
-#include "base/synchronization/lock.h" |
+#include "base/observer_list.h" |
#include "base/values.h" |
#include "sync/internal_api/public/base/model_type.h" |
#include "sync/protocol/sync.pb.h" |
@@ -21,15 +23,26 @@ namespace fake_server { |
// A fake version of the Sync server used for testing. |
class FakeServer { |
public: |
+ typedef base::Callback<void(int, int, const std::string&)> |
+ HandleCommandCallback; |
+ |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // Called after FakeServer has processed a successful commit. The types |
+ // updated as part of the commit are passed in |committed_model_types|. |
+ virtual void OnCommit(syncer::ModelTypeSet committed_model_types) = 0; |
+ }; |
+ |
FakeServer(); |
virtual ~FakeServer(); |
- // Handles a /command POST to the server. If the return value is 0 (success), |
- // |response_code| and |response| will be set. Otherwise, the return value |
- // will be a network error code. |
- int HandleCommand(const std::string& request, |
- int* response_code, |
- std::string* response); |
+ // Asynchronously handles a /command POST to the server. If the error_code is |
+ // passed to |callback| is 0 (success), the POST's response code and content |
+ // will also be passed. |
+ void HandleCommand(const std::string& request, |
+ const HandleCommandCallback& callback); |
// Creates a DicionaryValue representation of all entities present in the |
// server. The dictionary keys are the strings generated by ModelTypeToString |
@@ -37,6 +50,14 @@ class FakeServer { |
// names. |
scoped_ptr<base::DictionaryValue> GetEntitiesAsDictionaryValue(); |
+ // Adds |observer| to FakeServer's observer list. This should be called |
+ // before the Profile associated with |observer| is connected to the server. |
+ void AddObserver(Observer* observer); |
+ |
+ // Removes |observer| from the FakeServer's observer list. This method |
+ // must be called if AddObserver was ever called with |observer|. |
+ void RemoveObserver(Observer* observer); |
+ |
private: |
typedef std::map<std::string, FakeServerEntity*> EntityMap; |
@@ -59,14 +80,15 @@ class FakeServer { |
void SaveEntity(FakeServerEntity* entity); |
// Commits a client-side SyncEntity to the server as a FakeServerEntity. |
- // The client that sent the commit is identified via |client_guid| and all |
- // entity ID renaming is tracked with |client_to_server_ids|. If the commit |
- // is successful, true is returned and the server's version of the SyncEntity |
- // is stored in |server_entity|. |
- bool CommitEntity(const sync_pb::SyncEntity& client_entity, |
- sync_pb::CommitResponse_EntryResponse* entry_response, |
- std::string client_guid, |
- std::map<std::string, std::string>* client_to_server_ids); |
+ // The client that sent the commit is identified via |client_guid|. The |
+ // parent ID string present in |client_entity| should be ignored in favor |
+ // of |parent_id|. If the commit is successful, the entity's server ID string |
+ // is returned and a new FakeServerEntity is saved in |entities_|. |
+ std::string CommitEntity( |
+ const sync_pb::SyncEntity& client_entity, |
+ sync_pb::CommitResponse_EntryResponse* entry_response, |
+ std::string client_guid, |
+ std::string parent_id); |
// Populates |entry_response| based on |entity|. It is assumed that |
// SaveEntity has already been called on |entity|. |
@@ -82,14 +104,6 @@ class FakeServer { |
// |id|. A tombstone is not created for the entity itself. |
bool DeleteChildren(const std::string& id); |
- // The lock used to ensure that only one client is communicating with server |
- // at any given time. |
- // |
- // It is probably preferable to have FakeServer operate on its own thread and |
- // communicate with it via PostTask, but clients would still need to wait for |
- // requests to finish before proceeding. |
- base::Lock lock_; |
- |
// This is the last version number assigned to an entity. The next entity will |
// have a version number of version_ + 1. |
int64 version_; |
@@ -108,6 +122,9 @@ class FakeServer { |
// are kept track of so that permanent entities are not recreated for new |
// clients. |
syncer::ModelTypeSet created_permanent_entity_types_; |
+ |
+ // FakeServer's observers. |
+ ObserverList<Observer, true> observers_; |
}; |
} // namespace fake_server |