OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/service_worker/service_worker_provider_interfaces.mojom
.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 class ServiceWorkerContextCore; | 21 class ServiceWorkerContextCore; |
21 class ServiceWorkerDispatcherHost; | 22 class ServiceWorkerDispatcherHost; |
22 class ServiceWorkerProviderHost; | 23 class ServiceWorkerProviderHost; |
| 24 struct ServiceWorkerProviderHostInfo; |
23 | 25 |
24 template <typename Arg> | 26 template <typename Arg> |
25 void ReceiveResult(BrowserThread::ID run_quit_thread, | 27 void ReceiveResult(BrowserThread::ID run_quit_thread, |
26 const base::Closure& quit, | 28 const base::Closure& quit, |
27 Arg* out, Arg actual) { | 29 Arg* out, Arg actual) { |
28 *out = actual; | 30 *out = actual; |
29 if (!quit.is_null()) | 31 if (!quit.is_null()) |
30 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); | 32 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); |
31 } | 33 } |
32 | 34 |
33 template <typename Arg> base::Callback<void(Arg)> | 35 template <typename Arg> base::Callback<void(Arg)> |
34 CreateReceiver(BrowserThread::ID run_quit_thread, | 36 CreateReceiver(BrowserThread::ID run_quit_thread, |
35 const base::Closure& quit, Arg* out) { | 37 const base::Closure& quit, Arg* out) { |
36 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out); | 38 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out); |
37 } | 39 } |
38 | 40 |
39 template <typename Arg> | 41 template <typename Arg> |
40 base::Callback<void(Arg)> CreateReceiverOnCurrentThread( | 42 base::Callback<void(Arg)> CreateReceiverOnCurrentThread( |
41 Arg* out, | 43 Arg* out, |
42 const base::Closure& quit = base::Closure()) { | 44 const base::Closure& quit = base::Closure()) { |
43 BrowserThread::ID id; | 45 BrowserThread::ID id; |
44 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id); | 46 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id); |
45 DCHECK(ret); | 47 DCHECK(ret); |
46 return base::Bind(&ReceiveResult<Arg>, id, quit, out); | 48 return base::Bind(&ReceiveResult<Arg>, id, quit, out); |
47 } | 49 } |
48 | 50 |
| 51 // Container for keeping the Mojo connection to the service worker provider on |
| 52 // the renderer alive. |
| 53 class ServiceWorkerRemoteProviderEndpoint { |
| 54 public: |
| 55 ServiceWorkerRemoteProviderEndpoint(); |
| 56 ServiceWorkerRemoteProviderEndpoint( |
| 57 ServiceWorkerRemoteProviderEndpoint&& other); |
| 58 ~ServiceWorkerRemoteProviderEndpoint(); |
| 59 |
| 60 void BindWithProviderHostInfo(ServiceWorkerProviderHostInfo* info); |
| 61 |
| 62 mojom::ServiceWorkerProviderHostAssociatedPtr* host_ptr() { |
| 63 return &host_ptr_; |
| 64 } |
| 65 |
| 66 mojom::ServiceWorkerProviderAssociatedRequest* client_request() { |
| 67 return &client_request_; |
| 68 } |
| 69 |
| 70 private: |
| 71 // Bound with content::ServiceWorkerProviderHost. The provider host will be |
| 72 // removed asynchronously when this pointer is closed. |
| 73 mojom::ServiceWorkerProviderHostAssociatedPtr host_ptr_; |
| 74 // This is the other end of ServiceWorkerProviderAssociatedPtr owned by |
| 75 // content::ServiceWorkerProviderHost. |
| 76 mojom::ServiceWorkerProviderAssociatedRequest client_request_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRemoteProviderEndpoint); |
| 79 }; |
| 80 |
49 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostForWindow( | 81 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostForWindow( |
50 int process_id, | 82 int process_id, |
51 int provider_id, | 83 int provider_id, |
52 bool is_parent_frame_secure, | 84 bool is_parent_frame_secure, |
53 base::WeakPtr<ServiceWorkerContextCore> context); | 85 base::WeakPtr<ServiceWorkerContextCore> context, |
| 86 ServiceWorkerRemoteProviderEndpoint* output_endpoint); |
54 | 87 |
55 std::unique_ptr<ServiceWorkerProviderHost> | 88 std::unique_ptr<ServiceWorkerProviderHost> |
56 CreateProviderHostForServiceWorkerContext( | 89 CreateProviderHostForServiceWorkerContext( |
57 int process_id, | 90 int process_id, |
58 int provider_id, | 91 int provider_id, |
59 bool is_parent_frame_secure, | 92 bool is_parent_frame_secure, |
60 base::WeakPtr<ServiceWorkerContextCore> context); | 93 base::WeakPtr<ServiceWorkerContextCore> context, |
| 94 ServiceWorkerRemoteProviderEndpoint* output_endpoint); |
61 | 95 |
62 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostWithDispatcherHost( | 96 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostWithDispatcherHost( |
63 int process_id, | 97 int process_id, |
64 int provider_id, | 98 int provider_id, |
65 base::WeakPtr<ServiceWorkerContextCore> context, | 99 base::WeakPtr<ServiceWorkerContextCore> context, |
66 int route_id, | 100 int route_id, |
67 ServiceWorkerDispatcherHost* dispatcher_host); | 101 ServiceWorkerDispatcherHost* dispatcher_host, |
| 102 ServiceWorkerRemoteProviderEndpoint* output_endpoint); |
68 | 103 |
69 } // namespace content | 104 } // namespace content |
70 | 105 |
71 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 106 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
OLD | NEW |