OLD | NEW |
---|---|
(Empty) | |
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 | |
5 #ifndef REMOTING_HOST_HOST_TRAITS_H_ | |
6 #define REMOTING_HOST_HOST_TRAITS_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 | |
14 namespace remoting { | |
15 | |
16 class HostTraits& host_traits(); | |
17 | |
18 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.
| |
19 public: | |
20 ~HostTraits(); | |
21 | |
22 // Converts the HostTraits into its text representation, which is a comma- | |
23 // separated string, each field indicates one trait. | |
24 std::string ToString() const; | |
25 | |
26 // Registers a static value, which will be appended to ToString() result. | |
27 void Register(const std::string& key); | |
28 | |
29 // Registers a dynamic value, which will be evaluated each time ToString() is | |
30 // called. | |
31 void Register(const std::string& key, | |
32 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.
| |
33 | |
34 // Erases a value. This function is usually for testing purpose. | |
35 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.
| |
36 | |
37 // Whether the |output| contains the specified trait as |key|. This function | |
38 // is usually for testing purpose. | |
39 static bool ContainsTrait(const std::string& output, const std::string& key); | |
40 | |
41 private: | |
42 // A singleton object. | |
43 friend HostTraits& host_traits(); | |
44 HostTraits(); | |
45 | |
46 std::set<std::string> static_values_; | |
47 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
| |
48 }; | |
49 | |
50 } // namespace remoting | |
51 | |
52 #endif // REMOTING_HOST_HOST_TRAITS_H_ | |
OLD | NEW |