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.
4
5#ifndef CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_
6#define CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "base/macros.h"
13#include "components/copresence/public/whispernet_client.h"
14
15namespace content {
16class BrowserContext;
17}
18
19namespace extensions {
20namespace api {
21namespace copresence_private {
22struct AudioParameters;
23}
24}
25}
26
27namespace media {
28class AudioBusRefCounted;
29}
30
31// This class is responsible for communication with our ledger_proxy extension
32// that talks to the whispernet audio library.
33class ChromeWhispernetClient : public copresence::WhispernetClient {
34 public:
35  // The browser context needs to outlive this class.
36  explicit ChromeWhispernetClient(content::BrowserContext* browser_context);
37  virtual ~ChromeWhispernetClient();
38
39  // WhispernetClient overrides:
40  virtual void Initialize(const SuccessCallback& init_callback) OVERRIDE;
41  virtual void Shutdown() OVERRIDE;
42
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;
46
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;
53
54  virtual TokensCallback GetTokensCallback() OVERRIDE;
55  virtual SamplesCallback GetSamplesCallback() OVERRIDE;
56  virtual SuccessCallback GetDetectBroadcastCallback() OVERRIDE;
57  virtual SuccessCallback GetInitializedCallback() OVERRIDE;
58
59  static const char kWhispernetProxyExtensionId[];
60
61 private:
62  // Fire an event to initialize whispernet with the given parameters.
63  void InitializeWhispernet(
64      const extensions::api::copresence_private::AudioParameters& params);
65
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);
69
70  content::BrowserContext* browser_context_;
71
72  SuccessCallback extension_loaded_callback_;
73  SuccessCallback init_callback_;
74
75  TokensCallback tokens_callback_;
76  SamplesCallback samples_callback_;
77  SuccessCallback db_callback_;
78
79  bool extension_loaded_;
80
81  DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient);
82};
83
84#endif  // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_
85