File: remote_status_update.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 4,272 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/proximity_auth/remote_status_update.h"

#include "chromeos/ash/components/multidevice/logging/logging.h"

namespace {

// The value of the 'type' status update field.
const char kStatusUpdateType[] = "status_update";

// Keys in the serialized RemoteStatusUpdate JSON object.
const char kType[] = "type";
const char kUserPresence[] = "user_presence";
const char kSecureScreenLock[] = "secure_screen_lock";
const char kTrustAgent[] = "trust_agent";

// Values in the serialized RemoteStatusUpdate JSON object.
const char kUserPresent[] = "present";
const char kUserAbsent[] = "absent";
const char kUserPresenceUnknown[] = "unknown";
const char kUserPresenceSecondary[] = "secondary";
const char kUserPresenceBackground[] = "background";

const char kSecureScreenLockEnabled[] = "enabled";
const char kSecureScreenLockDisabled[] = "disabled";
const char kSecureScreenLockStateUnknown[] = "unknown";

const char kTrustAgentEnabled[] = "enabled";
const char kTrustAgentDisabled[] = "disabled";
const char kTrustAgentUnsupported[] = "unsupported";

}  // namespace

namespace proximity_auth {

// static
std::unique_ptr<RemoteStatusUpdate> RemoteStatusUpdate::Deserialize(
    const base::Value::Dict& serialized_value) {
  const std::string* type = serialized_value.FindString(kType);
  if (!type || *type != kStatusUpdateType) {
    PA_LOG(ERROR) << "Unable to parse remote status update: unexpected type. "
                  << "Expected: '" << kStatusUpdateType << "', "
                  << "Saw: '" << *type << "'.";
    return nullptr;
  }

  const std::string* user_presence = serialized_value.FindString(kUserPresence);
  const std::string* secure_screen_lock_state =
      serialized_value.FindString(kSecureScreenLock);
  const std::string* trust_agent_state =
      serialized_value.FindString(kTrustAgent);
  if (!user_presence || !secure_screen_lock_state || !trust_agent_state) {
    PA_LOG(ERROR) << "Unable to parse remote status update: missing data value."
                  << " Status update:\n"
                  << serialized_value;
    return nullptr;
  }

  std::unique_ptr<RemoteStatusUpdate> parsed_update(new RemoteStatusUpdate);
  if (*user_presence == kUserPresent) {
    parsed_update->user_presence = USER_PRESENT;
  } else if (*user_presence == kUserAbsent) {
    parsed_update->user_presence = USER_ABSENT;
  } else if (*user_presence == kUserPresenceUnknown) {
    parsed_update->user_presence = USER_PRESENCE_UNKNOWN;
  } else if (*user_presence == kUserPresenceSecondary) {
    parsed_update->user_presence = USER_PRESENCE_SECONDARY;
  } else if (*user_presence == kUserPresenceBackground) {
    parsed_update->user_presence = USER_PRESENCE_BACKGROUND;
  } else {
    PA_LOG(ERROR)
        << "Unable to parse remote status update: invalid user presence: '"
        << *user_presence << "'.";
    return nullptr;
  }

  if (*secure_screen_lock_state == kSecureScreenLockEnabled) {
    parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_ENABLED;
  } else if (*secure_screen_lock_state == kSecureScreenLockDisabled) {
    parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_DISABLED;
  } else if (*secure_screen_lock_state == kSecureScreenLockStateUnknown) {
    parsed_update->secure_screen_lock_state = SECURE_SCREEN_LOCK_STATE_UNKNOWN;
  } else {
    PA_LOG(ERROR) << "Unable to parse remote status update: invalid secure "
                  << "screen lock state: '" << *secure_screen_lock_state
                  << "'.";
    return nullptr;
  }

  if (*trust_agent_state == kTrustAgentEnabled) {
    parsed_update->trust_agent_state = TRUST_AGENT_ENABLED;
  } else if (*trust_agent_state == kTrustAgentDisabled) {
    parsed_update->trust_agent_state = TRUST_AGENT_DISABLED;
  } else if (*trust_agent_state == kTrustAgentUnsupported) {
    parsed_update->trust_agent_state = TRUST_AGENT_UNSUPPORTED;
  } else {
    PA_LOG(ERROR) << "Unable to parse remote status update: invalid trust "
                  << "agent state: '" << *trust_agent_state << "'.";
    return nullptr;
  }

  return parsed_update;
}

}  // namespace proximity_auth