1 // Copyright 2014 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.
5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/singleton.h"
10 #include "base/observer_list.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/worker_service.h"
15 struct ViewHostMsg_CreateWorker_Params;
23 class SharedWorkerMessageFilter;
24 class ResourceContext;
25 class WorkerServiceObserver;
26 class WorkerStoragePartition;
28 // If "enable-embedded-shared-worker" is set this class will be used instead of
30 // TODO(horo): implement this class.
31 class CONTENT_EXPORT SharedWorkerServiceImpl
32 : public NON_EXPORTED_BASE(WorkerService) {
34 // Returns the SharedWorkerServiceImpl singleton.
35 static SharedWorkerServiceImpl* GetInstance();
37 // WorkerService implementation:
38 virtual bool TerminateWorker(int process_id, int route_id) OVERRIDE;
39 virtual std::vector<WorkerInfo> GetWorkers() OVERRIDE;
40 virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE;
41 virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE;
43 // These methods correspond to worker related IPCs.
44 void CreateWorker(const ViewHostMsg_CreateWorker_Params& params,
46 SharedWorkerMessageFilter* filter,
47 ResourceContext* resource_context,
48 const WorkerStoragePartition& worker_partition,
50 void ForwardToWorker(const IPC::Message& message,
51 SharedWorkerMessageFilter* filter);
52 void DocumentDetached(unsigned long long document_id,
53 SharedWorkerMessageFilter* filter);
54 void WorkerContextClosed(int worker_route_id,
55 SharedWorkerMessageFilter* filter);
56 void WorkerContextDestroyed(int worker_route_id,
57 SharedWorkerMessageFilter* filter);
58 void WorkerScriptLoaded(int worker_route_id,
59 SharedWorkerMessageFilter* filter);
60 void WorkerScriptLoadFailed(int worker_route_id,
61 SharedWorkerMessageFilter* filter);
62 void WorkerConnected(int message_port_id,
64 SharedWorkerMessageFilter* filter);
65 void AllowDatabase(int worker_route_id,
67 const base::string16& name,
68 const base::string16& display_name,
69 unsigned long estimated_size,
71 SharedWorkerMessageFilter* filter);
72 void AllowFileSystem(int worker_route_id,
75 SharedWorkerMessageFilter* filter);
76 void AllowIndexedDB(int worker_route_id,
78 const base::string16& name,
80 SharedWorkerMessageFilter* filter);
82 void OnSharedWorkerMessageFilterClosing(
83 SharedWorkerMessageFilter* filter);
86 friend struct DefaultSingletonTraits<SharedWorkerServiceImpl>;
88 SharedWorkerServiceImpl();
89 virtual ~SharedWorkerServiceImpl();
91 ObserverList<WorkerServiceObserver> observers_;
93 DISALLOW_COPY_AND_ASSIGN(SharedWorkerServiceImpl);
96 } // namespace content
98 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_