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 "base/observer_list.h" | |
15 #include "components/copresence/proto/enums.pb.h" | |
16 #include "components/copresence/public/copresence_state.h" | |
17 | |
18 namespace copresence { | |
19 | |
20 class Directive; | |
21 struct AudioToken; | |
22 struct ReceivedToken; | |
23 struct TransmittedToken; | |
24 | |
25 // This class tracks the internal state of the copresence component | |
26 // for debugging purposes. CopresenceState only allows observation, | |
27 // but this class accepts updates from elsewhere in the component. | |
28 class CopresenceStateImpl final : public CopresenceState { | |
29 public: | |
30 CopresenceStateImpl(); | |
31 ~CopresenceStateImpl() override; | |
32 | |
33 // CopresenceState overrides. | |
34 void AddObserver(CopresenceObserver* observer) override; | |
35 void RemoveObserver(CopresenceObserver* observer) override; | |
36 const std::vector<Directive>& active_directives() const override; | |
37 const std::map<std::string, TransmittedToken>& transmitted_tokens() | |
38 const override; | |
xiyuan
2014/12/19 04:03:01
nit: wrap transimitted_tokens() as well? It feels
Charlie
2014/12/19 05:25:39
No I just made it up. Done.
| |
39 const std::map<std::string, ReceivedToken>& received_tokens() const 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 // TODO(ckehoe): Limit the number of tokens stored. | |
62 std::map<std::string, TransmittedToken> transmitted_tokens_; | |
63 std::map<std::string, ReceivedToken> received_tokens_; | |
64 | |
65 ObserverList<CopresenceObserver> observers_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl); | |
68 }; | |
69 | |
70 } // namespace copresence | |
71 | |
72 #endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_ | |
OLD | NEW |