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 <vector> |
| 8 |
7 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "chrome/browser/copresence/chrome_whispernet_client.h" | 11 #include "chrome/browser/copresence/chrome_whispernet_client.h" |
10 #include "chrome/browser/extensions/api/copresence/copresence_api.h" | 12 #include "chrome/browser/extensions/api/copresence/copresence_api.h" |
11 #include "chrome/common/extensions/api/copresence_private.h" | 13 #include "chrome/common/extensions/api/copresence_private.h" |
12 #include "components/copresence/public/whispernet_client.h" | 14 #include "components/copresence/public/whispernet_client.h" |
13 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
14 | 16 |
15 namespace extensions { | 17 namespace extensions { |
16 | 18 |
17 // Copresence Private functions. | 19 // Copresence Private functions. |
18 | 20 |
19 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | 21 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { |
20 CopresenceService* service = | 22 CopresenceService* service = |
21 CopresenceService::GetFactoryInstance()->Get(browser_context()); | 23 CopresenceService::GetFactoryInstance()->Get(browser_context()); |
22 return service ? service->whispernet_client() : NULL; | 24 return service ? service->whispernet_client() : NULL; |
23 } | 25 } |
24 | 26 |
25 // CopresenceSendFoundFunction implementation: | 27 // CopresenceSendFoundFunction implementation: |
26 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 28 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
27 if (!GetWhispernetClient() || | 29 if (!GetWhispernetClient() || |
28 GetWhispernetClient()->GetTokensCallback().is_null()) { | 30 GetWhispernetClient()->GetTokensCallback().is_null()) { |
29 return RespondNow(NoArguments()); | 31 return RespondNow(NoArguments()); |
30 } | 32 } |
31 | 33 |
32 scoped_ptr<api::copresence_private::SendFound::Params> params( | 34 scoped_ptr<api::copresence_private::SendFound::Params> params( |
33 api::copresence_private::SendFound::Params::Create(*args_)); | 35 api::copresence_private::SendFound::Params::Create(*args_)); |
34 EXTENSION_FUNCTION_VALIDATE(params.get()); | 36 EXTENSION_FUNCTION_VALIDATE(params.get()); |
35 std::vector<copresence::FullToken> tokens; | 37 std::vector<copresence::AudioToken> tokens; |
36 for (size_t i = 0; i < params->tokens.size(); ++i) { | 38 for (size_t i = 0; i < params->tokens.size(); ++i) { |
37 tokens.push_back(copresence::FullToken(params->tokens[i]->token, | 39 tokens.push_back(copresence::AudioToken(params->tokens[i]->token, |
38 params->tokens[i]->audible)); | 40 params->tokens[i]->audible)); |
39 } | 41 } |
40 GetWhispernetClient()->GetTokensCallback().Run(tokens); | 42 GetWhispernetClient()->GetTokensCallback().Run(tokens); |
41 return RespondNow(NoArguments()); | 43 return RespondNow(NoArguments()); |
42 } | 44 } |
43 | 45 |
44 // CopresenceSendEncodedFunction implementation: | 46 // CopresenceSendEncodedFunction implementation: |
45 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { | 47 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { |
46 if (!GetWhispernetClient() || | 48 if (!GetWhispernetClient() || |
47 GetWhispernetClient()->GetSamplesCallback().is_null()) { | 49 GetWhispernetClient()->GetSamplesCallback().is_null()) { |
48 return RespondNow(NoArguments()); | 50 return RespondNow(NoArguments()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 92 |
91 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
92 api::copresence_private::SendInitialized::Params::Create(*args_)); | 94 api::copresence_private::SendInitialized::Params::Create(*args_)); |
93 EXTENSION_FUNCTION_VALIDATE(params.get()); | 95 EXTENSION_FUNCTION_VALIDATE(params.get()); |
94 | 96 |
95 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
96 return RespondNow(NoArguments()); | 98 return RespondNow(NoArguments()); |
97 } | 99 } |
98 | 100 |
99 } // namespace extensions | 101 } // namespace extensions |
OLD | NEW |