Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: chrome/browser/extensions/api/copresence_private/copresence_private_api.cc

Issue 438513002: Add the whispernet proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap i.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h"
9 #include "chrome/browser/copresence/chrome_whispernet_client.h"
10 #include "chrome/common/extensions/api/copresence_private.h"
11 #include "components/copresence/public/whispernet_client.h"
12 #include "media/base/audio_bus.h"
13
14 namespace extensions {
15
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, this entire namespace will go away.
19 namespace util {
not at google - send to devlin 2014/07/31 15:24:17 I don't think the namespace is necessary.
rkc 2014/07/31 23:12:52 Done.
20
21 copresence::WhispernetClient* g_whispernet_client = NULL;
22
23 copresence::WhispernetClient* GetWhispernetClient(
24 content::BrowserContext* context) {
25 if (!g_whispernet_client)
26 g_whispernet_client = new ChromeWhispernetClient(context);
not at google - send to devlin 2014/07/31 15:24:17 this is a leak, use base::LazyInstance.
rkc 2014/07/31 23:12:53 This code will never get exercised, removed. This
27 return g_whispernet_client;
28 }
29
30 } // namespace util
31
32 // Copresence Private functions.
33
34 // CopresenceSendFoundFunction implementation:
35 bool CopresencePrivateSendFoundFunction::RunSync() {
36 if (!util::GetWhispernetClient(browser_context()) ||
not at google - send to devlin 2014/07/31 15:24:17 how can !util::GetWhispernetClient(browser_context
rkc 2014/07/31 23:12:52 Answered in the comment above :) The current GetWh
not at google - send to devlin 2014/07/31 23:31:17 you haven't Done the second part of this comment.
rkc 2014/08/01 19:20:00 Done.
37 util::GetWhispernetClient(browser_context())
38 ->GetTokensCallback()
39 .is_null()) {
40 return true;
not at google - send to devlin 2014/07/31 15:24:17 seems like this should be an error?
rkc 2014/07/31 23:12:52 If we don't have a callback registered right now,
41 }
42
43 scoped_ptr<api::copresence_private::SendFound::Params> params(
44 api::copresence_private::SendFound::Params::Create(*args_));
45 EXTENSION_FUNCTION_VALIDATE(params.get());
46 util::GetWhispernetClient(browser_context())->GetTokensCallback().Run(
47 params->tokens);
48 return true;
49 }
50
51 // CopresenceSendEncodedFunction implementation:
52 bool CopresencePrivateSendSamplesFunction::RunSync() {
53 if (!util::GetWhispernetClient(browser_context()) ||
54 util::GetWhispernetClient(browser_context())
55 ->GetSamplesCallback()
56 .is_null()) {
57 return true;
58 }
59
60 scoped_ptr<api::copresence_private::SendSamples::Params> params(
61 api::copresence_private::SendSamples::Params::Create(*args_));
62 EXTENSION_FUNCTION_VALIDATE(params.get());
63
64 scoped_refptr<media::AudioBusRefCounted> samples =
65 media::AudioBusRefCounted::Create(1,
66 params->samples.size() / sizeof(float));
67
68 memcpy(samples->channel(0),
69 string_as_array(&params->samples),
70 params->samples.size());
not at google - send to devlin 2014/07/31 15:24:17 this doesn't look safe to me, where is the guarant
rkc 2014/07/31 23:12:52 The AudioBusRefCounted constructor ensures that we
71
72 util::GetWhispernetClient(browser_context())->GetSamplesCallback().Run(
73 params->token, samples);
not at google - send to devlin 2014/07/31 15:24:17 should this take ownership of |samples|, and |samp
rkc 2014/07/31 23:12:52 We store the samples in STL data structures, and i
not at google - send to devlin 2014/07/31 23:31:17 ref counting doesn't make good interfaces. It seem
rkc 2014/08/01 19:20:00 Discussed offline.
74 return true;
75 }
76
77 // CopresenceSendDetectFunction implementation:
78 bool CopresencePrivateSendDetectFunction::RunSync() {
79 if (!util::GetWhispernetClient(browser_context()) ||
80 util::GetWhispernetClient(browser_context())
81 ->GetDetectBroadcastCallback()
82 .is_null()) {
83 return true;
84 }
85
86 scoped_ptr<api::copresence_private::SendDetect::Params> params(
87 api::copresence_private::SendDetect::Params::Create(*args_));
88 EXTENSION_FUNCTION_VALIDATE(params.get());
89
90 util::GetWhispernetClient(browser_context())
91 ->GetDetectBroadcastCallback()
92 .Run(params->detected);
93 return true;
94 }
95
96 // CopresenceSendInitializedFunction implementation:
97 bool CopresencePrivateSendInitializedFunction::RunSync() {
98 LOG(ERROR) << "RKC: Got Init! context is: " << browser_context();
not at google - send to devlin 2014/07/31 15:24:17 remove debugging?
rkc 2014/07/31 23:12:52 Whoops. Done.
99
100 if (!util::GetWhispernetClient(browser_context()) ||
101 util::GetWhispernetClient(browser_context())
102 ->GetInitializedCallback()
103 .is_null()) {
104 return true;
105 }
106
107 LOG(ERROR) << "RKC: Got Init and got profile!!";
not at google - send to devlin 2014/07/31 15:24:17 remove debugging?
rkc 2014/07/31 23:12:52 Done.
108
109 scoped_ptr<api::copresence_private::SendInitialized::Params> params(
110 api::copresence_private::SendInitialized::Params::Create(*args_));
111 EXTENSION_FUNCTION_VALIDATE(params.get());
112
113 util::GetWhispernetClient(browser_context())->GetInitializedCallback().Run(
114 params->success);
115 return true;
116 }
117
118 void SetWhispernetClientForTesting(copresence::WhispernetClient* client) {
119 util::g_whispernet_client = client;
120 }
121
122 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698