Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
| 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Puts the server in a state where it acts as if authentication has | 65 // Puts the server in a state where it acts as if authentication has |
| 66 // succeeded. | 66 // succeeded. |
| 67 void SetAuthenticated(); | 67 void SetAuthenticated(); |
| 68 | 68 |
| 69 // Puts the server in a state where all commands will fail with an | 69 // Puts the server in a state where all commands will fail with an |
| 70 // authentication error. | 70 // authentication error. |
| 71 void SetUnauthenticated(); | 71 void SetUnauthenticated(); |
| 72 | 72 |
| 73 // Force the server to return |error_type| in the error_code field of | 73 // Force the server to return |error_type| in the error_code field of |
| 74 // ClientToServerResponse on all subsequent sync requests. This method should | 74 // ClientToServerResponse on all subsequent sync requests. This method should |
| 75 // not be called if TriggerActionableError has previously been called. | 75 // not be called if TriggerActionableError has previously been called. Returns |
| 76 // TODO(pvalenzuela): Return a bool here to indicate whether the call | 76 // true if error triggering was successfully configured. |
| 77 // succeeded. | 77 bool TriggerError(const sync_pb::SyncEnums::ErrorType& error_type); |
| 78 void TriggerError(const sync_pb::SyncEnums::ErrorType& error_type); | |
| 79 | 78 |
| 80 // Force the server to return the given data as part of the error field of | 79 // Force the server to return the given data as part of the error field of |
| 81 // ClientToServerResponse on all subsequent sync requests. This method should | 80 // ClientToServerResponse on all subsequent sync requests. This method should |
| 82 // not be called if TriggerError has previously been called. | 81 // not be called if TriggerError has previously been called. Returns true if |
| 82 // error triggering was successfully configured. | |
| 83 bool TriggerActionableError( | 83 bool TriggerActionableError( |
| 84 const sync_pb::SyncEnums::ErrorType& error_type, | 84 const sync_pb::SyncEnums::ErrorType& error_type, |
| 85 const std::string& description, | 85 const std::string& description, |
| 86 const std::string& url, | 86 const std::string& url, |
| 87 const sync_pb::SyncEnums::Action& action); | 87 const sync_pb::SyncEnums::Action& action); |
| 88 | 88 |
| 89 // Instructs the server to send triggered errors on every other request | |
| 90 // (starting with the first one after this call). This method should only be | |
| 91 // called after a call to TriggerError or TriggerActionableError. Returns true | |
| 92 // if triggered error alternating was successful. | |
|
Nicolas Zea
2014/10/10 23:51:09
Comment why you might want to use this?
pval...(no longer on Chromium)
2014/10/14 17:26:04
Done.
| |
| 93 bool EnableAlternatingTriggeredErrors(); | |
| 94 | |
| 89 // Adds |observer| to FakeServer's observer list. This should be called | 95 // Adds |observer| to FakeServer's observer list. This should be called |
| 90 // before the Profile associated with |observer| is connected to the server. | 96 // before the Profile associated with |observer| is connected to the server. |
| 91 void AddObserver(Observer* observer); | 97 void AddObserver(Observer* observer); |
| 92 | 98 |
| 93 // Removes |observer| from the FakeServer's observer list. This method | 99 // Removes |observer| from the FakeServer's observer list. This method |
| 94 // must be called if AddObserver was ever called with |observer|. | 100 // must be called if AddObserver was ever called with |observer|. |
| 95 void RemoveObserver(Observer* observer); | 101 void RemoveObserver(Observer* observer); |
| 96 | 102 |
| 97 private: | 103 private: |
| 98 typedef std::map<std::string, FakeServerEntity*> EntityMap; | 104 typedef std::map<std::string, FakeServerEntity*> EntityMap; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 FakeServerEntity* entity); | 139 FakeServerEntity* entity); |
| 134 | 140 |
| 135 // Determines whether the SyncEntity with id_string |id| is a child of an | 141 // Determines whether the SyncEntity with id_string |id| is a child of an |
| 136 // entity with id_string |potential_parent_id|. | 142 // entity with id_string |potential_parent_id|. |
| 137 bool IsChild(const std::string& id, const std::string& potential_parent_id); | 143 bool IsChild(const std::string& id, const std::string& potential_parent_id); |
| 138 | 144 |
| 139 // Creates and saves tombstones for all children of the entity with the given | 145 // Creates and saves tombstones for all children of the entity with the given |
| 140 // |id|. A tombstone is not created for the entity itself. | 146 // |id|. A tombstone is not created for the entity itself. |
| 141 bool DeleteChildren(const std::string& id); | 147 bool DeleteChildren(const std::string& id); |
| 142 | 148 |
| 149 // Returns whether a triggered error should be sent for the request. | |
| 150 bool ShouldSendTriggeredError() const; | |
| 151 | |
| 143 // This is the last version number assigned to an entity. The next entity will | 152 // This is the last version number assigned to an entity. The next entity will |
| 144 // have a version number of version_ + 1. | 153 // have a version number of version_ + 1. |
| 145 int64 version_; | 154 int64 version_; |
| 146 | 155 |
| 147 // The current store birthday value. | 156 // The current store birthday value. |
| 148 std::string store_birthday_; | 157 std::string store_birthday_; |
| 149 | 158 |
| 150 // Whether the server should act as if incoming connections are properly | 159 // Whether the server should act as if incoming connections are properly |
| 151 // authenticated. | 160 // authenticated. |
| 152 bool authenticated_; | 161 bool authenticated_; |
| 153 | 162 |
| 154 // All SyncEntity objects saved by the server. The key value is the entity's | 163 // All SyncEntity objects saved by the server. The key value is the entity's |
| 155 // id string. | 164 // id string. |
| 156 EntityMap entities_; | 165 EntityMap entities_; |
| 157 | 166 |
| 158 // All Keystore keys known to the server. | 167 // All Keystore keys known to the server. |
| 159 std::vector<std::string> keystore_keys_; | 168 std::vector<std::string> keystore_keys_; |
| 160 | 169 |
| 161 // Used as the error_code field of ClientToServerResponse on all responses | 170 // Used as the error_code field of ClientToServerResponse on all responses |
| 162 // except when |triggered_actionable_error_| is set. | 171 // except when |triggered_actionable_error_| is set. |
| 163 sync_pb::SyncEnums::ErrorType error_type_; | 172 sync_pb::SyncEnums::ErrorType error_type_; |
| 164 | 173 |
| 165 // Used as the error field of ClientToServerResponse when its pointer is not | 174 // Used as the error field of ClientToServerResponse when its pointer is not |
| 166 // NULL. | 175 // NULL. |
| 167 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; | 176 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; |
| 168 | 177 |
| 178 // These values are used in tandem to return a triggered error (either | |
| 179 // |error_type_| or |triggered_actionable_error_|) on every other request. | |
| 180 // |alternate_triggered_errors_| is set if this feature is enabled and | |
| 181 // |request_counter_| is used to send triggered errors on odd-numbered | |
| 182 // requests. Note that |request_counter_| can be reset and is not necessarily | |
| 183 // indicative of the total number of requests handled during the object's | |
| 184 // lifetime. | |
| 185 bool alternate_triggered_errors_; | |
| 186 int request_counter_; | |
| 187 | |
| 169 // FakeServer's observers. | 188 // FakeServer's observers. |
| 170 ObserverList<Observer, true> observers_; | 189 ObserverList<Observer, true> observers_; |
| 171 }; | 190 }; |
| 172 | 191 |
| 173 } // namespace fake_server | 192 } // namespace fake_server |
| 174 | 193 |
| 175 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ | 194 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ |
| OLD | NEW |