| OLD | NEW |
| 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 CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ |
| 6 #define CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | 6 #define CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "components/copresence/public/copresence_constants.h" | 13 #include "chrome/browser/copresence/chrome_whispernet_config.h" |
| 14 #include "components/copresence/public/whispernet_client.h" | 14 #include "components/audio_modem/public/whispernet_client.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class BrowserContext; | 17 class BrowserContext; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 struct Event; | 22 struct Event; |
| 23 class EventRouter; | 23 class EventRouter; |
| 24 | 24 |
| 25 namespace api { | 25 namespace api { |
| 26 namespace copresence_private { | 26 namespace copresence_private { |
| 27 struct AudioParameters; | 27 struct AudioParameters; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace extensions | 31 } // namespace extensions |
| 32 | 32 |
| 33 namespace media { | 33 namespace media { |
| 34 class AudioBusRefCounted; | 34 class AudioBusRefCounted; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // This class is responsible for communication with our ledger_proxy extension | 37 // This class is responsible for communication with our whispernet_proxy |
| 38 // that talks to the whispernet audio library. | 38 // extension that talks to the whispernet audio library. |
| 39 class ChromeWhispernetClient final : public copresence::WhispernetClient { | 39 class ChromeWhispernetClient final : public audio_modem::WhispernetClient { |
| 40 public: | 40 public: |
| 41 // The browser context needs to outlive this class. | 41 // The browser context needs to outlive this class. |
| 42 explicit ChromeWhispernetClient(content::BrowserContext* browser_context); | 42 explicit ChromeWhispernetClient(content::BrowserContext* browser_context); |
| 43 ~ChromeWhispernetClient() override; | 43 ~ChromeWhispernetClient() override; |
| 44 | 44 |
| 45 // WhispernetClient overrides: | 45 // WhispernetClient overrides: |
| 46 void Initialize(const copresence::SuccessCallback& init_callback) override; | 46 void Initialize(const audio_modem::SuccessCallback& init_callback) override; |
| 47 void Shutdown() override; | |
| 48 void EncodeToken(const std::string& token_str, | 47 void EncodeToken(const std::string& token_str, |
| 49 copresence::AudioType type) override; | 48 audio_modem::AudioType type) override; |
| 50 void DecodeSamples(copresence::AudioType type, | 49 void DecodeSamples(audio_modem::AudioType type, |
| 51 const std::string& samples, | 50 const std::string& samples, |
| 52 const size_t token_length[2]) override; | 51 const size_t token_length[2]) override; |
| 53 void DetectBroadcast() override; | 52 void DetectBroadcast() override; |
| 54 void RegisterTokensCallback( | 53 void RegisterTokensCallback( |
| 55 const copresence::TokensCallback& tokens_callback) override; | 54 const audio_modem::TokensCallback& tokens_callback) override; |
| 56 void RegisterSamplesCallback( | 55 void RegisterSamplesCallback( |
| 57 const copresence::SamplesCallback& samples_callback) override; | 56 const audio_modem::SamplesCallback& samples_callback) override; |
| 58 void RegisterDetectBroadcastCallback( | 57 void RegisterDetectBroadcastCallback( |
| 59 const copresence::SuccessCallback& db_callback) override; | 58 const audio_modem::SuccessCallback& db_callback) override; |
| 60 | 59 |
| 61 copresence::TokensCallback GetTokensCallback() override; | 60 audio_modem::TokensCallback GetTokensCallback() override; |
| 62 copresence::SamplesCallback GetSamplesCallback() override; | 61 audio_modem::SamplesCallback GetSamplesCallback() override; |
| 63 copresence::SuccessCallback GetDetectBroadcastCallback() override; | 62 audio_modem::SuccessCallback GetDetectBroadcastCallback() override; |
| 64 copresence::SuccessCallback GetInitializedCallback() override; | 63 audio_modem::SuccessCallback GetInitializedCallback() override; |
| 65 | 64 |
| 66 static const char kWhispernetProxyExtensionId[]; | 65 static const char kWhispernetProxyExtensionId[]; |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 // Fire an event to configure whispernet with the given audio parameters. | 68 // Fire an event to configure whispernet with the given audio parameters. |
| 70 void AudioConfiguration(const copresence::config::AudioParamData& params); | 69 void AudioConfiguration(const AudioParamData& params); |
| 71 | 70 |
| 72 void SendEventIfLoaded(scoped_ptr<extensions::Event> event); | 71 void SendEventIfLoaded(scoped_ptr<extensions::Event> event); |
| 73 | 72 |
| 74 // This gets called twice; once when the proxy extension loads, the second | 73 // This gets called twice; once when the proxy extension loads, the second |
| 75 // time when we have initialized the proxy extension's encoder and decoder. | 74 // time when we have initialized the proxy extension's encoder and decoder. |
| 76 void OnExtensionLoaded(bool success); | 75 void OnExtensionLoaded(bool success); |
| 77 | 76 |
| 78 content::BrowserContext* const browser_context_; | 77 content::BrowserContext* const browser_context_; |
| 79 extensions::EventRouter* const event_router_; | 78 extensions::EventRouter* const event_router_; |
| 80 | 79 |
| 81 copresence::SuccessCallback extension_loaded_callback_; | 80 audio_modem::SuccessCallback extension_loaded_callback_; |
| 82 copresence::SuccessCallback init_callback_; | 81 audio_modem::SuccessCallback init_callback_; |
| 83 | 82 |
| 84 copresence::TokensCallback tokens_callback_; | 83 audio_modem::TokensCallback tokens_callback_; |
| 85 copresence::SamplesCallback samples_callback_; | 84 audio_modem::SamplesCallback samples_callback_; |
| 86 copresence::SuccessCallback db_callback_; | 85 audio_modem::SuccessCallback db_callback_; |
| 87 | 86 |
| 88 ScopedVector<extensions::Event> queued_events_; | 87 ScopedVector<extensions::Event> queued_events_; |
| 89 bool extension_loaded_; | 88 bool extension_loaded_; |
| 90 | 89 |
| 91 DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient); | 90 DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient); |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 #endif // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | 93 #endif // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ |
| OLD | NEW |