OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" | 5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap
i.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 9 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
| 10 #include "chrome/browser/extensions/api/copresence/copresence_api.h" |
10 #include "chrome/common/extensions/api/copresence_private.h" | 11 #include "chrome/common/extensions/api/copresence_private.h" |
11 #include "components/copresence/public/whispernet_client.h" | 12 #include "components/copresence/public/whispernet_client.h" |
12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
16 // This code is only for testing while we don't have the rest of the | |
17 // CopresenceAPI service which will actually give us the whispernet client. | |
18 // Once we add that code, both the g_whispernet_client and the | |
19 // GetWhispernetClient function will go away, to be replaced by the | |
20 // GetWhispernetClient function that will fetch our active whispernet client | |
21 // from the CopresenceAPI profile keyed service. | |
22 copresence::WhispernetClient* g_whispernet_client = NULL; | |
23 | |
24 // Copresence Private functions. | 17 // Copresence Private functions. |
25 | 18 |
26 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | 19 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { |
27 // This is temporary code, this needs to be replaced by the real | 20 extensions::CopresenceService* service = |
28 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h | 21 extensions::CopresenceService::GetFactoryInstance()->Get( |
29 DCHECK(g_whispernet_client); | 22 browser_context()); |
30 return g_whispernet_client; | 23 return service ? service->whispernet_client() : NULL; |
31 } | 24 } |
32 | 25 |
33 // CopresenceSendFoundFunction implementation: | 26 // CopresenceSendFoundFunction implementation: |
34 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 27 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
35 if (!GetWhispernetClient() || | 28 if (!GetWhispernetClient() || |
36 GetWhispernetClient()->GetTokensCallback().is_null()) { | 29 GetWhispernetClient()->GetTokensCallback().is_null()) { |
37 return RespondNow(NoArguments()); | 30 return RespondNow(NoArguments()); |
38 } | 31 } |
39 | 32 |
40 scoped_ptr<api::copresence_private::SendFound::Params> params( | 33 scoped_ptr<api::copresence_private::SendFound::Params> params( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 84 } |
92 | 85 |
93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 86 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
94 api::copresence_private::SendInitialized::Params::Create(*args_)); | 87 api::copresence_private::SendInitialized::Params::Create(*args_)); |
95 EXTENSION_FUNCTION_VALIDATE(params.get()); | 88 EXTENSION_FUNCTION_VALIDATE(params.get()); |
96 | 89 |
97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 90 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
98 return RespondNow(NoArguments()); | 91 return RespondNow(NoArguments()); |
99 } | 92 } |
100 | 93 |
101 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) { | |
102 g_whispernet_client = client; | |
103 } | |
104 | |
105 } // namespace extensions | 94 } // namespace extensions |
OLD | NEW |