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_WEB_SERVICE_WORKER_IMPL_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/strings/string16.h"
13 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
14 #include "third_party/WebKit/public/platform/WebServiceWorker.h"
15 #include "third_party/WebKit/public/web/WebFrame.h"
18 class WebServiceWorkerProxy
;
23 class ServiceWorkerHandleReference
;
24 struct ServiceWorkerObjectInfo
;
25 class ThreadSafeSender
;
27 // Each instance corresponds to one ServiceWorker object in JS context, and
28 // is held by ServiceWorker object in blink's c++ layer, e.g. created one
29 // per navigator.serviceWorker.current or per successful
30 // navigator.serviceWorker.register call.
32 // Each instance holds one ServiceWorkerHandleReference so that
33 // corresponding ServiceWorkerHandle doesn't go away in the browser process
34 // while the ServiceWorker object is alive.
35 class WebServiceWorkerImpl
36 : NON_EXPORTED_BASE(public blink::WebServiceWorker
) {
38 WebServiceWorkerImpl(scoped_ptr
<ServiceWorkerHandleReference
> handle_ref
,
39 ThreadSafeSender
* thread_safe_sender
);
40 virtual ~WebServiceWorkerImpl();
42 // Notifies that the service worker's state changed. This function may queue
43 // the state change for later processing, if the proxy is not yet ready to
44 // handle state changes.
45 void OnStateChanged(blink::WebServiceWorkerState new_state
);
47 virtual void setProxy(blink::WebServiceWorkerProxy
* proxy
);
48 virtual blink::WebServiceWorkerProxy
* proxy();
49 virtual void proxyReadyChanged();
50 virtual blink::WebURL
scope() const;
51 virtual blink::WebURL
url() const;
52 virtual blink::WebServiceWorkerState
state() const;
53 virtual void postMessage(const blink::WebString
& message
,
54 blink::WebMessagePortChannelArray
* channels
);
55 virtual void terminate();
58 // Commits the new state internally and notifies the proxy of the change.
59 void CommitState(blink::WebServiceWorkerState new_state
);
61 scoped_ptr
<ServiceWorkerHandleReference
> handle_ref_
;
62 blink::WebServiceWorkerState state_
;
63 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
64 blink::WebServiceWorkerProxy
* proxy_
;
65 std::vector
<blink::WebServiceWorkerState
> queued_states_
;
67 DISALLOW_COPY_AND_ASSIGN(WebServiceWorkerImpl
);
70 } // namespace content
72 #endif // CONTENT_CHILD_SERVICE_WORKER_WEB_SERVICE_WORKER_IMPL_H_