OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_ | |
6 #define COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "components/copresence/proto/enums.pb.h" | |
15 #include "components/copresence/public/copresence_state.h" | |
16 | |
17 // TODO(ckehoe): Write tests. | |
rkc
2014/12/18 18:12:09
We should put in at least some basic unit tests, e
Charlie
2014/12/19 03:53:33
Done.
| |
18 | |
19 namespace copresence { | |
20 | |
21 class Directive; | |
22 struct AudioToken; | |
23 struct ReceivedToken; | |
24 struct TransmittedToken; | |
25 | |
26 // This class tracks the internal state of the copresence component | |
27 // for debugging purposes. CopresenceState only allows observation, | |
28 // but this class accepts updates from elsewhere in the component. | |
29 class CopresenceStateImpl final : public CopresenceState { | |
30 public: | |
31 CopresenceStateImpl(); | |
32 ~CopresenceStateImpl() override; | |
33 | |
34 // CopresenceState overrides. | |
35 void AddObserver(CopresenceObserver* observer) override; | |
36 void RemoveObserver(CopresenceObserver* observer) override; | |
37 const std::vector<Directive>& active_directives() override; | |
38 const std::map<std::string, TransmittedToken>& transmitted_tokens() override; | |
39 const std::map<std::string, ReceivedToken>& received_tokens() override; | |
40 | |
41 // Update the current active directives. | |
42 void UpdateDirectives(const std::vector<Directive>& directives); | |
43 | |
44 // Report transmitting a token. | |
45 void UpdateTransmittedToken(const TransmittedToken& token); | |
46 | |
47 // Report receiving a token. | |
48 void UpdateReceivedToken(const ReceivedToken& token); | |
49 | |
50 // Report the token state from the server. | |
51 void UpdateTokenStatus(const std::string& token_id, TokenStatus status); | |
52 | |
53 private: | |
54 // Reconcile the |active_directives_| against |transmitted_tokens_|. | |
55 void UpdateTransmittingTokens(); | |
56 | |
57 std::vector<Directive> active_directives_; | |
58 | |
59 // TODO(ckehoe): When we support more mediums, separate tokens by medium. | |
60 // Otherwise tokens from different mediums could overwrite each other. | |
61 std::map<std::string, TransmittedToken> transmitted_tokens_; | |
62 std::map<std::string, ReceivedToken> received_tokens_; | |
63 | |
64 std::set<CopresenceObserver*> observers_; | |
xiyuan
2014/12/18 18:10:52
Why not use ObserverList in base/observer_list.h?
Charlie
2014/12/19 03:53:33
Thanks! Done.
| |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl); | |
67 }; | |
68 | |
69 } // namespace copresence | |
70 | |
71 #endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_ | |
OLD | NEW |