Splits |key_value| on '=' and inserts the resulting key and value into |map|. If |key_value| has the wrong format, logs an error and returns false. If the key is already in the map, logs a warning, replaces the existing value, and returns true. If the key and value were inserted into the map, returns true. |argument| is used to give context to logged messages.
| 263 | // returns true. If the key and value were inserted into the map, returns true. |
| 264 | // |argument| is used to give context to logged messages. |
| 265 | bool AddKeyValueToMap(std::map<std::string, std::string>* map, |
| 266 | const std::string& key_value, |
| 267 | const char* argument) { |
| 268 | std::string key; |
| 269 | std::string value; |
| 270 | if (!SplitStringFirst(key_value, '=', &key, &value)) { |
| 271 | LOG(ERROR) << argument << " requires KEY=VALUE"; |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | std::string old_value; |
| 276 | if (!MapInsertOrReplace(map, key, value, &old_value)) { |
| 277 | LOG(WARNING) << argument << " has duplicate key " << key |
| 278 | << ", discarding value " << old_value; |
| 279 | } |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | // Calls Metrics::HandlerLifetimeMilestone, but only on the first call. This is |
| 284 | // to prevent multiple exit events from inadvertently being recorded, which |
no test coverage detected