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

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

Issue 2777183002: Hook up the other Background Fetch Mojo methods with the system (Closed)
Patch Set: Hook up the other Background Fetch Mojo methods with the system Created 3 years, 8 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_context.h" 5 #include "content/browser/background_fetch/background_fetch_context.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/background_fetch/background_fetch_data_manager.h" 8 #include "content/browser/background_fetch/background_fetch_data_manager.h"
9 #include "content/browser/background_fetch/background_fetch_job_controller.h" 9 #include "content/browser/background_fetch/background_fetch_job_controller.h"
10 #include "content/browser/background_fetch/background_fetch_registration_id.h" 10 #include "content/browser/background_fetch/background_fetch_registration_id.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/browser/storage_partition_impl.h" 12 #include "content/browser/storage_partition_impl.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "url/origin.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 BackgroundFetchContext::BackgroundFetchContext( 18 BackgroundFetchContext::BackgroundFetchContext(
18 BrowserContext* browser_context, 19 BrowserContext* browser_context,
19 StoragePartitionImpl* storage_partition, 20 StoragePartitionImpl* storage_partition,
20 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 21 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
21 : browser_context_(browser_context), 22 : browser_context_(browser_context),
22 storage_partition_(storage_partition), 23 storage_partition_(storage_partition),
23 service_worker_context_(service_worker_context), 24 service_worker_context_(service_worker_context),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // which enables it to resolve the promise telling the developer it worked. 72 // which enables it to resolve the promise telling the developer it worked.
72 BackgroundFetchRegistration registration; 73 BackgroundFetchRegistration registration;
73 registration.tag = registration_id.tag(); 74 registration.tag = registration_id.tag();
74 registration.icons = options.icons; 75 registration.icons = options.icons;
75 registration.title = options.title; 76 registration.title = options.title;
76 registration.total_download_size = options.total_download_size; 77 registration.total_download_size = options.total_download_size;
77 78
78 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); 79 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration);
79 } 80 }
80 81
82 std::vector<std::string>
83 BackgroundFetchContext::GetActiveTagsForServiceWorkerRegistration(
84 int64_t service_worker_registration_id,
85 const url::Origin& origin) const {
86 std::vector<std::string> tags;
87 for (const auto& pair : active_fetches_) {
88 const BackgroundFetchRegistrationId& registration_id =
89 pair.second->registration_id();
90
91 // Only return the tags when the origin and SW registration id match.
92 if (registration_id.origin() == origin &&
93 registration_id.service_worker_registration_id() ==
94 service_worker_registration_id) {
95 tags.push_back(pair.second->registration_id().tag());
96 }
97 }
98
99 return tags;
100 }
101
102 BackgroundFetchJobController* BackgroundFetchContext::GetActiveFetch(
103 const BackgroundFetchRegistrationId& registration_id) const {
104 DCHECK_CURRENTLY_ON(BrowserThread::IO);
105
106 auto iter = active_fetches_.find(registration_id);
107 if (iter == active_fetches_.end())
108 return nullptr;
109
110 return iter->second.get();
111 }
112
81 void BackgroundFetchContext::CreateController( 113 void BackgroundFetchContext::CreateController(
82 const BackgroundFetchRegistrationId& registration_id, 114 const BackgroundFetchRegistrationId& registration_id,
83 const BackgroundFetchOptions& options) { 115 const BackgroundFetchOptions& options) {
84 std::unique_ptr<BackgroundFetchJobController> controller = 116 std::unique_ptr<BackgroundFetchJobController> controller =
85 base::MakeUnique<BackgroundFetchJobController>( 117 base::MakeUnique<BackgroundFetchJobController>(
86 registration_id, browser_context_, storage_partition_, 118 registration_id, options, browser_context_, storage_partition_,
87 background_fetch_data_manager_.get(), 119 background_fetch_data_manager_.get(),
88 base::BindOnce(&BackgroundFetchContext::DidFinishFetch, this)); 120 base::BindOnce(&BackgroundFetchContext::DidFinishFetch, this));
89 121
90 active_fetches_.insert( 122 active_fetches_.insert(
91 std::make_pair(registration_id, std::move(controller))); 123 std::make_pair(registration_id, std::move(controller)));
92 } 124 }
93 125
94 void BackgroundFetchContext::DidFinishFetch( 126 void BackgroundFetchContext::DidFinishFetch(
95 const BackgroundFetchRegistrationId& registration_id) { 127 const BackgroundFetchRegistrationId& registration_id,
128 bool aborted_by_developer) {
96 DCHECK_GT(active_fetches_.count(registration_id), 0u); 129 DCHECK_GT(active_fetches_.count(registration_id), 0u);
97 130
98 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` 131 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail`
99 // event to the Service Worker. 132 // event to the Service Worker when |aborted_by_developer| is not set.
100 133
101 active_fetches_.erase(registration_id); 134 active_fetches_.erase(registration_id);
102 } 135 }
103 136
104 } // namespace content 137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698