| 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 #include "components/proximity_auth/remote_status_update.h" | 5 #include "components/proximity_auth/remote_status_update.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 const char kTrustAgentEnabled[] = "enabled"; | 30 const char kTrustAgentEnabled[] = "enabled"; |
| 31 const char kTrustAgentDisabled[] = "disabled"; | 31 const char kTrustAgentDisabled[] = "disabled"; |
| 32 const char kTrustAgentUnsupported[] = "unsupported"; | 32 const char kTrustAgentUnsupported[] = "unsupported"; |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 namespace proximity_auth { | 36 namespace proximity_auth { |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 scoped_ptr<RemoteStatusUpdate> RemoteStatusUpdate::Deserialize( | 39 std::unique_ptr<RemoteStatusUpdate> RemoteStatusUpdate::Deserialize( |
| 40 const base::DictionaryValue& serialized_value) { | 40 const base::DictionaryValue& serialized_value) { |
| 41 std::string type; | 41 std::string type; |
| 42 if (!serialized_value.GetString(kType, &type) || type != kStatusUpdateType) { | 42 if (!serialized_value.GetString(kType, &type) || type != kStatusUpdateType) { |
| 43 VLOG(1) << "Unable to parse remote status update: unexpected type. " | 43 VLOG(1) << "Unable to parse remote status update: unexpected type. " |
| 44 << "Expected: '" << kStatusUpdateType << "', " | 44 << "Expected: '" << kStatusUpdateType << "', " |
| 45 << "Saw: '" << type << "'."; | 45 << "Saw: '" << type << "'."; |
| 46 return scoped_ptr<RemoteStatusUpdate>(); | 46 return std::unique_ptr<RemoteStatusUpdate>(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 std::string user_presence, secure_screen_lock_state, trust_agent_state; | 49 std::string user_presence, secure_screen_lock_state, trust_agent_state; |
| 50 if (!serialized_value.GetString(kUserPresence, &user_presence) || | 50 if (!serialized_value.GetString(kUserPresence, &user_presence) || |
| 51 !serialized_value.GetString(kSecureScreenLock, | 51 !serialized_value.GetString(kSecureScreenLock, |
| 52 &secure_screen_lock_state) || | 52 &secure_screen_lock_state) || |
| 53 !serialized_value.GetString(kTrustAgent, &trust_agent_state)) { | 53 !serialized_value.GetString(kTrustAgent, &trust_agent_state)) { |
| 54 VLOG(1) << "Unable to parse remote status update: missing data value. " | 54 VLOG(1) << "Unable to parse remote status update: missing data value. " |
| 55 << "Status update:\n" << serialized_value; | 55 << "Status update:\n" << serialized_value; |
| 56 return scoped_ptr<RemoteStatusUpdate>(); | 56 return std::unique_ptr<RemoteStatusUpdate>(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 scoped_ptr<RemoteStatusUpdate> parsed_update(new RemoteStatusUpdate); | 59 std::unique_ptr<RemoteStatusUpdate> parsed_update(new RemoteStatusUpdate); |
| 60 if (user_presence == kUserPresent) { | 60 if (user_presence == kUserPresent) { |
| 61 parsed_update->user_presence = USER_PRESENT; | 61 parsed_update->user_presence = USER_PRESENT; |
| 62 } else if (user_presence == kUserAbsent) { | 62 } else if (user_presence == kUserAbsent) { |
| 63 parsed_update->user_presence = USER_ABSENT; | 63 parsed_update->user_presence = USER_ABSENT; |
| 64 } else if (user_presence == kUserPresenceUnknown) { | 64 } else if (user_presence == kUserPresenceUnknown) { |
| 65 parsed_update->user_presence = USER_PRESENCE_UNKNOWN; | 65 parsed_update->user_presence = USER_PRESENCE_UNKNOWN; |
| 66 } else { | 66 } else { |
| 67 VLOG(1) << "Unable to parse remote status update: invalid user presence: '" | 67 VLOG(1) << "Unable to parse remote status update: invalid user presence: '" |
| 68 << user_presence << "'."; | 68 << user_presence << "'."; |
| 69 return scoped_ptr<RemoteStatusUpdate>(); | 69 return std::unique_ptr<RemoteStatusUpdate>(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (secure_screen_lock_state == kSecureScreenLockEnabled) { | 72 if (secure_screen_lock_state == kSecureScreenLockEnabled) { |
| 73 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED; | 73 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED; |
| 74 } else if (secure_screen_lock_state == kSecureScreenLockDisabled) { | 74 } else if (secure_screen_lock_state == kSecureScreenLockDisabled) { |
| 75 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_DISABLED; | 75 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_DISABLED; |
| 76 } else if (secure_screen_lock_state == kSecureScreenLockStateUnknown) { | 76 } else if (secure_screen_lock_state == kSecureScreenLockStateUnknown) { |
| 77 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_STATE_UNKNOWN; | 77 parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_STATE_UNKNOWN; |
| 78 } else { | 78 } else { |
| 79 VLOG(1) << "Unable to parse remote status update: invalid secure screen " | 79 VLOG(1) << "Unable to parse remote status update: invalid secure screen " |
| 80 << "lock state: '" << secure_screen_lock_state << "'."; | 80 << "lock state: '" << secure_screen_lock_state << "'."; |
| 81 return scoped_ptr<RemoteStatusUpdate>(); | 81 return std::unique_ptr<RemoteStatusUpdate>(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (trust_agent_state == kTrustAgentEnabled) { | 84 if (trust_agent_state == kTrustAgentEnabled) { |
| 85 parsed_update->trust_agent_state = TRUST_AGENT_ENABLED; | 85 parsed_update->trust_agent_state = TRUST_AGENT_ENABLED; |
| 86 } else if (trust_agent_state == kTrustAgentDisabled) { | 86 } else if (trust_agent_state == kTrustAgentDisabled) { |
| 87 parsed_update->trust_agent_state = TRUST_AGENT_DISABLED; | 87 parsed_update->trust_agent_state = TRUST_AGENT_DISABLED; |
| 88 } else if (trust_agent_state == kTrustAgentUnsupported) { | 88 } else if (trust_agent_state == kTrustAgentUnsupported) { |
| 89 parsed_update->trust_agent_state = TRUST_AGENT_UNSUPPORTED; | 89 parsed_update->trust_agent_state = TRUST_AGENT_UNSUPPORTED; |
| 90 } else { | 90 } else { |
| 91 VLOG(1) << "Unable to parse remote status update: invalid trust agent " | 91 VLOG(1) << "Unable to parse remote status update: invalid trust agent " |
| 92 << "state: '" << trust_agent_state << "'."; | 92 << "state: '" << trust_agent_state << "'."; |
| 93 return scoped_ptr<RemoteStatusUpdate>(); | 93 return std::unique_ptr<RemoteStatusUpdate>(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 return parsed_update; | 96 return parsed_update; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace proximity_auth | 99 } // namespace proximity_auth |
| OLD | NEW |