Index: remoting/host/host_traits.h |
diff --git a/remoting/host/host_traits.h b/remoting/host/host_traits.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e1dac2f8e5babf8c5bdb3823d9301fb5624a31c |
--- /dev/null |
+++ b/remoting/host/host_traits.h |
@@ -0,0 +1,52 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_HOST_TRAITS_H_ |
+#define REMOTING_HOST_HOST_TRAITS_H_ |
+ |
+#include <map> |
+#include <set> |
+#include <string> |
+ |
+#include "base/callback.h" |
+ |
+namespace remoting { |
+ |
+class HostTraits& host_traits(); |
+ |
+class HostTraits final { |
Sergey Ulanov
2016/11/02 20:10:32
Normally term "trait" means something different, s
Hzj_jie
2016/11/03 02:29:35
Then we will lose the functionality of ToString(),
Sergey Ulanov
2016/11/03 19:05:34
Not sure why that would be a problem. Just to make
Hzj_jie
2016/11/03 21:33:30
Acknowledged.
|
+ public: |
+ ~HostTraits(); |
+ |
+ // Converts the HostTraits into its text representation, which is a comma- |
+ // separated string, each field indicates one trait. |
+ std::string ToString() const; |
+ |
+ // Registers a static value, which will be appended to ToString() result. |
+ void Register(const std::string& key); |
+ |
+ // Registers a dynamic value, which will be evaluated each time ToString() is |
+ // called. |
+ void Register(const std::string& key, |
+ const base::Callback<bool(void)>& value); |
Sergey Ulanov
2016/11/02 20:10:32
don't need void.
Hzj_jie
2016/11/03 02:29:35
Done.
|
+ |
+ // Erases a value. This function is usually for testing purpose. |
+ void Erase(const std::string& key); |
Sergey Ulanov
2016/11/02 20:10:32
Do you really need this? Not sure we will ever wan
Hzj_jie
2016/11/03 02:29:35
This is for test only, in HostTraitsTest.DynamicVa
Sergey Ulanov
2016/11/03 19:05:34
That's actually one of the reasons why singletons
Hzj_jie
2016/11/03 21:33:30
Done.
|
+ |
+ // Whether the |output| contains the specified trait as |key|. This function |
+ // is usually for testing purpose. |
+ static bool ContainsTrait(const std::string& output, const std::string& key); |
+ |
+ private: |
+ // A singleton object. |
+ friend HostTraits& host_traits(); |
+ HostTraits(); |
+ |
+ std::set<std::string> static_values_; |
+ std::map<std::string, base::Callback<bool(void)>> dynamic_values_; |
Sergey Ulanov
2016/11/02 20:10:32
I don't think you really need set or map here. vec
Hzj_jie
2016/11/03 02:29:35
The set and map are used to ensure no keys are dup
|
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_HOST_TRAITS_H_ |