| 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 <string> | |
| 10 #include <vector> | |
| 11 | |
| 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" | |
| 16 | |
| 17 namespace copresence { | |
| 18 | |
| 19 class Directive; | |
| 20 struct ReceivedToken; | |
| 21 struct TransmittedToken; | |
| 22 | |
| 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 { | |
| 27 public: | |
| 28 CopresenceStateImpl(); | |
| 29 ~CopresenceStateImpl() override; | |
| 30 | |
| 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; | |
| 39 | |
| 40 // Update the current active directives. | |
| 41 void UpdateDirectives(const std::vector<Directive>& directives); | |
| 42 | |
| 43 // Report transmitting a token. | |
| 44 void UpdateTransmittedToken(const TransmittedToken& token); | |
| 45 | |
| 46 // Report receiving a token. | |
| 47 void UpdateReceivedToken(const ReceivedToken& token); | |
| 48 | |
| 49 // Report the token state from the server. | |
| 50 void UpdateTokenStatus(const std::string& token_id, TokenStatus status); | |
| 51 | |
| 52 private: | |
| 53 // Reconcile the |active_directives_| against |transmitted_tokens_|. | |
| 54 void UpdateTransmittingTokens(); | |
| 55 | |
| 56 std::vector<Directive> active_directives_; | |
| 57 | |
| 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_; | |
| 63 | |
| 64 base::ObserverList<CopresenceObserver> observers_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl); | |
| 67 }; | |
| 68 | |
| 69 } // namespace copresence | |
| 70 | |
| 71 #endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_ | |
| OLD | NEW |