Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: components/copresence/copresence_state_impl.h

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/copresence/copresence_manager_impl.cc ('k') | components/copresence/copresence_state_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/copresence_state_impl.h
diff --git a/components/copresence/copresence_state_impl.h b/components/copresence/copresence_state_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..2a941bf4105ca41c331ed808ded42e9cb920b3ae
--- /dev/null
+++ b/components/copresence/copresence_state_impl.h
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_
+#define COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "components/copresence/proto/enums.pb.h"
+#include "components/copresence/public/copresence_state.h"
+
+namespace copresence {
+
+class Directive;
+struct AudioToken;
+struct ReceivedToken;
+struct TransmittedToken;
+
+// This class tracks the internal state of the copresence component
+// for debugging purposes. CopresenceState only allows observation,
+// but this class accepts updates from elsewhere in the component.
+class CopresenceStateImpl final : public CopresenceState {
+ public:
+ CopresenceStateImpl();
+ ~CopresenceStateImpl() override;
+
+ // CopresenceState overrides.
+ void AddObserver(CopresenceObserver* observer) override;
+ void RemoveObserver(CopresenceObserver* observer) override;
+ const std::vector<Directive>& active_directives() const override;
+ const std::map<std::string, TransmittedToken>&
+ transmitted_tokens() const override;
+ const std::map<std::string, ReceivedToken>&
+ received_tokens() const override;
+
+ // Update the current active directives.
+ void UpdateDirectives(const std::vector<Directive>& directives);
+
+ // Report transmitting a token.
+ void UpdateTransmittedToken(const TransmittedToken& token);
+
+ // Report receiving a token.
+ void UpdateReceivedToken(const ReceivedToken& token);
+
+ // Report the token state from the server.
+ void UpdateTokenStatus(const std::string& token_id, TokenStatus status);
+
+ private:
+ // Reconcile the |active_directives_| against |transmitted_tokens_|.
+ void UpdateTransmittingTokens();
+
+ std::vector<Directive> active_directives_;
+
+ // TODO(ckehoe): When we support more mediums, separate tokens by medium.
+ // Otherwise tokens from different mediums could overwrite each other.
+ // TODO(ckehoe): Limit the number of tokens stored.
+ std::map<std::string, TransmittedToken> transmitted_tokens_;
+ std::map<std::string, ReceivedToken> received_tokens_;
+
+ ObserverList<CopresenceObserver> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl);
+};
+
+} // namespace copresence
+
+#endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_
« no previous file with comments | « components/copresence/copresence_manager_impl.cc ('k') | components/copresence/copresence_state_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698