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 CopresenceService* service = |
28 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h | 21 CopresenceService::GetFactoryInstance()->Get(browser_context()); |
29 DCHECK(g_whispernet_client); | 22 return service ? service->whispernet_client() : NULL; |
30 return g_whispernet_client; | |
31 } | 23 } |
32 | 24 |
33 // CopresenceSendFoundFunction implementation: | 25 // CopresenceSendFoundFunction implementation: |
34 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 26 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
35 if (!GetWhispernetClient() || | 27 if (!GetWhispernetClient() || |
36 GetWhispernetClient()->GetTokensCallback().is_null()) { | 28 GetWhispernetClient()->GetTokensCallback().is_null()) { |
37 return RespondNow(NoArguments()); | 29 return RespondNow(NoArguments()); |
38 } | 30 } |
39 | 31 |
40 scoped_ptr<api::copresence_private::SendFound::Params> params( | 32 scoped_ptr<api::copresence_private::SendFound::Params> params( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 83 } |
92 | 84 |
93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 85 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
94 api::copresence_private::SendInitialized::Params::Create(*args_)); | 86 api::copresence_private::SendInitialized::Params::Create(*args_)); |
95 EXTENSION_FUNCTION_VALIDATE(params.get()); | 87 EXTENSION_FUNCTION_VALIDATE(params.get()); |
96 | 88 |
97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 89 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
98 return RespondNow(NoArguments()); | 90 return RespondNow(NoArguments()); |
99 } | 91 } |
100 | 92 |
101 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) { | |
102 g_whispernet_client = client; | |
103 } | |
104 | |
105 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |