OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/proximity_auth/remote_status_update.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/values.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 // The value of the 'type' status update field. |
| 13 const char kStatusUpdateType[] = "status_update"; |
| 14 |
| 15 // Keys in the serialized RemoteStatusUpdate JSON object. |
| 16 const char kType[] = "type"; |
| 17 const char kUserPresence[] = "user_presence"; |
| 18 const char kSecureScreenLock[] = "secure_screen_lock"; |
| 19 const char kTrustAgent[] = "trust_agent"; |
| 20 |
| 21 // Values in the serialized RemoteStatusUpdate JSON object. |
| 22 const char kUserPresent[] = "present"; |
| 23 const char kUserAbsent[] = "absent"; |
| 24 const char kUserPresenceUnknown[] = "unknown"; |
| 25 |
| 26 const char kSecureScreenLockEnabled[] = "enabled"; |
| 27 const char kSecureScreenLockDisabled[] = "disabled"; |
| 28 const char kSecureScreenLockStateUnknown[] = "unknown"; |
| 29 |
| 30 const char kTrustAgentEnabled[] = "enabled"; |
| 31 const char kTrustAgentDisabled[] = "disabled"; |
| 32 const char kTrustAgentUnsupported[] = "unsupported"; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 namespace proximity_auth { |
| 37 |
| 38 // static |
| 39 scoped_ptr<RemoteStatusUpdate> RemoteStatusUpdate::Deserialize( |
| 40 const base::DictionaryValue& serialized_value) { |
| 41 std::string type; |
| 42 if (!serialized_value.GetString(kType, &type) || type != kStatusUpdateType) { |
| 43 VLOG(1) << "Unable to parse remote status update: unexpected type. " |
| 44 << "Expected: '" << kStatusUpdateType << "', " |
| 45 << "Saw: '" << type << "'."; |
| 46 return scoped_ptr<RemoteStatusUpdate>(); |
| 47 } |
| 48 |
| 49 std::string user_presence, secure_screen_lock_state, trust_agent_state; |
| 50 if (!serialized_value.GetString(kUserPresence, &user_presence) || |
| 51 !serialized_value.GetString(kSecureScreenLock, |
| 52 &secure_screen_lock_state) || |
| 53 !serialized_value.GetString(kTrustAgent, &trust_agent_state)) { |
| 54 VLOG(1) << "Unable to parse remote status update: missing data value. " |
| 55 << "Status update:\n" << serialized_value; |
| 56 return scoped_ptr<RemoteStatusUpdate>(); |
| 57 } |
| 58 |
| 59 scoped_ptr<RemoteStatusUpdate> parsed_update(new RemoteStatusUpdate); |
| 60 if (user_presence == kUserPresent) { |
| 61 parsed_update->user_presence = USER_PRESENT; |
| 62 } else if (user_presence == kUserAbsent) { |
| 63 parsed_update->user_presence = USER_ABSENT; |
| 64 } else if (user_presence == kUserPresenceUnknown) { |
| 65 parsed_update->user_presence = USER_PRESENCE_UNKNOWN; |
| 66 } else { |
| 67 VLOG(1) << "Unable to parse remote status update: invalid user presence: '" |
| 68 << user_presence << "'."; |
| 69 return scoped_ptr<RemoteStatusUpdate>(); |
| 70 } |
| 71 |
| 72 if (secure_screen_lock_state == kSecureScreenLockEnabled) { |
| 73 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED; |
| 74 } else if (secure_screen_lock_state == kSecureScreenLockDisabled) { |
| 75 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_DISABLED; |
| 76 } else if (secure_screen_lock_state == kSecureScreenLockStateUnknown) { |
| 77 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_STATE_UNKNOWN; |
| 78 } else { |
| 79 VLOG(1) << "Unable to parse remote status update: invalid secure screen " |
| 80 << "lock state: '" << secure_screen_lock_state << "'."; |
| 81 return scoped_ptr<RemoteStatusUpdate>(); |
| 82 } |
| 83 |
| 84 if (trust_agent_state == kTrustAgentEnabled) { |
| 85 parsed_update->trust_agent_state = TRUST_AGENT_ENABLED; |
| 86 } else if (trust_agent_state == kTrustAgentDisabled) { |
| 87 parsed_update->trust_agent_state = TRUST_AGENT_DISABLED; |
| 88 } else if (trust_agent_state == kTrustAgentUnsupported) { |
| 89 parsed_update->trust_agent_state = TRUST_AGENT_UNSUPPORTED; |
| 90 } else { |
| 91 VLOG(1) << "Unable to parse remote status update: invalid trust agent " |
| 92 << "state: '" << trust_agent_state << "'."; |
| 93 return scoped_ptr<RemoteStatusUpdate>(); |
| 94 } |
| 95 |
| 96 return parsed_update.Pass(); |
| 97 } |
| 98 |
| 99 } // namespace proximity_auth |
OLD | NEW |