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

Side by Side Diff: components/copresence/handlers/directive_handler.h

Issue 704923002: Add polling and audio check to copresence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ 6 #define COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "components/copresence/public/whispernet_client.h" 14 #include "components/copresence/public/copresence_constants.h"
15 15
16 namespace copresence { 16 namespace copresence {
17 17
18 class AudioDirectiveHandler; 18 class AudioDirectiveHandler;
19 class Directive; 19 class Directive;
20 class WhispernetClient;
20 21
21 // The directive handler manages transmit and receive directives. 22 // The directive handler manages transmit and receive directives.
22 // TODO(ckehoe): Add tests for this class. 23 // TODO(ckehoe): Add tests for this class.
23 // TODO(ckehoe): Turn this into an interface. 24 // TODO(ckehoe): Turn this into an interface.
24 class DirectiveHandler { 25 class DirectiveHandler {
25 public: 26 public:
26 DirectiveHandler(); 27 DirectiveHandler();
27 virtual ~DirectiveHandler(); 28 virtual ~DirectiveHandler();
28 29
29 // Starts processing directives with the provided Whispernet client. 30 // Starts processing directives with the provided Whispernet client.
30 // Directives will be queued until this function is called. 31 // Directives will be queued until this function is called.
31 // |whispernet_client| is owned by the caller 32 // |whispernet_client| is owned by the caller and must outlive the
32 // and must outlive the DirectiveHandler. 33 // DirectiveHandler.
33 virtual void Start(WhispernetClient* whispernet_client); 34 // |tokens_cb| is called for all audio tokens found in recorded audio.
35 virtual void Start(WhispernetClient* whispernet_client,
36 const TokensCallback& tokens_cb);
34 37
35 // Adds a directive to handle. 38 // Adds a directive to handle.
36 virtual void AddDirective(const Directive& directive); 39 virtual void AddDirective(const Directive& directive);
37 40
38 // Removes any directives associated with the given operation id. 41 // Removes any directives associated with the given operation id.
39 virtual void RemoveDirectives(const std::string& op_id); 42 virtual void RemoveDirectives(const std::string& op_id);
40 43
44 // TODO(rkc): Too many audio specific functions here, find a better way to
Charlie 2014/11/06 17:28:23 CopresenceManagerImpl::CheckForAudio() probably be
rkc 2014/11/06 19:58:24 It doesn't solve the problem. If we put it in the
Charlie 2014/11/06 21:53:14 I don't actually think the AudioManager should be
rkc 2014/11/06 21:58:34 We can discuss this offline if you wish. I think t
45 // get this information to the copresence manager.
41 virtual const std::string GetCurrentAudioToken(AudioType type) const; 46 virtual const std::string GetCurrentAudioToken(AudioType type) const;
47 virtual bool IsAudioTokenHeard(AudioType type) const;
42 48
43 private: 49 private:
44 // Starts actually running a directive. 50 // Starts actually running a directive.
45 void StartDirective(const std::string& op_id, const Directive& directive); 51 void StartDirective(const std::string& op_id, const Directive& directive);
46 52
47 // Forwards the request to encode a token to whispernet,
48 // and instructs it to call samples_callback when encoding is complete.
49 void EncodeToken(
50 const std::string& token,
51 AudioType type,
52 const WhispernetClient::SamplesCallback& samples_callback);
53
54 scoped_ptr<AudioDirectiveHandler> audio_handler_; 53 scoped_ptr<AudioDirectiveHandler> audio_handler_;
55 std::map<std::string, std::vector<Directive>> pending_directives_; 54 std::map<std::string, std::vector<Directive>> pending_directives_;
56 55
57 // Belongs to the caller. 56 bool is_started_;
58 WhispernetClient* whispernet_client_;
59 57
60 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler); 58 DISALLOW_COPY_AND_ASSIGN(DirectiveHandler);
61 }; 59 };
62 60
63 } // namespace copresence 61 } // namespace copresence
64 62
65 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_ 63 #endif // COMPONENTS_COPRESENCE_HANDLERS_DIRECTIVE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698