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 namespace { |
17 // CopresenceAPI service which will actually give us the whispernet client. | 18 |
18 // Once we add that code, both the g_whispernet_client and the | 19 copresence::WhispernetClient* GetWhispernetClient( |
19 // GetWhispernetClient function will go away, to be replaced by the | 20 content::BrowserContext* browser_context) { |
20 // GetWhispernetClient function that will fetch our active whispernet client | 21 extensions::CopresenceService* service = |
21 // from the CopresenceAPI profile keyed service. | 22 extensions::CopresenceService::GetFactoryInstance()->Get(browser_context); |
22 copresence::WhispernetClient* g_whispernet_client = NULL; | 23 return service ? service->whispernet_client() : NULL; |
| 24 } |
| 25 |
| 26 } // namespace |
23 | 27 |
24 // Copresence Private functions. | 28 // Copresence Private functions. |
25 | 29 |
26 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { | 30 copresence::WhispernetClient* CopresencePrivateFunction::GetWhispernetClient() { |
27 // This is temporary code, this needs to be replaced by the real | 31 return extensions::GetWhispernetClient(browser_context()); |
28 // GetWhispernetClient code from c/b/e/api/copresence/copresence_util.h | |
29 DCHECK(g_whispernet_client); | |
30 return g_whispernet_client; | |
31 } | 32 } |
32 | 33 |
33 // CopresenceSendFoundFunction implementation: | 34 // CopresenceSendFoundFunction implementation: |
34 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { | 35 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { |
35 if (!GetWhispernetClient() || | 36 if (!GetWhispernetClient() || |
36 GetWhispernetClient()->GetTokensCallback().is_null()) { | 37 GetWhispernetClient()->GetTokensCallback().is_null()) { |
37 return RespondNow(NoArguments()); | 38 return RespondNow(NoArguments()); |
38 } | 39 } |
39 | 40 |
40 scoped_ptr<api::copresence_private::SendFound::Params> params( | 41 scoped_ptr<api::copresence_private::SendFound::Params> params( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 92 } |
92 | 93 |
93 scoped_ptr<api::copresence_private::SendInitialized::Params> params( | 94 scoped_ptr<api::copresence_private::SendInitialized::Params> params( |
94 api::copresence_private::SendInitialized::Params::Create(*args_)); | 95 api::copresence_private::SendInitialized::Params::Create(*args_)); |
95 EXTENSION_FUNCTION_VALIDATE(params.get()); | 96 EXTENSION_FUNCTION_VALIDATE(params.get()); |
96 | 97 |
97 GetWhispernetClient()->GetInitializedCallback().Run(params->success); | 98 GetWhispernetClient()->GetInitializedCallback().Run(params->success); |
98 return RespondNow(NoArguments()); | 99 return RespondNow(NoArguments()); |
99 } | 100 } |
100 | 101 |
101 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) { | |
102 g_whispernet_client = client; | |
103 } | |
104 | |
105 } // namespace extensions | 102 } // namespace extensions |
OLD | NEW |