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/background_fetch/background_fetch_registration_id.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 #include "url/origin.h" | 16 #include "url/origin.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // static | 20 // static |
20 void BackgroundFetchServiceImpl::Create( | 21 void BackgroundFetchServiceImpl::Create( |
21 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 22 scoped_refptr<BackgroundFetchContext> background_fetch_context, |
22 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | |
23 blink::mojom::BackgroundFetchServiceRequest request) { | 23 blink::mojom::BackgroundFetchServiceRequest request) { |
24 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 24 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
25 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( | 25 mojo::MakeStrongBinding(base::MakeUnique<BackgroundFetchServiceImpl>( |
26 std::move(background_fetch_context), | 26 std::move(background_fetch_context)), |
27 std::move(service_worker_context)), | |
28 std::move(request)); | 27 std::move(request)); |
29 } | 28 } |
30 | 29 |
31 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( | 30 BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( |
32 scoped_refptr<BackgroundFetchContext> background_fetch_context, | 31 scoped_refptr<BackgroundFetchContext> background_fetch_context) |
33 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) | 32 : background_fetch_context_(std::move(background_fetch_context)) { |
34 : background_fetch_context_(std::move(background_fetch_context)), | |
35 service_worker_context_(std::move(service_worker_context)) { | |
36 DCHECK(background_fetch_context_); | 33 DCHECK(background_fetch_context_); |
37 DCHECK(service_worker_context_); | |
38 } | 34 } |
39 | 35 |
40 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; | 36 BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() = default; |
41 | 37 |
42 void BackgroundFetchServiceImpl::Fetch(int64_t service_worker_registration_id, | 38 void BackgroundFetchServiceImpl::Fetch(int64_t service_worker_registration_id, |
43 const url::Origin& origin, | 39 const url::Origin& origin, |
44 const std::string& tag, | 40 const std::string& tag, |
45 const BackgroundFetchOptions& options, | 41 const BackgroundFetchOptions& options, |
46 const FetchCallback& callback) { | 42 const FetchCallback& callback) { |
47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 44 BackgroundFetchRegistrationId registration_id(service_worker_registration_id, |
| 45 origin, tag); |
48 | 46 |
49 // TODO(peter): Create a new job with the BackgroundFetchContext for the | 47 // TODO(peter): Make sure |tag| isn't empty. |
50 // given tag, requests and options. For now we return a registration that's | 48 // TODO(peter): Make sure there are >0 |requests|. |
51 // based on the given |options|, to make sure round-trip is covered. | |
52 | 49 |
53 BackgroundFetchRegistration registration; | 50 std::vector<ServiceWorkerFetchRequest> requests; |
54 registration.tag = tag; | 51 requests.emplace_back(GURL("https://example.com/image.png"), "POST", |
55 registration.icons = options.icons; | 52 ServiceWorkerHeaderMap(), Referrer(), |
56 registration.title = options.title; | 53 false /* is_reload */); |
57 registration.total_download_size = options.total_download_size; | |
58 | 54 |
59 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); | 55 background_fetch_context_->StartFetch(registration_id, requests, options, |
| 56 callback); |
60 } | 57 } |
61 | 58 |
62 void BackgroundFetchServiceImpl::UpdateUI( | 59 void BackgroundFetchServiceImpl::UpdateUI( |
63 int64_t service_worker_registration_id, | 60 int64_t service_worker_registration_id, |
64 const url::Origin& origin, | 61 const url::Origin& origin, |
65 const std::string& tag, | 62 const std::string& tag, |
66 const std::string& title, | 63 const std::string& title, |
67 const UpdateUICallback& callback) { | 64 const UpdateUICallback& callback) { |
68 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 65 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
69 | 66 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
106 | 103 |
107 // TODO(peter): Get the list of active Background Fetches associated with | 104 // TODO(peter): Get the list of active Background Fetches associated with |
108 // service_worker_registration_id and share their tags. | 105 // service_worker_registration_id and share their tags. |
109 | 106 |
110 callback.Run(blink::mojom::BackgroundFetchError::NONE, | 107 callback.Run(blink::mojom::BackgroundFetchError::NONE, |
111 std::vector<std::string>()); | 108 std::vector<std::string>()); |
112 } | 109 } |
113 | 110 |
114 } // namespace content | 111 } // namespace content |
OLD | NEW |