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

Unified Diff: chrome/browser/extensions/api/serial/serial_api.cc

Issue 9174019: Add skeleton plumbing for serial API. No functionality yet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/serial/serial_api.cc
diff --git a/chrome/browser/extensions/api/serial/serial_api.cc b/chrome/browser/extensions/api/serial/serial_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da52f5ed4d9a898a1647bdf90ceb86d5a1313090
--- /dev/null
+++ b/chrome/browser/extensions/api/serial/serial_api.cc
@@ -0,0 +1,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
« no previous file with comments | « chrome/browser/extensions/api/serial/serial_api.h ('k') | chrome/browser/extensions/api/serial/serial_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698