| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/socket/socket_api.h" | 5 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/socket/socket_api_controller.h" | 9 #include "chrome/browser/extensions/api/socket/socket_api_controller.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 BrowserThread::UI, FROM_HERE, | 42 BrowserThread::UI, FROM_HERE, |
| 43 base::Bind(&SocketApiFunction::RespondOnUIThread, this)); | 43 base::Bind(&SocketApiFunction::RespondOnUIThread, this)); |
| 44 DCHECK(rv); | 44 DCHECK(rv); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SocketApiFunction::RespondOnUIThread() { | 47 void SocketApiFunction::RespondOnUIThread() { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 49 SendResponse(Respond()); | 49 SendResponse(Respond()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 SocketCreateFunction::SocketCreateFunction() |
| 53 : src_id_(-1) {} |
| 54 |
| 52 bool SocketCreateFunction::Prepare() { | 55 bool SocketCreateFunction::Prepare() { |
| 53 std::string socket_type; | 56 std::string socket_type; |
| 54 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type)); | 57 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &socket_type)); |
| 55 | 58 |
| 59 scoped_ptr<DictionaryValue> options(new DictionaryValue()); |
| 60 if (args_->GetSize() >= 2) { |
| 61 DictionaryValue* temp_options = NULL; |
| 62 if (args_->GetDictionary(1, &temp_options)) |
| 63 options.reset(temp_options->DeepCopy()); |
| 64 } |
| 65 |
| 66 // If we tacked on a srcId to the options object, pull it out here to provide |
| 67 // to the Socket. |
| 68 if (options->HasKey(kSrcIdKey)) { |
| 69 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kSrcIdKey, &src_id_)); |
| 70 } |
| 71 |
| 56 // TODO(miket): this constitutes a second form of truth as to the enum | 72 // TODO(miket): this constitutes a second form of truth as to the enum |
| 57 // validity. But our unit-test framework skips the enum validation. So in | 73 // validity. But our unit-test framework skips the enum validation. So in |
| 58 // order to get an invalid-enum test to pass, we need duplicative | 74 // order to get an invalid-enum test to pass, we need duplicative |
| 59 // value-checking. Too bad. Fix this if/when the argument validation code is | 75 // value-checking. Too bad. Fix this if/when the argument validation code is |
| 60 // moved to C++ rather than its current JavaScript form. | 76 // moved to C++ rather than its current JavaScript form. |
| 61 if (socket_type != kUDPSocketType) { | 77 if (socket_type != kUDPSocketType) { |
| 62 return false; | 78 return false; |
| 63 } | 79 } |
| 64 return true; | 80 return true; |
| 65 } | 81 } |
| 66 | 82 |
| 67 void SocketCreateFunction::Work() { | 83 void SocketCreateFunction::Work() { |
| 68 DictionaryValue* result = new DictionaryValue(); | 84 DictionaryValue* result = new DictionaryValue(); |
| 69 int socket_id = controller()->CreateUdp(profile(), extension_id(), | 85 int socket_id = controller()->CreateUdp(profile(), extension_id(), src_id_, |
| 70 source_url()); | 86 source_url()); |
| 71 result->SetInteger(kSocketIdKey, socket_id); | 87 result->SetInteger(kSocketIdKey, socket_id); |
| 72 result_.reset(result); | 88 result_.reset(result); |
| 73 | 89 |
| 74 } | 90 } |
| 75 | 91 |
| 76 bool SocketCreateFunction::Respond() { | 92 bool SocketCreateFunction::Respond() { |
| 77 return true; | 93 return true; |
| 78 } | 94 } |
| 79 | 95 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DictionaryValue* result = new DictionaryValue(); | 148 DictionaryValue* result = new DictionaryValue(); |
| 133 result->SetInteger(kBytesWrittenKey, bytesWritten); | 149 result->SetInteger(kBytesWrittenKey, bytesWritten); |
| 134 result_.reset(result); | 150 result_.reset(result); |
| 135 } | 151 } |
| 136 | 152 |
| 137 bool SocketWriteFunction::Respond() { | 153 bool SocketWriteFunction::Respond() { |
| 138 return true; | 154 return true; |
| 139 } | 155 } |
| 140 | 156 |
| 141 } // namespace extensions | 157 } // namespace extensions |
| OLD | NEW |