Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / shared_worker / shared_worker_service_impl.h
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.
4
5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
7
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"
14
15 struct ViewHostMsg_CreateWorker_Params;
16
17 namespace IPC {
18 class Message;
19 }
20
21 namespace content {
22
23 class SharedWorkerMessageFilter;
24 class ResourceContext;
25 class WorkerServiceObserver;
26 class WorkerStoragePartition;
27
28 // If "enable-embedded-shared-worker" is set this class will be used instead of
29 // WorkerServiceImpl.
30 // TODO(horo): implement this class.
31 class CONTENT_EXPORT SharedWorkerServiceImpl
32     : public NON_EXPORTED_BASE(WorkerService) {
33  public:
34   // Returns the SharedWorkerServiceImpl singleton.
35   static SharedWorkerServiceImpl* GetInstance();
36
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;
42
43   // These methods correspond to worker related IPCs.
44   void CreateWorker(const ViewHostMsg_CreateWorker_Params& params,
45                     int route_id,
46                     SharedWorkerMessageFilter* filter,
47                     ResourceContext* resource_context,
48                     const WorkerStoragePartition& worker_partition,
49                     bool* url_mismatch);
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,
63                        int worker_route_id,
64                        SharedWorkerMessageFilter* filter);
65   void AllowDatabase(int worker_route_id,
66                      const GURL& url,
67                      const base::string16& name,
68                      const base::string16& display_name,
69                      unsigned long estimated_size,
70                      bool* result,
71                      SharedWorkerMessageFilter* filter);
72   void AllowFileSystem(int worker_route_id,
73                        const GURL& url,
74                        bool* result,
75                        SharedWorkerMessageFilter* filter);
76   void AllowIndexedDB(int worker_route_id,
77                       const GURL& url,
78                       const base::string16& name,
79                       bool* result,
80                       SharedWorkerMessageFilter* filter);
81
82   void OnSharedWorkerMessageFilterClosing(
83       SharedWorkerMessageFilter* filter);
84
85  private:
86   friend struct DefaultSingletonTraits<SharedWorkerServiceImpl>;
87
88   SharedWorkerServiceImpl();
89   virtual ~SharedWorkerServiceImpl();
90
91   ObserverList<WorkerServiceObserver> observers_;
92
93   DISALLOW_COPY_AND_ASSIGN(SharedWorkerServiceImpl);
94 };
95
96 }  // namespace content
97
98 #endif  // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_