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

Side by Side Diff: chrome/browser/extensions/socket_api.cc

Issue 8743017: Real (but naive) UDP socket sending. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Post-try-server fixes. Created 9 years 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 (c) 2011 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/socket_api.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "content/public/browser/browser_thread.h"
10
11 using content::BrowserThread;
12
13 namespace extensions {
14
15 SocketCreateFunction::SocketCreateFunction() {
16 }
17
18 SocketCreateFunction::~SocketCreateFunction() {
19 }
20
21 bool SocketCreateFunction::RunImpl() {
22 std::string socket_type;
23 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type));
24
25 // TODO(miket): this constitutes a second form of truth as to the
26 // enum validity. But our unit-test framework skips the enum
27 // validation. So in order to get an invalid-enum test to pass, we
28 // need duplicative value-checking. Too bad. Fix this if/when the
29 // argument validation code is moved to C++ rather than its current
30 // JavaScript form.
31 if (socket_type != "udp") {
32 return false;
33 }
34
35 bool rv = BrowserThread::PostTask(
36 BrowserThread::IO, FROM_HERE,
37 base::Bind(&SocketCreateFunction::WorkOnIOThread, this));
38 DCHECK(rv);
39 return true;
40 }
41
42 void SocketCreateFunction::WorkOnIOThread() {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
44 DictionaryValue* result = new DictionaryValue();
45 result->SetInteger("socketId", 42);
46 result_.reset(result);
47 bool rv = BrowserThread::PostTask(
48 BrowserThread::UI, FROM_HERE,
49 base::Bind(&SocketCreateFunction::RespondOnUIThread, this));
50 DCHECK(rv);
51 }
52
53 void SocketCreateFunction::RespondOnUIThread() {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 SendResponse(true);
56 }
57
58 SocketConnectFunction::SocketConnectFunction() {
59 }
60
61 SocketConnectFunction::~SocketConnectFunction() {
62 }
63
64 bool SocketConnectFunction::RunImpl() {
65 std::string socket_type;
66 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type));
67
68 bool rv = BrowserThread::PostTask(
69 BrowserThread::IO, FROM_HERE,
70 base::Bind(&SocketConnectFunction::WorkOnIOThread, this));
71 DCHECK(rv);
72 return true;
73 }
74
75 void SocketConnectFunction::WorkOnIOThread() {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77 result_.reset(Value::CreateIntegerValue(4));
78 bool rv = BrowserThread::PostTask(
79 BrowserThread::UI, FROM_HERE,
80 base::Bind(&SocketConnectFunction::RespondOnUIThread, this));
81 DCHECK(rv);
82 }
83
84 void SocketConnectFunction::RespondOnUIThread() {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
86 SendResponse(true);
87 }
88
89 SocketDisconnectFunction::SocketDisconnectFunction() {
90 }
91
92 SocketDisconnectFunction::~SocketDisconnectFunction() {
93 }
94
95 bool SocketDisconnectFunction::RunImpl() {
96 std::string socket_type;
97 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type));
98
99 bool rv = BrowserThread::PostTask(
100 BrowserThread::IO, FROM_HERE,
101 base::Bind(&SocketDisconnectFunction::WorkOnIOThread, this));
102 DCHECK(rv);
103 return true;
104 }
105
106 void SocketDisconnectFunction::WorkOnIOThread() {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
108 result_.reset(Value::CreateIntegerValue(4));
109 bool rv = BrowserThread::PostTask(
110 BrowserThread::UI, FROM_HERE,
111 base::Bind(&SocketDisconnectFunction::RespondOnUIThread, this));
112 DCHECK(rv);
113 }
114
115 void SocketDisconnectFunction::RespondOnUIThread() {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 SendResponse(true);
118 }
119
120 SocketSendFunction::SocketSendFunction() {
121 }
122
123 SocketSendFunction::~SocketSendFunction() {
124 }
125
126 bool SocketSendFunction::RunImpl() {
127 std::string socket_type;
128 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type));
129
130 bool rv = BrowserThread::PostTask(
131 BrowserThread::IO, FROM_HERE,
132 base::Bind(&SocketSendFunction::WorkOnIOThread, this));
133 DCHECK(rv);
134 return true;
135 }
136
137 void SocketSendFunction::WorkOnIOThread() {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
139 result_.reset(Value::CreateIntegerValue(4));
140 bool rv = BrowserThread::PostTask(
141 BrowserThread::UI, FROM_HERE,
142 base::Bind(&SocketSendFunction::RespondOnUIThread, this));
143 DCHECK(rv);
144 }
145
146 void SocketSendFunction::RespondOnUIThread() {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 SendResponse(true);
149 }
150
151 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698