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

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

Issue 2833793002: Added AddDownload communication path and observers
Patch Set: Addressed comments and moved thrad jumps into the client proxy. 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 client_proxy_->AddDownload(GURL(registration_id.origin().Serialize()),
110 registration_id.Serialize(), options);
111
106 // Create the BackgroundFetchRegistration the renderer process will receive, 112 // Create the BackgroundFetchRegistration the renderer process will receive,
107 // which enables it to resolve the promise telling the developer it worked. 113 // which enables it to resolve the promise telling the developer it worked.
108 BackgroundFetchRegistration registration; 114 BackgroundFetchRegistration registration;
109 registration.tag = registration_id.tag(); 115 registration.tag = registration_id.tag();
110 registration.icons = options.icons; 116 registration.icons = options.icons;
111 registration.title = options.title; 117 registration.title = options.title;
112 registration.total_download_size = options.total_download_size; 118 registration.total_download_size = options.total_download_size;
113 119
114 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration); 120 callback.Run(blink::mojom::BackgroundFetchError::NONE, registration);
115 } 121 }
(...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. 254 // TODO(harkness): pass the command to the JobController for the given task.
249 } 255 }
250 256
251 void BackgroundFetchContext::ResumeFetch( 257 void BackgroundFetchContext::ResumeFetch(
252 const BackgroundFetchRegistrationId& registration_id) { 258 const BackgroundFetchRegistrationId& registration_id) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); 259 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 // TODO(harkness): pass the command to the JobController for the given task. 260 // TODO(harkness): pass the command to the JobController for the given task.
255 } 261 }
256 262
257 } // namespace content 263 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698