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

Unified Diff: components/copresence/handlers/directive_handler.h

Issue 684273004: Moving the DirectiveHandler to be owned by CopresenceManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing crash Created 6 years, 2 months 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/handlers/directive_handler.h
diff --git a/components/copresence/handlers/directive_handler.h b/components/copresence/handlers/directive_handler.h
index b9b1a88cd0d04645f14bf1fa0a26d552b05ad888..75761286d13eb6330ebcf0f06ad11b4083177ab7 100644
--- a/components/copresence/handlers/directive_handler.h
+++ b/components/copresence/handlers/directive_handler.h
@@ -5,41 +5,57 @@
#ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
#define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
+#include <map>
#include <string>
+#include <vector>
-#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-#include "components/copresence/handlers/audio/audio_directive_handler.h"
-#include "components/copresence/mediums/audio/audio_manager.h"
+#include "components/copresence/public/whispernet_client.h"
namespace copresence {
+class AudioDirectiveHandler;
class Directive;
-// The directive handler manages transmit and receive directives
-// given to it by the manager.
+// The directive handler manages transmit and receive directives.
+// TODO(ckehoe): Add tests for this class.
+// TODO(ckehoe): Turn this into an interface.
class DirectiveHandler {
public:
DirectiveHandler();
virtual ~DirectiveHandler();
- // Initialize the |audio_handler_| with the appropriate callbacks.
- // This function must be called before any others.
- // TODO(ckehoe): Instead of this, use a static Create() method
- // and make the constructor private.
- virtual void Initialize(const AudioManager::DecodeSamplesCallback& decode_cb,
- const AudioManager::EncodeTokenCallback& encode_cb);
+ // Starts processing directives with the provided Whispernet client.
+ // Directives will be queued until this function is called.
+ // |whispernet_client| is owned by the caller
+ // and must outlive the DirectiveHandler.
+ virtual void Start(WhispernetClient* whispernet_client);
// Adds a directive to handle.
- virtual void AddDirective(const copresence::Directive& directive);
+ virtual void AddDirective(const Directive& directive);
+
// Removes any directives associated with the given operation id.
virtual void RemoveDirectives(const std::string& op_id);
- const std::string GetCurrentAudioToken(AudioType type) const;
+ virtual const std::string GetCurrentAudioToken(AudioType type) const;
private:
+ // Starts actually running a directive.
+ void StartDirective(const std::string& op_id, const Directive& directive);
+
+ // Forwards the request to encode a token to whispernet,
+ // and instructs it to call samples_callback when encoding is complete.
+ void EncodeToken(
+ const std::string& token,
+ AudioType type,
+ const WhispernetClient::SamplesCallback& samples_callback);
+
scoped_ptr<AudioDirectiveHandler> audio_handler_;
+ std::map<std::string, std::vector<Directive>> pending_directives_;
+
+ // Belongs to the caller.
+ WhispernetClient* whispernet_client_;
DISALLOW_COPY_AND_ASSIGN(DirectiveHandler);
};
« no previous file with comments | « components/copresence/copresence_manager_impl.cc ('k') | components/copresence/handlers/directive_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698