| Index: content/child/service_worker/service_worker_provider_context.h
|
| diff --git a/content/child/service_worker/service_worker_provider_context.h b/content/child/service_worker/service_worker_provider_context.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c2eec31ed2cde527c2631b5e578949eda136967f
|
| --- /dev/null
|
| +++ b/content/child/service_worker/service_worker_provider_context.h
|
| @@ -0,0 +1,87 @@
|
| +// 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.
|
| +
|
| +#ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
|
| +#define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
|
| +
|
| +#include <set>
|
| +#include <vector>
|
| +
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/sequenced_task_runner_helpers.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "content/common/service_worker/service_worker_types.h"
|
| +
|
| +namespace base {
|
| +class MessageLoopProxy;
|
| +}
|
| +
|
| +namespace IPC {
|
| +class Message;
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +class ScopedServiceWorkerReference;
|
| +struct ServiceWorkerProviderContextDeleter;
|
| +class ThreadSafeSender;
|
| +
|
| +// An instance of this class holds document-related information (e.g. .current)
|
| +// and can be shared by multiple WebServiceWorkerProviderImpl's across threads
|
| +// (e.g. for dedicated workers created for the document).
|
| +// Created and destructed on the main thread.
|
| +class ServiceWorkerProviderContext
|
| + : public base::RefCountedThreadSafe<ServiceWorkerProviderContext,
|
| + ServiceWorkerProviderContextDeleter> {
|
| + public:
|
| + explicit ServiceWorkerProviderContext(int provider_id);
|
| +
|
| + // Adds and removes a thread where a scriptable provider is running.
|
| + // The Add method also returns information necessary to initialize
|
| + // the provider (i.e. current ServiceWorker info).
|
| + void AddProviderThreadAndGetInitializationInfo(
|
| + int thread_id,
|
| + scoped_ptr<ScopedServiceWorkerReference>* current);
|
| + void RemoveProviderThread(int thread_id);
|
| +
|
| + // Called from ServiceWorkerDispatcher.
|
| + void OnServiceWorkerStateChanged(int thread_id,
|
| + int handle_id,
|
| + blink::WebServiceWorkerState state);
|
| + void OnSetCurrentServiceWorker(int thread_id,
|
| + int provider_id,
|
| + const ServiceWorkerObjectInfo& info);
|
| +
|
| + int provider_id() const { return provider_id_; }
|
| + const ServiceWorkerObjectInfo& current() const;
|
| +
|
| + private:
|
| + friend struct ServiceWorkerProviderContextDeleter;
|
| + friend class base::DeleteHelper<ServiceWorkerProviderContext>;
|
| + friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext,
|
| + ServiceWorkerProviderContextDeleter>;
|
| + ~ServiceWorkerProviderContext();
|
| + void DestructOnMainThread() const;
|
| + void ForwardMessageToProviderThreads(const IPC::Message& message,
|
| + const std::set<int>& thread_ids);
|
| +
|
| + const int provider_id_;
|
| + scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
|
| + scoped_refptr<ThreadSafeSender> thread_safe_sender_;
|
| + mutable base::Lock lock_; // Protects |current_| and |provider_thread_ids_|.
|
| + mutable scoped_ptr<ScopedServiceWorkerReference> current_;
|
| + std::set<int> provider_thread_ids_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext);
|
| +};
|
| +
|
| +struct ServiceWorkerProviderContextDeleter {
|
| + static void Destruct(const ServiceWorkerProviderContext* context) {
|
| + context->DestructOnMainThread();
|
| + }
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
|
|
|