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 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
7 | 7 |
| 8 #include <unordered_map> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "content/browser/background_fetch/background_fetch_data_manager.h" | 12 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
11 #include "content/browser/background_fetch/background_fetch_job_controller.h" | 13 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
12 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/browser_thread.h" |
13 | 16 |
14 namespace content { | 17 namespace content { |
15 | 18 |
16 class BackgroundFetchJobInfo; | 19 class BackgroundFetchJobInfo; |
17 class BackgroundFetchRequestInfo; | 20 class BackgroundFetchRequestInfo; |
18 class BrowserContext; | 21 class BrowserContext; |
19 class ServiceWorkerContextWrapper; | 22 class ServiceWorkerContextWrapper; |
20 | 23 |
21 // The BackgroundFetchContext is the central moderator of ongoing background | 24 // The BackgroundFetchContext is the central moderator of ongoing background |
22 // fetch requests from the Mojo service and from other callers. | 25 // fetch requests from the Mojo service and from other callers. |
23 // Background Fetch requests function similar to normal fetches except that | 26 // Background Fetch requests function similar to normal fetches except that |
24 // they are persistent across Chromium or service worker shutdown. | 27 // they are persistent across Chromium or service worker shutdown. |
25 class CONTENT_EXPORT BackgroundFetchContext | 28 class CONTENT_EXPORT BackgroundFetchContext |
26 : public base::RefCountedThreadSafe<BackgroundFetchContext> { | 29 : public base::RefCountedThreadSafe<BackgroundFetchContext, |
| 30 BrowserThread::DeleteOnUIThread> { |
27 public: | 31 public: |
28 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so | 32 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so |
29 // that it can respond to service worker events such as unregister. | 33 // that it can respond to service worker events such as unregister. |
30 BackgroundFetchContext( | 34 BackgroundFetchContext( |
31 BrowserContext* browser_context, | 35 BrowserContext* browser_context, |
32 StoragePartition* storage_partition, | 36 StoragePartition* storage_partition, |
33 const scoped_refptr<ServiceWorkerContextWrapper>& context); | 37 const scoped_refptr<ServiceWorkerContextWrapper>& context); |
34 | 38 |
35 // Init and Shutdown are for use on the UI thread when the StoragePartition is | 39 // Init and Shutdown are for use on the UI thread when the StoragePartition is |
36 // being setup and torn down. | 40 // being setup and torn down. |
37 void Init(); | 41 void Init(); |
38 | 42 |
39 // Shutdown must be called before deleting this. Call on the UI thread. | 43 // Shutdown must be called before deleting this. Call on the UI thread. |
40 void Shutdown(); | 44 void Shutdown(); |
41 | 45 |
42 BackgroundFetchDataManager* GetDataManagerForTesting() { | 46 BackgroundFetchDataManager* GetDataManagerForTesting() { |
43 return &background_fetch_data_manager_; | 47 return &background_fetch_data_manager_; |
44 } | 48 } |
45 | 49 |
46 private: | 50 private: |
| 51 friend class base::DeleteHelper<BackgroundFetchContext>; |
| 52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 53 friend class base::RefCountedThreadSafe<BackgroundFetchContext, |
| 54 BrowserThread::DeleteOnUIThread>; |
| 55 |
| 56 virtual ~BackgroundFetchContext(); |
| 57 |
47 void CreateRequest(const BackgroundFetchJobInfo& job_info, | 58 void CreateRequest(const BackgroundFetchJobInfo& job_info, |
48 std::vector<BackgroundFetchRequestInfo>& request_infos); | 59 std::vector<BackgroundFetchRequestInfo>& request_infos); |
49 | 60 |
50 friend class base::RefCountedThreadSafe<BackgroundFetchContext>; | 61 void ShutdownOnIO(); |
51 ~BackgroundFetchContext(); | 62 |
| 63 // |this| is owned by the BrowserContext via the StoragePartition. |
| 64 BrowserContext* browser_context_; |
| 65 StoragePartition* storage_partition_; |
52 | 66 |
53 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 67 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
54 BackgroundFetchJobController background_fetch_job_controller_; | |
55 BackgroundFetchDataManager background_fetch_data_manager_; | 68 BackgroundFetchDataManager background_fetch_data_manager_; |
56 | 69 |
| 70 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobController>> |
| 71 job_map_; |
| 72 |
57 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); | 73 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); |
58 }; | 74 }; |
59 | 75 |
60 } // namespace content | 76 } // namespace content |
61 | 77 |
62 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ | 78 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ |
OLD | NEW |