Add git cl format presubmit warning for extension and apps.
[chromium-blink-merge.git] / content / renderer / service_worker / embedded_worker_context_client.h
blob65c0ea454c0978cdc9064938c8c608f45b1daacb
1 // Copyright 2013 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_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string16.h"
11 #include "ipc/ipc_listener.h"
12 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h"
13 #include "url/gurl.h"
15 namespace base {
16 class MessageLoopProxy;
17 class TaskRunner;
20 namespace content {
22 class ServiceWorkerScriptContext;
23 class ThreadSafeSender;
25 // This class provides access to/from an embedded worker's WorkerGlobalScope.
26 // All methods other than the constructor (it's created on the main thread)
27 // are called on the worker thread.
29 // TODO(kinuko): Currently EW/SW separation is made a little hazily.
30 // This should implement WebEmbeddedWorkerContextClient
31 // or sort of it (which doesn't exist yet) rather than
32 // WebServiceWorkerContextClient if we want to separate them more cleanly,
33 // or ServiceWorkerScriptContext should be merged into this class
34 // if we consider EW == SW script context.
35 class EmbeddedWorkerContextClient
36 : public blink::WebServiceWorkerContextClient {
37 public:
38 // Returns a thread-specific client instance. This does NOT create a
39 // new instance.
40 static EmbeddedWorkerContextClient* ThreadSpecificInstance();
42 EmbeddedWorkerContextClient(int embedded_worker_id,
43 int64 service_worker_version_id,
44 const GURL& script_url);
46 virtual ~EmbeddedWorkerContextClient();
48 bool OnMessageReceived(const IPC::Message& msg);
50 void SendMessageToBrowser(int request_id, const IPC::Message& message);
52 // WebServiceWorkerContextClient overrides.
53 virtual void workerContextFailedToStart();
54 virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
55 virtual void workerContextDestroyed();
57 // TODO: Implement DevTools related method overrides.
59 int embedded_worker_id() const { return embedded_worker_id_; }
61 private:
62 void OnSendMessageToWorker(int thread_id,
63 int embedded_worker_id,
64 int request_id,
65 const IPC::Message& message);
66 void SendWorkerStarted();
68 const int embedded_worker_id_;
69 const int64 service_worker_version_id_;
70 const GURL script_url_;
71 scoped_refptr<ThreadSafeSender> sender_;
72 scoped_refptr<base::MessageLoopProxy> main_thread_proxy_;
73 scoped_refptr<base::TaskRunner> worker_task_runner_;
75 scoped_ptr<ServiceWorkerScriptContext> script_context_;
77 base::WeakPtrFactory<EmbeddedWorkerContextClient> weak_factory_;
79 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerContextClient);
82 } // namespace content
84 #endif // CONTENT_CHILD_SERVICE_WORKER_EMBEDDED_WORKER_CLIENT_H_