Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: Source/modules/navigatorconnect/ServicePortCollection.h

Issue 1191393003: Update client side navigator.connect API to use ServicePortCollection [1/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@serviceport
Patch Set: address more comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ServicePortCollection_h 5 #ifndef ServicePortCollection_h
6 #define ServicePortCollection_h 6 #define ServicePortCollection_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "core/dom/ContextLifecycleObserver.h" 9 #include "core/dom/ContextLifecycleObserver.h"
10 #include "core/events/EventTarget.h" 10 #include "core/events/EventTarget.h"
11 #include "modules/ModulesExport.h" 11 #include "modules/ModulesExport.h"
12 #include "public/platform/modules/navigator_services/WebServicePortProvider.h"
13 #include "public/platform/modules/navigator_services/WebServicePortProviderClien t.h"
12 #include "wtf/RefCounted.h" 14 #include "wtf/RefCounted.h"
13 15
14 namespace blink { 16 namespace blink {
15 17
18 class ServicePort;
16 class ServicePortConnectOptions; 19 class ServicePortConnectOptions;
17 class ServicePortMatchOptions; 20 class ServicePortMatchOptions;
18 21
19 class MODULES_EXPORT ServicePortCollection final 22 class MODULES_EXPORT ServicePortCollection final
20 : public EventTargetWithInlineData 23 : public RefCountedGarbageCollectedEventTargetWithInlineData<ServicePortColl ection>
21 , public RefCountedWillBeNoBase<ServicePortCollection> 24 , public ContextLifecycleObserver
22 , public ContextLifecycleObserver { 25 , public WebServicePortProviderClient {
23 DEFINE_WRAPPERTYPEINFO(); 26 DEFINE_WRAPPERTYPEINFO();
24 REFCOUNTED_EVENT_TARGET(ServicePortCollection); 27 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(ServicePortCollection);
25 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ServicePortCollection);
26 WTF_MAKE_NONCOPYABLE(ServicePortCollection); 28 WTF_MAKE_NONCOPYABLE(ServicePortCollection);
27 public: 29 public:
28 static PassRefPtrWillBeRawPtr<ServicePortCollection> create(ExecutionContext *); 30 static ServicePortCollection* create(ExecutionContext*);
29 ~ServicePortCollection() override; 31 ~ServicePortCollection() override;
30 32
33 // Adds a port to this collection to keep track of it and allow delivering
34 // events related to it.
35 void addPort(ServicePort*);
36
37 // Called when a port is closed to signal the WebServicePortProvider as well
38 // as remove the port from this collection.
39 void closePort(ServicePort*);
40
41 WebServicePortProvider* provider() { return m_provider.get(); }
42
31 // ServicePortCollection.idl 43 // ServicePortCollection.idl
32 ScriptPromise connect(ScriptState*, const String& url, const ServicePortConn ectOptions&); 44 ScriptPromise connect(ScriptState*, const String& url, const ServicePortConn ectOptions&, ExceptionState&);
33 ScriptPromise match(ScriptState*, const ServicePortMatchOptions&); 45 ScriptPromise match(ScriptState*, const ServicePortMatchOptions&);
34 ScriptPromise matchAll(ScriptState*, const ServicePortMatchOptions&); 46 ScriptPromise matchAll(ScriptState*, const ServicePortMatchOptions&);
35 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); 47 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
36 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); 48 DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
37 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
38 50
39 // EventTarget overrides. 51 // EventTarget overrides.
40 const AtomicString& interfaceName() const override; 52 const AtomicString& interfaceName() const override;
41 ExecutionContext* executionContext() const override; 53 ExecutionContext* executionContext() const override;
42 54
55 // WebServicePortProviderClient overrides.
56 void postMessage(WebServicePortID, const WebString&, const WebMessagePortCha nnelArray&) override;
57
43 DECLARE_VIRTUAL_TRACE(); 58 DECLARE_VIRTUAL_TRACE();
44 59
45 private: 60 private:
46 explicit ServicePortCollection(ExecutionContext*); 61 explicit ServicePortCollection(ExecutionContext*);
62
63 OwnPtr<WebServicePortProvider> m_provider;
64 HeapVector<Member<ServicePort>> m_ports;
47 }; 65 };
48 66
49 } // namespace blink 67 } // namespace blink
50 68
51 #endif // ServicePortCollection_h 69 #endif // ServicePortCollection_h
OLDNEW
« no previous file with comments | « Source/modules/navigatorconnect/ServicePort.idl ('k') | Source/modules/navigatorconnect/ServicePortCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698