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.
5 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_
6 #define COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_
12 #include "base/macros.h"
13 #include "base/observer_list.h"
14 #include "components/copresence/proto/enums.pb.h"
15 #include "components/copresence/public/copresence_state.h"
17 namespace copresence
{
21 struct TransmittedToken
;
23 // This class tracks the internal state of the copresence component
24 // for debugging purposes. CopresenceState only allows observation,
25 // but this class accepts updates from elsewhere in the component.
26 class CopresenceStateImpl final
: public CopresenceState
{
28 CopresenceStateImpl();
29 ~CopresenceStateImpl() override
;
31 // CopresenceState overrides.
32 void AddObserver(CopresenceObserver
* observer
) override
;
33 void RemoveObserver(CopresenceObserver
* observer
) override
;
34 const std::vector
<Directive
>& active_directives() const override
;
35 const std::map
<std::string
, TransmittedToken
>&
36 transmitted_tokens() const override
;
37 const std::map
<std::string
, ReceivedToken
>&
38 received_tokens() const override
;
40 // Update the current active directives.
41 void UpdateDirectives(const std::vector
<Directive
>& directives
);
43 // Report transmitting a token.
44 void UpdateTransmittedToken(const TransmittedToken
& token
);
46 // Report receiving a token.
47 void UpdateReceivedToken(const ReceivedToken
& token
);
49 // Report the token state from the server.
50 void UpdateTokenStatus(const std::string
& token_id
, TokenStatus status
);
53 // Reconcile the |active_directives_| against |transmitted_tokens_|.
54 void UpdateTransmittingTokens();
56 std::vector
<Directive
> active_directives_
;
58 // TODO(ckehoe): When we support more mediums, separate tokens by medium.
59 // Otherwise tokens from different mediums could overwrite each other.
60 // TODO(ckehoe): Limit the number of tokens stored.
61 std::map
<std::string
, TransmittedToken
> transmitted_tokens_
;
62 std::map
<std::string
, ReceivedToken
> received_tokens_
;
64 base::ObserverList
<CopresenceObserver
> observers_
;
66 DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl
);
69 } // namespace copresence
71 #endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_