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