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_EXTENSIONS_API_COPRESENCE_PRIVATE_COPRESENCE_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_PRIVATE_COPRESENCE_PRIVATE_API_H_
10 #include "base/macros.h"
11 #include "extensions/browser/browser_context_keyed_api_factory.h"
12 #include "extensions/browser/extension_function.h"
13 #include "extensions/browser/extension_function_histogram_value.h"
15 namespace audio_modem
{
16 class WhispernetClient
;
19 namespace extensions
{
21 class CopresencePrivateService final
: public BrowserContextKeyedAPI
{
23 explicit CopresencePrivateService(content::BrowserContext
* context
);
24 ~CopresencePrivateService() override
;
26 // Registers a client to receive events from Whispernet.
28 RegisterWhispernetClient(audio_modem::WhispernetClient
* client
);
30 // Gets the whispernet client by ID.
31 audio_modem::WhispernetClient
* GetWhispernetClient(const std::string
& id
);
33 // Called from the whispernet_proxy extension when it has initialized.
34 void OnWhispernetInitialized(bool success
);
36 // BrowserContextKeyedAPI implementation.
37 static BrowserContextKeyedAPIFactory
<CopresencePrivateService
>*
41 friend class BrowserContextKeyedAPIFactory
<CopresencePrivateService
>;
43 // BrowserContextKeyedAPI implementation.
44 static const bool kServiceRedirectedInIncognito
= true;
45 static const char* service_name() { return "CopresencePrivateService"; }
48 std::map
<std::string
, audio_modem::WhispernetClient
*> whispernet_clients_
;
50 DISALLOW_COPY_AND_ASSIGN(CopresencePrivateService
);
54 void BrowserContextKeyedAPIFactory
<CopresencePrivateService
>
55 ::DeclareFactoryDependencies();
57 class CopresencePrivateSendFoundFunction
: public UIThreadExtensionFunction
{
59 DECLARE_EXTENSION_FUNCTION("copresencePrivate.sendFound",
60 COPRESENCEPRIVATE_SENDFOUND
);
63 ~CopresencePrivateSendFoundFunction() override
{}
64 ExtensionFunction::ResponseAction
Run() override
;
67 class CopresencePrivateSendSamplesFunction
: public UIThreadExtensionFunction
{
69 DECLARE_EXTENSION_FUNCTION("copresencePrivate.sendSamples",
70 COPRESENCEPRIVATE_SENDSAMPLES
);
73 ~CopresencePrivateSendSamplesFunction() override
{}
74 ExtensionFunction::ResponseAction
Run() override
;
77 class CopresencePrivateSendDetectFunction
: public UIThreadExtensionFunction
{
79 DECLARE_EXTENSION_FUNCTION("copresencePrivate.sendDetect",
80 COPRESENCEPRIVATE_SENDDETECT
);
83 ~CopresencePrivateSendDetectFunction() override
{}
84 ExtensionFunction::ResponseAction
Run() override
;
87 class CopresencePrivateSendInitializedFunction
88 : public UIThreadExtensionFunction
{
90 DECLARE_EXTENSION_FUNCTION("copresencePrivate.sendInitialized",
91 COPRESENCEPRIVATE_SENDINITIALIZED
);
94 ~CopresencePrivateSendInitializedFunction() override
{}
95 ExtensionFunction::ResponseAction
Run() override
;
98 } // namespace extensions
100 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_PRIVATE_COPRESENCE_PRIVATE_API_H_