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

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

Issue 2833793002: Added AddDownload communication path and observers
Patch Set: 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_client_proxy.h" 8 #include "content/browser/background_fetch/background_fetch_client_proxy.h"
9 #include "content/browser/background_fetch/background_fetch_data_manager.h" 9 #include "content/browser/background_fetch/background_fetch_data_manager.h"
10 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" 10 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h"
(...skipping 27 matching lines...) Expand all
38 38
39 BackgroundFetchContext::BackgroundFetchContext( 39 BackgroundFetchContext::BackgroundFetchContext(
40 BrowserContext* browser_context, 40 BrowserContext* browser_context,
41 StoragePartitionImpl* storage_partition, 41 StoragePartitionImpl* storage_partition,
42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
43 : browser_context_(browser_context), 43 : browser_context_(browser_context),
44 data_manager_( 44 data_manager_(
45 base::MakeUnique<BackgroundFetchDataManager>(browser_context)), 45 base::MakeUnique<BackgroundFetchDataManager>(browser_context)),
46 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>( 46 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>(
47 std::move(service_worker_context))), 47 std::move(service_worker_context))),
48 client_proxy_(base::MakeUnique<BackgroundFetchClientProxy>(this)) { 48 client_proxy_(
49 base::MakeUnique<BackgroundFetchClientProxy>(browser_context, this)) {
49 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
50 BackgroundFetchClient* background_fetch_client = 51 BackgroundFetchClient* background_fetch_client =
51 browser_context_->GetBackgroundFetchClient(); 52 browser_context_->GetBackgroundFetchClient();
52 if (background_fetch_client) 53 if (background_fetch_client)
53 background_fetch_client->SetDelegate(client_proxy_.get()); 54 background_fetch_client->SetDelegate(client_proxy_.get());
54 } 55 }
55 56
56 BackgroundFetchContext::~BackgroundFetchContext() { 57 BackgroundFetchContext::~BackgroundFetchContext() {
57 DCHECK_CURRENTLY_ON(BrowserThread::UI); 58 DCHECK_CURRENTLY_ON(BrowserThread::UI);
58 } 59 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) { 97 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
97 RecordRegistrationCreatedError(error); 98 RecordRegistrationCreatedError(error);
98 if (error != blink::mojom::BackgroundFetchError::NONE) { 99 if (error != blink::mojom::BackgroundFetchError::NONE) {
99 callback.Run(error, base::nullopt /* registration */); 100 callback.Run(error, base::nullopt /* registration */);
100 return; 101 return;
101 } 102 }
102 103
103 // Create the BackgroundFetchJobController, which will do the actual fetching. 104 // Create the BackgroundFetchJobController, which will do the actual fetching.
104 CreateController(registration_id, options, std::move(initial_requests)); 105 CreateController(registration_id, options, std::move(initial_requests));
105 106
107 // Tell the BackgroundFetchClient that a job has started, which will allow
108 // embedders to display updates.
109 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
110 base::Bind(&BackgroundFetchClientProxy::AddDownload,
111 client_proxy_->GetWeakPtr(),
112 registration_id.Serialize(), options));
Peter Beverloo 2017/04/20 16:27:55 I'd like to encapsulate the thread-jumps to the Ba
Peter Beverloo 2017/04/20 16:27:55 Should the JobController make this call? It has be
Peter Beverloo 2017/04/24 14:39:14 Ping.
113
106 // Create the BackgroundFetchRegistration the renderer process will receive, 114 // Create the BackgroundFetchRegistration the renderer process will receive,
107 // which enables it to resolve the promise telling the developer it worked. 115 // which enables it to resolve the promise telling the developer it worked.
108 BackgroundFetchRegistration registration; 116 BackgroundFetchRegistration registration;
109 registration.tag = registration_id.tag(); 117 registration.tag = registration_id.tag();
110 registration.icons = options.icons; 118 registration.icons = options.icons;
111 registration.title = options.title; 119 registration.title = options.title;
112 registration.total_download_size = options.total_download_size; 120 registration.total_download_size = options.total_download_size;
113 121
114 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); 122 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration);
115 } 123 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // TODO(harkness): pass the command to the JobController for the given task. 256 // TODO(harkness): pass the command to the JobController for the given task.
249 } 257 }
250 258
251 void BackgroundFetchContext::ResumeFetch( 259 void BackgroundFetchContext::ResumeFetch(
252 const BackgroundFetchRegistrationId& registration_id) { 260 const BackgroundFetchRegistrationId& registration_id) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); 261 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 // TODO(harkness): pass the command to the JobController for the given task. 262 // TODO(harkness): pass the command to the JobController for the given task.
255 } 263 }
256 264
257 } // namespace content 265 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698