Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: content/browser/background_fetch/background_fetch_service_impl.cc

Issue 2762573003: Implement BackgroundFetchManager.fetch() and struct traits (Closed)
Patch Set: Add a missing file Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/service_worker/service_worker_types.h"
harkness 2017/03/21 11:30:00 #include background_fetch_types instead?
Peter Beverloo 2017/03/21 13:46:27 Done.
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,
58 std::move(registration));
dcheng 2017/03/21 07:03:20 FWIW, I believe that BackgroundFetchRegistration i
Peter Beverloo 2017/03/21 13:46:27 Uch, sloppy. Sorry, done. I had been going back an
59 }
60
39 void BackgroundFetchServiceImpl::UpdateUI( 61 void BackgroundFetchServiceImpl::UpdateUI(
40 int64_t service_worker_registration_id, 62 int64_t service_worker_registration_id,
41 const std::string& tag, 63 const std::string& tag,
42 const std::string& title, 64 const std::string& title,
43 const UpdateUICallback& callback) { 65 const UpdateUICallback& callback) {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); 66 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 67
46 // TODO(peter): Get the BackgroundFetchJobController for the 68 // TODO(peter): Get the BackgroundFetchJobController for the
47 // {service_worker_registration_id, tag} pair and call UpdateUI() on it. 69 // {service_worker_registration_id, tag} pair and call UpdateUI() on it.
48 70
(...skipping 11 matching lines...) Expand all
60 void BackgroundFetchServiceImpl::GetRegistration( 82 void BackgroundFetchServiceImpl::GetRegistration(
61 int64_t service_worker_registration_id, 83 int64_t service_worker_registration_id,
62 const std::string& tag, 84 const std::string& tag,
63 const GetRegistrationCallback& callback) { 85 const GetRegistrationCallback& callback) {
64 DCHECK_CURRENTLY_ON(BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
65 87
66 // TODO(peter): Get the registration for {service_worker_registration_id, tag} 88 // TODO(peter): Get the registration for {service_worker_registration_id, tag}
67 // and construct a BackgroundFetchRegistrationPtr for it. 89 // and construct a BackgroundFetchRegistrationPtr for it.
68 90
69 callback.Run(blink::mojom::BackgroundFetchError::NONE, 91 callback.Run(blink::mojom::BackgroundFetchError::NONE,
70 nullptr /* registration */); 92 base::nullopt /* registration */);
71 } 93 }
72 94
73 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id, 95 void BackgroundFetchServiceImpl::GetTags(int64_t service_worker_registration_id,
74 const GetTagsCallback& callback) { 96 const GetTagsCallback& callback) {
75 DCHECK_CURRENTLY_ON(BrowserThread::IO); 97 DCHECK_CURRENTLY_ON(BrowserThread::IO);
76 98
77 // TODO(peter): Get the list of active Background Fetches associated with 99 // TODO(peter): Get the list of active Background Fetches associated with
78 // service_worker_registration_id and share their tags. 100 // service_worker_registration_id and share their tags.
79 101
80 callback.Run(blink::mojom::BackgroundFetchError::NONE, 102 callback.Run(blink::mojom::BackgroundFetchError::NONE,
81 std::vector<std::string>()); 103 std::vector<std::string>());
82 } 104 }
83 105
84 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698