session_options.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2016 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. #ifndef REMOTING_BASE_SESSION_OPTIONS_H_
  5. #define REMOTING_BASE_SESSION_OPTIONS_H_
  6. #include <string>
  7. #include "base/containers/flat_map.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. namespace remoting {
  10. // Session based host options sending from client. This class parses and stores
  11. // session configuration from client side to control the behavior of other host
  12. // components.
  13. class SessionOptions final {
  14. public:
  15. SessionOptions();
  16. SessionOptions(const SessionOptions& other);
  17. SessionOptions(SessionOptions&& other);
  18. explicit SessionOptions(const std::string& parameter);
  19. ~SessionOptions();
  20. SessionOptions& operator=(const SessionOptions& other);
  21. SessionOptions& operator=(SessionOptions&& other);
  22. // Appends one key-value pair into current instance.
  23. void Append(const std::string& key, const std::string& value);
  24. // Retrieves the value of |key|. Returns a true Optional if |key| has been
  25. // found, value of the Optional will be set to corresponding value.
  26. absl::optional<std::string> Get(const std::string& key) const;
  27. // Retrieves the value of |key|. Returns a true Optional if |key| has been
  28. // found and the corresponding value can be converted to a boolean value.
  29. // "true", "1" or empty will be converted to true, "false" or "0" will be
  30. // converted to false.
  31. absl::optional<bool> GetBool(const std::string& key) const;
  32. // Equivalent to GetBool(key).value_or(false).
  33. bool GetBoolValue(const std::string& key) const;
  34. // Retrieves the value of |key|. Returns a true Optional if |key| has been
  35. // found and the corresponding value can be converted to an integer.
  36. absl::optional<int> GetInt(const std::string& key) const;
  37. // Returns a string to represent current instance. Consumers can rebuild an
  38. // exactly same instance with Import() function.
  39. std::string Export() const;
  40. // Overwrite current instance with |parameter|, which is a string returned by
  41. // Export() function. So a parent process can send SessionOptions to a
  42. // child process.
  43. void Import(const std::string& parameter);
  44. private:
  45. base::flat_map<std::string, std::string> options_;
  46. };
  47. } // namespace remoting
  48. #endif // REMOTING_BASE_SESSION_OPTIONS_H_