| 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/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "url/origin.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(int64_t service_worker_registration_id, |
| 43 const url::Origin& origin, |
| 42 const std::string& tag, | 44 const std::string& tag, |
| 43 const BackgroundFetchOptions& options, | 45 const BackgroundFetchOptions& options, |
| 44 const FetchCallback& callback) { | 46 const FetchCallback& callback) { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 47 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 46 | 48 |
| 47 // TODO(peter): Create a new job with the BackgroundFetchContext for the | 49 // 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 | 50 // 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. | 51 // based on the given |options|, to make sure round-trip is covered. |
| 50 | 52 |
| 51 BackgroundFetchRegistration registration; | 53 BackgroundFetchRegistration registration; |
| 52 registration.tag = tag; | 54 registration.tag = tag; |
| 53 registration.icons = options.icons; | 55 registration.icons = options.icons; |
| 54 registration.title = options.title; | 56 registration.title = options.title; |
| 55 registration.total_download_size = options.total_download_size; | 57 registration.total_download_size = options.total_download_size; |
| 56 | 58 |
| 57 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); | 59 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void BackgroundFetchServiceImpl::UpdateUI( | 62 void BackgroundFetchServiceImpl::UpdateUI( |
| 61 int64_t service_worker_registration_id, | 63 int64_t service_worker_registration_id, |
| 64 const url::Origin& origin, |
| 62 const std::string& tag, | 65 const std::string& tag, |
| 63 const std::string& title, | 66 const std::string& title, |
| 64 const UpdateUICallback& callback) { | 67 const UpdateUICallback& callback) { |
| 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 68 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 66 | 69 |
| 67 // TODO(peter): Get the BackgroundFetchJobController for the | 70 // TODO(peter): Get the BackgroundFetchJobController for the |
| 68 // {service_worker_registration_id, tag} pair and call UpdateUI() on it. | 71 // {service_worker_registration_id, tag} pair and call UpdateUI() on it. |
| 69 | 72 |
| 70 callback.Run(blink::mojom::BackgroundFetchError::NONE); | 73 callback.Run(blink::mojom::BackgroundFetchError::NONE); |
| 71 } | 74 } |
| 72 | 75 |
| 73 void BackgroundFetchServiceImpl::Abort(int64_t service_worker_registration_id, | 76 void BackgroundFetchServiceImpl::Abort(int64_t service_worker_registration_id, |
| 77 const url::Origin& origin, |
| 74 const std::string& tag, | 78 const std::string& tag, |
| 75 const AbortCallback& callback) { | 79 const AbortCallback& callback) { |
| 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 | 81 |
| 78 // TODO(peter): Get the BackgroundFetchJobController for the | 82 // TODO(peter): Get the BackgroundFetchJobController for the |
| 79 // {service_worker_registration_id, tag} pair and call Abort() on it. | 83 // {service_worker_registration_id, tag} pair and call Abort() on it. |
| 80 | 84 |
| 81 callback.Run(blink::mojom::BackgroundFetchError::NONE); | 85 callback.Run(blink::mojom::BackgroundFetchError::NONE); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void BackgroundFetchServiceImpl::GetRegistration( | 88 void BackgroundFetchServiceImpl::GetRegistration( |
| 85 int64_t service_worker_registration_id, | 89 int64_t service_worker_registration_id, |
| 90 const url::Origin& origin, |
| 86 const std::string& tag, | 91 const std::string& tag, |
| 87 const GetRegistrationCallback& callback) { | 92 const GetRegistrationCallback& callback) { |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 89 | 94 |
| 90 // TODO(peter): Get the registration for {service_worker_registration_id, tag} | 95 // TODO(peter): Get the registration for {service_worker_registration_id, tag} |
| 91 // and construct a BackgroundFetchRegistrationPtr for it. | 96 // and construct a BackgroundFetchRegistrationPtr for it. |
| 92 | 97 |
| 93 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 98 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
| 94 base::nullopt /* registration */); | 99 base::nullopt /* registration */); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id, | 102 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id, |
| 103 const url::Origin& origin, |
| 98 const GetTagsCallback& callback) { | 104 const GetTagsCallback& callback) { |
| 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 100 | 106 |
| 101 // TODO(peter): Get the list of active Background Fetches associated with | 107 // TODO(peter): Get the list of active Background Fetches associated with |
| 102 // service_worker_registration_id and share their tags. | 108 // service_worker_registration_id and share their tags. |
| 103 | 109 |
| 104 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 110 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
| 105 std::vector<std::string>()); | 111 std::vector<std::string>()); |
| 106 } | 112 } |
| 107 | 113 |
| 108 } // namespace content | 114 } // namespace content |
| OLD | NEW |