OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/background_fetch/background_fetch_service_impl.h" | 5 #include "content/browser/background_fetch/background_fetch_service_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/optional.h" | 9 #include "base/optional.h" |
10 #include "content/browser/background_fetch/background_fetch_context.h" | 10 #include "content/browser/background_fetch/background_fetch_context.h" |
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
12 #include "content/common/background_fetch/background_fetch_types.h" | 12 #include "content/common/background_fetch/background_fetch_types.h" |
| 13 #include "content/common/service_worker/service_worker_types.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 // static | 19 // static |
19 void BackgroundFetchServiceImpl::Create( | 20 void BackgroundFetchServiceImpl::Create( |
20 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 21 scoped_refptr<BackgroundFetchContext> background_fetch_context, |
21 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 22 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
22 blink::mojom::BackgroundFetchServiceRequest request) { | 23 blink::mojom::BackgroundFetchServiceRequest request) { |
23 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 24 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
24 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( | 25 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( |
25 std::move(background_fetch_context), | 26 std::move(background_fetch_context), |
26 std::move(service_worker_context)), | 27 std::move(service_worker_context)), |
27 std::move(request)); | 28 std::move(request)); |
28 } | 29 } |
29 | 30 |
30 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( | 31 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( |
31 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 32 scoped_refptr<BackgroundFetchContext> background_fetch_context, |
32 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) | 33 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
33 : background_fetch_context_(std::move(background_fetch_context)), | 34 : background_fetch_context_(std::move(background_fetch_context)), |
34 service_worker_context_(std::move(service_worker_context)) { | 35 service_worker_context_(std::move(service_worker_context)) { |
35 DCHECK(background_fetch_context_); | 36 DCHECK(background_fetch_context_); |
36 DCHECK(service_worker_context_); | 37 DCHECK(service_worker_context_); |
37 } | 38 } |
38 | 39 |
39 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; | 40 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; |
40 | 41 |
41 void BackgroundFetchServiceImpl::Fetch(int64_t service_worker_registration_id, | 42 void BackgroundFetchServiceImpl::Fetch( |
42 const std::string& tag, | 43 int64_t service_worker_registration_id, |
43 const BackgroundFetchOptions& options, | 44 const std::string& tag, |
44 const FetchCallback& callback) { | 45 const std::vector<ServiceWorkerFetchRequest>& requests, |
| 46 const BackgroundFetchOptions& options, |
| 47 const FetchCallback& callback) { |
45 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
46 | 49 |
47 // TODO(peter): Create a new job with the BackgroundFetchContext for the | 50 // TODO(peter): Create a new job with the BackgroundFetchContext for the |
48 // given tag, requests and options. For now we return a registration that's | 51 // given |tag|, |requests| and |options|. For now we return a registration |
49 // based on the given |options|, to make sure round-trip is covered. | 52 // that's based on the given |options|, to make sure round-trip is covered. |
50 | 53 |
51 BackgroundFetchRegistration registration; | 54 BackgroundFetchRegistration registration; |
52 registration.tag = tag; | 55 registration.tag = tag; |
53 registration.icons = options.icons; | 56 registration.icons = options.icons; |
54 registration.title = options.title; | 57 registration.title = options.title; |
55 registration.total_download_size = options.total_download_size; | 58 registration.total_download_size = options.total_download_size; |
56 | 59 |
57 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); | 60 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); |
58 } | 61 } |
59 | 62 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 | 103 |
101 // TODO(peter): Get the list of active Background Fetches associated with | 104 // TODO(peter): Get the list of active Background Fetches associated with |
102 // service_worker_registration_id and share their tags. | 105 // service_worker_registration_id and share their tags. |
103 | 106 |
104 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 107 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
105 std::vector<std::string>()); | 108 std::vector<std::string>()); |
106 } | 109 } |
107 | 110 |
108 } // namespace content | 111 } // namespace content |
OLD | NEW |