Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / copresence / chrome_whispernet_client.h
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/copresence_constants.h"
14 #include "components/copresence/public/whispernet_client.h"
15
16 namespace content {
17 class BrowserContext;
18 }
19
20 namespace extensions {
21 namespace api {
22 namespace copresence_private {
23 struct AudioParameters;
24 }
25 }
26 }
27
28 namespace media {
29 class AudioBusRefCounted;
30 }
31
32 // This class is responsible for communication with our ledger_proxy extension
33 // that talks to the whispernet audio library.
34 class ChromeWhispernetClient final : public copresence::WhispernetClient {
35  public:
36   // The browser context needs to outlive this class.
37   explicit ChromeWhispernetClient(content::BrowserContext* browser_context);
38   ~ChromeWhispernetClient() override;
39
40   // WhispernetClient overrides:
41   void Initialize(const copresence::SuccessCallback& init_callback) override;
42   void Shutdown() override;
43
44   void EncodeToken(const std::string& token,
45                    copresence::AudioType type) override;
46   void DecodeSamples(copresence::AudioType type,
47                      const std::string& samples) override;
48   void DetectBroadcast() override;
49
50   void RegisterTokensCallback(
51       const copresence::TokensCallback& tokens_callback) override;
52   void RegisterSamplesCallback(
53       const copresence::SamplesCallback& samples_callback) override;
54   void RegisterDetectBroadcastCallback(
55       const copresence::SuccessCallback& db_callback) override;
56
57   copresence::TokensCallback GetTokensCallback() override;
58   copresence::SamplesCallback GetSamplesCallback() override;
59   copresence::SuccessCallback GetDetectBroadcastCallback() override;
60   copresence::SuccessCallback GetInitializedCallback() override;
61
62   static const char kWhispernetProxyExtensionId[];
63
64  private:
65   // Fire an event to initialize whispernet with the given parameters.
66   void InitializeWhispernet(
67       const extensions::api::copresence_private::AudioParameters& params);
68
69   // This gets called twice; once when the proxy extension loads, the second
70   // time when we have initialized the proxy extension's encoder and decoder.
71   void OnExtensionLoaded(bool success);
72
73   content::BrowserContext* browser_context_;
74
75   copresence::SuccessCallback extension_loaded_callback_;
76   copresence::SuccessCallback init_callback_;
77
78   copresence::TokensCallback tokens_callback_;
79   copresence::SamplesCallback samples_callback_;
80   copresence::SuccessCallback db_callback_;
81
82   bool extension_loaded_;
83
84   DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient);
85 };
86
87 #endif  // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_