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

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: Fixing overzealous DCHECK 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
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..84200eee834838cdb2a00457eb0073f8d0a3cf62
--- /dev/null
+++ b/components/copresence/copresence_state_impl.h
@@ -0,0 +1,71 @@
+// 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 <set>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "components/copresence/proto/enums.pb.h"
+#include "components/copresence/public/copresence_state.h"
+
+// 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.
+
+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() override;
+ const std::map<std::string, TransmittedToken>& transmitted_tokens() override;
+ const std::map<std::string, ReceivedToken>& received_tokens() 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.
+ std::map<std::string, TransmittedToken> transmitted_tokens_;
+ std::map<std::string, ReceivedToken> received_tokens_;
+
+ 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.
+
+ DISALLOW_COPY_AND_ASSIGN(CopresenceStateImpl);
+};
+
+} // namespace copresence
+
+#endif // COMPONENTS_COPRESENCE_COPRESENCE_STATE_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698