OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 <string> |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/serial/serial_api.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 |
| 12 using content::BrowserThread; |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 const char kConnectionIdKey[] = "connectionId"; |
| 17 |
| 18 SerialOpenFunction::SerialOpenFunction() { |
| 19 } |
| 20 |
| 21 SerialOpenFunction::~SerialOpenFunction() { |
| 22 } |
| 23 |
| 24 bool SerialOpenFunction::RunImpl() { |
| 25 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &port_)); |
| 26 |
| 27 bool rv = BrowserThread::PostTask( |
| 28 BrowserThread::IO, FROM_HERE, |
| 29 base::Bind(&SerialOpenFunction::WorkOnIOThread, this)); |
| 30 DCHECK(rv); |
| 31 |
| 32 return true; |
| 33 } |
| 34 |
| 35 void SerialOpenFunction::WorkOnIOThread() { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 37 |
| 38 DictionaryValue* result = new DictionaryValue(); |
| 39 result->SetInteger(kConnectionIdKey, 42); |
| 40 result_.reset(result); |
| 41 |
| 42 bool rv = BrowserThread::PostTask( |
| 43 BrowserThread::UI, FROM_HERE, |
| 44 base::Bind(&SerialOpenFunction::RespondOnUIThread, this)); |
| 45 DCHECK(rv); |
| 46 } |
| 47 |
| 48 void SerialOpenFunction::RespondOnUIThread() { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 50 SendResponse(true); |
| 51 } |
| 52 |
| 53 SerialCloseFunction::SerialCloseFunction() { |
| 54 } |
| 55 |
| 56 SerialCloseFunction::~SerialCloseFunction() { |
| 57 } |
| 58 |
| 59 bool SerialCloseFunction::RunImpl() { |
| 60 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &connection_id_)); |
| 61 |
| 62 bool rv = BrowserThread::PostTask( |
| 63 BrowserThread::IO, FROM_HERE, |
| 64 base::Bind(&SerialCloseFunction::WorkOnIOThread, this)); |
| 65 DCHECK(rv); |
| 66 |
| 67 return true; |
| 68 } |
| 69 |
| 70 void SerialCloseFunction::WorkOnIOThread() { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 72 |
| 73 result_.reset(Value::CreateBooleanValue(true)); |
| 74 |
| 75 bool rv = BrowserThread::PostTask( |
| 76 BrowserThread::UI, FROM_HERE, |
| 77 base::Bind(&SerialCloseFunction::RespondOnUIThread, this)); |
| 78 DCHECK(rv); |
| 79 } |
| 80 |
| 81 void SerialCloseFunction::RespondOnUIThread() { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 83 SendResponse(true); |
| 84 } |
| 85 |
| 86 } // namespace extensions |
OLD | NEW |