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

Unified Diff: content/browser/shared_worker/shared_worker_instance.cc

Issue 177043003: Implement SharedWorkerServiceImpl::CreateWorker and SharedWorkerInstance and SharedWorkerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test for SharedWorkerInstance Created 6 years, 10 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: content/browser/shared_worker/shared_worker_instance.cc
diff --git a/content/common/gpu/media/exynos_v4l2_video_device.cc b/content/browser/shared_worker/shared_worker_instance.cc
similarity index 10%
copy from content/common/gpu/media/exynos_v4l2_video_device.cc
copy to content/browser/shared_worker/shared_worker_instance.cc
index ef40cf0e6854e4a7a9b90aa24d038bfb60977432..a55dd918152761871ea6aa06de5f4e7c0ce82ed7 100644
--- a/content/common/gpu/media/exynos_v4l2_video_device.cc
+++ b/content/browser/shared_worker/shared_worker_instance.cc
@@ -1,117 +1,101 @@
// Copyright 2014 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 <fcntl.h>
-#include <linux/videodev2.h>
-#include <poll.h>
-#include <sys/eventfd.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-
-#include "base/debug/trace_event.h"
-#include "base/posix/eintr_wrapper.h"
-#include "content/common/gpu/media/exynos_v4l2_video_device.h"
-namespace content {
+#include "content/browser/shared_worker/shared_worker_instance.h"
-namespace {
-const char kDevice[] = "/dev/mfc-dec";
-}
+#include "base/logging.h"
+#include "content/browser/worker_host/worker_document_set.h"
-ExynosV4L2Device::ExynosV4L2Device()
- : device_fd_(-1), device_poll_interrupt_fd_(-1) {}
+namespace content {
-ExynosV4L2Device::~ExynosV4L2Device() {
- if (device_poll_interrupt_fd_ != -1) {
- close(device_poll_interrupt_fd_);
- device_poll_interrupt_fd_ = -1;
- }
- if (device_fd_ != -1) {
- close(device_fd_);
- device_fd_ = -1;
- }
+SharedWorkerInstance::SharedWorkerInstance(
+ const GURL& url,
+ const base::string16& name,
+ const base::string16& content_security_policy,
+ blink::WebContentSecurityPolicyType security_policy_type,
+ ResourceContext* resource_context,
+ const WorkerStoragePartition& partition)
+ : url_(url),
+ closed_(false),
+ name_(name),
+ content_security_policy_(content_security_policy),
+ security_policy_type_(security_policy_type),
+ worker_document_set_(new WorkerDocumentSet()),
+ resource_context_(resource_context),
+ partition_(partition),
+ load_failed_(false) {
+ DCHECK(resource_context_);
}
-int ExynosV4L2Device::Ioctl(int request, void* arg) {
- return ioctl(device_fd_, request, arg);
+SharedWorkerInstance::~SharedWorkerInstance() {
}
-bool ExynosV4L2Device::Poll(bool poll_device, bool* event_pending) {
- struct pollfd pollfds[2];
- nfds_t nfds;
- int pollfd = -1;
-
- pollfds[0].fd = device_poll_interrupt_fd_;
- pollfds[0].events = POLLIN | POLLERR;
- nfds = 1;
-
- if (poll_device) {
- DVLOG(3) << "Poll(): adding device fd to poll() set";
- pollfds[nfds].fd = device_fd_;
- pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI;
- pollfd = nfds;
- nfds++;
- }
-
- if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) {
- DPLOG(ERROR) << "poll() failed";
- return false;
+void SharedWorkerInstance::SetMessagePortID(
+ SharedWorkerMessageFilter* filter,
+ int route_id,
+ int message_port_id) {
+ for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) {
+ if (i->filter() == filter && i->route_id() == route_id) {
+ i->set_message_port_id(message_port_id);
+ return;
+ }
}
- *event_pending = (pollfd != -1 && pollfds[pollfd].revents & POLLPRI);
- return true;
}
-void* ExynosV4L2Device::Mmap(void* addr,
- unsigned int len,
- int prot,
- int flags,
- unsigned int offset) {
- return mmap(addr, len, prot, flags, device_fd_, offset);
-}
+bool SharedWorkerInstance::Matches(const GURL& match_url,
+ const base::string16& match_name,
+ const WorkerStoragePartition& partition,
+ ResourceContext* resource_context) const {
+ // Only match open shared workers.
+ if (closed_)
+ return false;
-void ExynosV4L2Device::Munmap(void* addr, unsigned int len) {
- munmap(addr, len);
-}
+ // ResourceContext equivalence is being used as a proxy to ensure we only
+ // matched shared workers within the same BrowserContext.
+ if (resource_context_ != resource_context)
+ return false;
-bool ExynosV4L2Device::SetDevicePollInterrupt() {
- DVLOG(3) << "SetDevicePollInterrupt()";
+ // We must be in the same storage partition otherwise sharing will violate
+ // isolation.
+ if (!partition_.Equals(partition))
+ return false;
- const uint64 buf = 1;
- if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) {
+ if (url_.GetOrigin() != match_url.GetOrigin())
return false;
- }
- return true;
-}
-bool ExynosV4L2Device::ClearDevicePollInterrupt() {
- DVLOG(3) << "ClearDevicePollInterrupt()";
+ if (name_.empty() && match_name.empty())
+ return url_ == match_url;
- uint64 buf;
- if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) {
- if (errno == EAGAIN) {
- // No interrupt flag set, and we're reading nonblocking. Not an error.
- return true;
- } else {
- DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed";
- return false;
- }
+ return name_ == match_name;
+}
+
+void SharedWorkerInstance::AddFilter(SharedWorkerMessageFilter* filter,
+ int route_id) {
+ CHECK(filter);
+ if (!HasFilter(filter, route_id)) {
+ FilterInfo info(filter, route_id);
+ filters_.push_back(info);
}
- return true;
}
-bool ExynosV4L2Device::Initialize() {
- DVLOG(2) << "Initialize(): opening device: " << kDevice;
- // Open the video device.
- device_fd_ = HANDLE_EINTR(open(kDevice, O_RDWR | O_NONBLOCK | O_CLOEXEC));
- if (device_fd_ == -1) {
- return false;
+void SharedWorkerInstance::RemoveFilters(SharedWorkerMessageFilter* filter) {
+ for (FilterList::iterator i = filters_.begin(); i != filters_.end();) {
+ if (i->filter() == filter)
+ i = filters_.erase(i);
+ else
+ ++i;
}
+}
- device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
- if (device_poll_interrupt_fd_ == -1) {
- return false;
+bool SharedWorkerInstance::HasFilter(SharedWorkerMessageFilter* filter,
+ int route_id) const {
+ for (FilterList::const_iterator i = filters_.begin(); i != filters_.end();
+ ++i) {
+ if (i->filter() == filter && i->route_id() == route_id)
+ return true;
}
- return true;
+ return false;
}
-} // namespace content
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698