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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_
6 #define CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h"
13 #include "chrome/browser/copresence/chrome_whispernet_config.h"
14 #include "components/audio_modem/public/whispernet_client.h"
20 namespace extensions
{
26 namespace copresence_private
{
27 struct AudioParameters
;
31 } // namespace extensions
34 class AudioBusRefCounted
;
37 // This class is responsible for communication with our whispernet_proxy
38 // extension that talks to the whispernet audio library.
39 class ChromeWhispernetClient final
: public audio_modem::WhispernetClient
{
41 // The browser context needs to outlive this class.
42 explicit ChromeWhispernetClient(content::BrowserContext
* browser_context
);
43 ~ChromeWhispernetClient() override
;
45 // WhispernetClient overrides:
46 void Initialize(const audio_modem::SuccessCallback
& init_callback
) override
;
47 void EncodeToken(const std::string
& token_str
,
48 audio_modem::AudioType type
,
49 const audio_modem::TokenParameters token_params
[2]) override
;
51 audio_modem::AudioType type
,
52 const std::string
& samples
,
53 const audio_modem::TokenParameters token_params
[2]) override
;
54 void RegisterTokensCallback(
55 const audio_modem::TokensCallback
& tokens_callback
) override
;
56 void RegisterSamplesCallback(
57 const audio_modem::SamplesCallback
& samples_callback
) override
;
59 audio_modem::TokensCallback
GetTokensCallback() override
;
60 audio_modem::SamplesCallback
GetSamplesCallback() override
;
61 audio_modem::SuccessCallback
GetInitializedCallback() override
;
63 static const char kWhispernetProxyExtensionId
[];
66 // Fire an event to configure whispernet with the given audio parameters.
67 void AudioConfiguration(const AudioParamData
& params
);
69 void SendEventIfLoaded(scoped_ptr
<extensions::Event
> event
);
71 // This gets called when the proxy extension loads.
72 void OnExtensionLoaded(bool success
);
74 content::BrowserContext
* const browser_context_
;
75 extensions::EventRouter
* const event_router_
;
76 std::string client_id_
;
78 audio_modem::SuccessCallback extension_loaded_callback_
;
79 audio_modem::SuccessCallback init_callback_
;
81 audio_modem::TokensCallback tokens_callback_
;
82 audio_modem::SamplesCallback samples_callback_
;
84 ScopedVector
<extensions::Event
> queued_events_
;
85 bool extension_loaded_
;
87 DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient
);
90 #endif // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_