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_client_proxy.h" | 5 #include "content/browser/background_fetch/background_fetch_client_proxy.h" |
6 | 6 |
7 #include "content/browser/background_fetch/background_fetch_context.h" | 7 #include "content/browser/background_fetch/background_fetch_context.h" |
8 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 8 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
9 #include "content/common/background_fetch/background_fetch_types.h" | |
10 #include "content/public/browser/browser_context.h" | |
9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
10 | 12 |
11 namespace content { | 13 namespace content { |
12 | 14 |
13 BackgroundFetchClientProxy::BackgroundFetchClientProxy( | 15 BackgroundFetchClientProxy::BackgroundFetchClientProxy( |
16 BrowserContext* browser_context, | |
14 BackgroundFetchContext* background_fetch_context) | 17 BackgroundFetchContext* background_fetch_context) |
15 : background_fetch_context_(background_fetch_context) { | 18 : background_fetch_context_(background_fetch_context), |
19 weak_ptr_factory_(this) { | |
16 DCHECK(background_fetch_context); | 20 DCHECK(background_fetch_context); |
21 DCHECK(browser_context); | |
22 background_fetch_client_ = browser_context->GetBackgroundFetchClient(); | |
23 DCHECK(background_fetch_client_); | |
17 } | 24 } |
18 | 25 |
19 BackgroundFetchClientProxy::~BackgroundFetchClientProxy() = default; | 26 BackgroundFetchClientProxy::~BackgroundFetchClientProxy() = default; |
20 | 27 |
28 void BackgroundFetchClientProxy::AddDownload( | |
29 const GURL& url, | |
30 const std::string& registration_id, | |
31 const BackgroundFetchOptions& options) { | |
32 BrowserThread::PostTask( | |
Peter Beverloo
2017/04/24 14:39:15
DCHECK_CURRENTLY_ON() to both new methods.
AddDow
| |
33 BrowserThread::IO, FROM_HERE, | |
34 base::Bind(&BackgroundFetchClientProxy::AddDownloadOnIO, | |
35 weak_ptr_factory_.GetWeakPtr(), url, registration_id, | |
36 options)); | |
37 } | |
38 | |
39 void BackgroundFetchClientProxy::AddDownloadOnIO( | |
40 const GURL& url, | |
41 const std::string& registration_id, | |
42 const BackgroundFetchOptions& options) { | |
43 background_fetch_client_->AddDownload(url, registration_id, options.title, | |
44 options.total_download_size); | |
45 } | |
46 | |
21 void BackgroundFetchClientProxy::CleanupAllTasks() { | 47 void BackgroundFetchClientProxy::CleanupAllTasks() { |
22 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
23 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 49 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
24 base::Bind(&BackgroundFetchContext::CleanupAllTasks, | 50 base::Bind(&BackgroundFetchContext::CleanupAllTasks, |
25 background_fetch_context_)); | 51 background_fetch_context_)); |
26 } | 52 } |
27 | 53 |
28 void BackgroundFetchClientProxy::CancelDownload( | 54 void BackgroundFetchClientProxy::CancelDownload( |
29 const std::string& registration_id) { | 55 const std::string& registration_id) { |
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 return; | 93 return; |
68 } | 94 } |
69 | 95 |
70 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
71 BrowserThread::IO, FROM_HERE, | 97 BrowserThread::IO, FROM_HERE, |
72 base::Bind(&BackgroundFetchContext::ResumeFetch, | 98 base::Bind(&BackgroundFetchContext::ResumeFetch, |
73 background_fetch_context_, deserialized_id)); | 99 background_fetch_context_, deserialized_id)); |
74 } | 100 } |
75 | 101 |
76 } // namespace content | 102 } // namespace content |
OLD | NEW |