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_
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "components/copresence/public/whispernet_client.h"
19 namespace extensions
{
21 namespace copresence_private
{
22 struct AudioParameters
;
28 class AudioBusRefCounted
;
31 // This class is responsible for communication with our ledger_proxy extension
32 // that talks to the whispernet audio library.
33 class ChromeWhispernetClient
: public copresence::WhispernetClient
{
35 // The browser context needs to outlive this class.
36 explicit ChromeWhispernetClient(content::BrowserContext
* browser_context
);
37 virtual ~ChromeWhispernetClient();
39 // WhispernetClient overrides:
40 virtual void Initialize(const SuccessCallback
& init_callback
) OVERRIDE
;
41 virtual void Shutdown() OVERRIDE
;
43 virtual void EncodeToken(const std::string
& token
, bool audible
) OVERRIDE
;
44 virtual void DecodeSamples(const std::string
& samples
) OVERRIDE
;
45 virtual void DetectBroadcast() OVERRIDE
;
47 virtual void RegisterTokensCallback(
48 const TokensCallback
& tokens_callback
) OVERRIDE
;
49 virtual void RegisterSamplesCallback(
50 const SamplesCallback
& samples_callback
) OVERRIDE
;
51 virtual void RegisterDetectBroadcastCallback(
52 const SuccessCallback
& db_callback
) OVERRIDE
;
54 virtual TokensCallback
GetTokensCallback() OVERRIDE
;
55 virtual SamplesCallback
GetSamplesCallback() OVERRIDE
;
56 virtual SuccessCallback
GetDetectBroadcastCallback() OVERRIDE
;
57 virtual SuccessCallback
GetInitializedCallback() OVERRIDE
;
59 static const char kWhispernetProxyExtensionId
[];
62 // Fire an event to initialize whispernet with the given parameters.
63 void InitializeWhispernet(
64 const extensions::api::copresence_private::AudioParameters
& params
);
66 // This gets called twice; once when the proxy extension loads, the second
67 // time when we have initialized the proxy extension's encoder and decoder.
68 void OnExtensionLoaded(bool success
);
70 content::BrowserContext
* browser_context_
;
72 SuccessCallback extension_loaded_callback_
;
73 SuccessCallback init_callback_
;
75 TokensCallback tokens_callback_
;
76 SamplesCallback samples_callback_
;
77 SuccessCallback db_callback_
;
79 bool extension_loaded_
;
81 DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient
);
84 #endif // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_