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 "content/browser/background_fetch/background_fetch_context.h" | 10 #include "content/browser/background_fetch/background_fetch_context.h" |
10 #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" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 // static | 18 // static |
17 void BackgroundFetchServiceImpl::Create( | 19 void BackgroundFetchServiceImpl::Create( |
18 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 20 scoped_refptr<BackgroundFetchContext> background_fetch_context, |
19 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 21 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
20 blink::mojom::BackgroundFetchServiceRequest request) { | 22 blink::mojom::BackgroundFetchServiceRequest request) { |
21 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
22 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( | 24 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( |
23 std::move(background_fetch_context), | 25 std::move(background_fetch_context), |
24 std::move(service_worker_context)), | 26 std::move(service_worker_context)), |
25 std::move(request)); | 27 std::move(request)); |
26 } | 28 } |
27 | 29 |
28 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( | 30 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( |
29 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 31 scoped_refptr<BackgroundFetchContext> background_fetch_context, |
30 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) | 32 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
31 : background_fetch_context_(std::move(background_fetch_context)), | 33 : background_fetch_context_(std::move(background_fetch_context)), |
32 service_worker_context_(std::move(service_worker_context)) { | 34 service_worker_context_(std::move(service_worker_context)) { |
33 DCHECK(background_fetch_context_); | 35 DCHECK(background_fetch_context_); |
34 DCHECK(service_worker_context_); | 36 DCHECK(service_worker_context_); |
35 } | 37 } |
36 | 38 |
37 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; | 39 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; |
38 | 40 |
| 41 void BackgroundFetchServiceImpl::Fetch(int64_t service_worker_registration_id, |
| 42 const std::string& tag, |
| 43 const BackgroundFetchOptions& options, |
| 44 const FetchCallback& callback) { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 46 |
| 47 // 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 |
| 49 // based on the given |options|, to make sure round-trip is covered. |
| 50 |
| 51 BackgroundFetchRegistration registration; |
| 52 registration.tag = tag; |
| 53 registration.icons = options.icons; |
| 54 registration.title = options.title; |
| 55 registration.total_download_size = options.total_download_size; |
| 56 |
| 57 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); |
| 58 } |
| 59 |
39 void BackgroundFetchServiceImpl::UpdateUI( | 60 void BackgroundFetchServiceImpl::UpdateUI( |
40 int64_t service_worker_registration_id, | 61 int64_t service_worker_registration_id, |
41 const std::string& tag, | 62 const std::string& tag, |
42 const std::string& title, | 63 const std::string& title, |
43 const UpdateUICallback& callback) { | 64 const UpdateUICallback& callback) { |
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
45 | 66 |
46 // TODO(peter): Get the BackgroundFetchJobController for the | 67 // TODO(peter): Get the BackgroundFetchJobController for the |
47 // {service_worker_registration_id, tag} pair and call UpdateUI() on it. | 68 // {service_worker_registration_id, tag} pair and call UpdateUI() on it. |
48 | 69 |
(...skipping 14 matching lines...) Expand all Loading... |
63 void BackgroundFetchServiceImpl::GetRegistration( | 84 void BackgroundFetchServiceImpl::GetRegistration( |
64 int64_t service_worker_registration_id, | 85 int64_t service_worker_registration_id, |
65 const std::string& tag, | 86 const std::string& tag, |
66 const GetRegistrationCallback& callback) { | 87 const GetRegistrationCallback& callback) { |
67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
68 | 89 |
69 // TODO(peter): Get the registration for {service_worker_registration_id, tag} | 90 // TODO(peter): Get the registration for {service_worker_registration_id, tag} |
70 // and construct a BackgroundFetchRegistrationPtr for it. | 91 // and construct a BackgroundFetchRegistrationPtr for it. |
71 | 92 |
72 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 93 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
73 nullptr /* registration */); | 94 base::nullopt /* registration */); |
74 } | 95 } |
75 | 96 |
76 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id, | 97 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id, |
77 const GetTagsCallback& callback) { | 98 const GetTagsCallback& callback) { |
78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
79 | 100 |
80 // TODO(peter): Get the list of active Background Fetches associated with | 101 // TODO(peter): Get the list of active Background Fetches associated with |
81 // service_worker_registration_id and share their tags. | 102 // service_worker_registration_id and share their tags. |
82 | 103 |
83 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 104 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
84 std::vector<std::string>()); | 105 std::vector<std::string>()); |
85 } | 106 } |
86 | 107 |
87 } // namespace content | 108 } // namespace content |
OLD | NEW |