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

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

Issue 2973233002: [Background Fetch] Cleanup/fix thread safety (Closed)
Patch Set: Remove n.b. from comments Created 3 years, 5 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
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
14 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h" 17 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h"
17 18
18 namespace net { 19 namespace net {
19 class URLRequestContextGetter; 20 class URLRequestContextGetter;
20 } 21 }
21 22
22 namespace url { 23 namespace url {
23 class Origin; 24 class Origin;
24 } 25 }
25 26
26 namespace content { 27 namespace content {
27 28
28 class BackgroundFetchDataManager; 29 class BackgroundFetchDataManager;
29 class BackgroundFetchEventDispatcher; 30 class BackgroundFetchEventDispatcher;
30 class BackgroundFetchJobController; 31 class BackgroundFetchJobController;
31 struct BackgroundFetchOptions; 32 struct BackgroundFetchOptions;
32 class BackgroundFetchRegistrationId; 33 class BackgroundFetchRegistrationId;
33 class BackgroundFetchRequestInfo; 34 class BackgroundFetchRequestInfo;
34 class BlobHandle; 35 class BlobHandle;
35 class BrowserContext; 36 class BrowserContext;
36 class ServiceWorkerContextWrapper; 37 class ServiceWorkerContextWrapper;
37 struct ServiceWorkerFetchRequest; 38 struct ServiceWorkerFetchRequest;
38 class StoragePartitionImpl;
39 39
40 // The BackgroundFetchContext is the central moderator of ongoing background 40 // The BackgroundFetchContext is the central moderator of ongoing background
41 // fetch requests from the Mojo service and from other callers. 41 // fetch requests from the Mojo service and from other callers.
42 // Background Fetch requests function similar to normal fetches except that 42 // Background Fetch requests function similarly to normal fetches except that
43 // they are persistent across Chromium or service worker shutdown. 43 // they are persistent across Chromium or service worker shutdown.
44 class CONTENT_EXPORT BackgroundFetchContext 44 class CONTENT_EXPORT BackgroundFetchContext
45 : public base::RefCountedThreadSafe<BackgroundFetchContext, 45 : public base::RefCountedThreadSafe<BackgroundFetchContext,
46 BrowserThread::DeleteOnUIThread> { 46 BrowserThread::DeleteOnIOThread> {
47 public: 47 public:
48 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so 48 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so
49 // that it can respond to service worker events such as unregister. 49 // that it can respond to service worker events such as unregister.
50 BackgroundFetchContext(BrowserContext* browser_context, 50 BackgroundFetchContext(BrowserContext* browser_context,
51 StoragePartitionImpl* storage_partition,
52 scoped_refptr<ServiceWorkerContextWrapper> context); 51 scoped_refptr<ServiceWorkerContextWrapper> context);
53 52
54 // Finishes initializing the Background Fetch context on the IO thread by 53 // Finishes initializing the Background Fetch context on the IO thread by
55 // setting the |request_context_getter|. 54 // setting the |request_context_getter|.
56 void InitializeOnIOThread( 55 void InitializeOnIOThread(
57 scoped_refptr<net::URLRequestContextGetter> request_context_getter); 56 scoped_refptr<net::URLRequestContextGetter> request_context_getter);
58 57
59 // Shutdown must be called before deleting this. Call on the UI thread.
60 void Shutdown();
61
62 // Starts a Background Fetch for the |registration_id|. The |requests| will be 58 // Starts a Background Fetch for the |registration_id|. The |requests| will be
63 // asynchronously fetched. The |callback| will be invoked when the fetch has 59 // asynchronously fetched. The |callback| will be invoked when the fetch has
64 // been registered, or an error occurred that avoids it from doing so. 60 // been registered, or an error occurred that avoids it from doing so.
65 void StartFetch(const BackgroundFetchRegistrationId& registration_id, 61 void StartFetch(const BackgroundFetchRegistrationId& registration_id,
66 const std::vector<ServiceWorkerFetchRequest>& requests, 62 const std::vector<ServiceWorkerFetchRequest>& requests,
67 const BackgroundFetchOptions& options, 63 const BackgroundFetchOptions& options,
68 blink::mojom::BackgroundFetchService::FetchCallback callback); 64 blink::mojom::BackgroundFetchService::FetchCallback callback);
69 65
70 // Returns a vector with the tags of the active fetches for the given |origin| 66 // Returns a vector with the tags of the active fetches for the given |origin|
71 // and |service_worker_registration_id|. 67 // and |service_worker_registration_id|.
72 std::vector<std::string> GetActiveTagsForServiceWorkerRegistration( 68 std::vector<std::string> GetActiveTagsForServiceWorkerRegistration(
73 int64_t service_worker_registration_id, 69 int64_t service_worker_registration_id,
74 const url::Origin& origin) const; 70 const url::Origin& origin) const;
75 71
76 // Returns the JobController that is handling the |registration_id|, or a 72 // Returns the JobController that is handling the |registration_id|, or a
77 // nullptr if it does not exist. Must be immediately used by the caller. 73 // nullptr if it does not exist. Must be immediately used by the caller.
78 BackgroundFetchJobController* GetActiveFetch( 74 BackgroundFetchJobController* GetActiveFetch(
79 const BackgroundFetchRegistrationId& registration_id) const; 75 const BackgroundFetchRegistrationId& registration_id) const;
80 76
81 private: 77 private:
82 friend class base::DeleteHelper<BackgroundFetchContext>; 78 friend class base::DeleteHelper<BackgroundFetchContext>;
83 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 79 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
84 friend class base::RefCountedThreadSafe<BackgroundFetchContext, 80 friend class base::RefCountedThreadSafe<BackgroundFetchContext,
85 BrowserThread::DeleteOnUIThread>; 81 BrowserThread::DeleteOnIOThread>;
86 82
87 ~BackgroundFetchContext(); 83 ~BackgroundFetchContext();
88 84
89 // Shuts down the active Job Controllers on the IO thread.
90 void ShutdownOnIO();
91
92 // Creates a new Job Controller for the given |registration_id| and |options|, 85 // Creates a new Job Controller for the given |registration_id| and |options|,
93 // which will start fetching the files that are part of the registration. 86 // which will start fetching the files that are part of the registration.
94 void CreateController( 87 void CreateController(
95 const BackgroundFetchRegistrationId& registration_id, 88 const BackgroundFetchRegistrationId& registration_id,
96 const BackgroundFetchOptions& options, 89 const BackgroundFetchOptions& options,
97 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests); 90 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests);
98 91
99 // Called when a new registration has been created by the data manager. 92 // Called when a new registration has been created by the data manager.
100 void DidCreateRegistration( 93 void DidCreateRegistration(
101 const BackgroundFetchRegistrationId& registration_id, 94 const BackgroundFetchRegistrationId& registration_id,
(...skipping 26 matching lines...) Expand all
128 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 121 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
129 122
130 std::unique_ptr<BackgroundFetchDataManager> data_manager_; 123 std::unique_ptr<BackgroundFetchDataManager> data_manager_;
131 std::unique_ptr<BackgroundFetchEventDispatcher> event_dispatcher_; 124 std::unique_ptr<BackgroundFetchEventDispatcher> event_dispatcher_;
132 125
133 // Map of the Background Fetch fetches that are currently in-progress. 126 // Map of the Background Fetch fetches that are currently in-progress.
134 std::map<BackgroundFetchRegistrationId, 127 std::map<BackgroundFetchRegistrationId,
135 std::unique_ptr<BackgroundFetchJobController>> 128 std::unique_ptr<BackgroundFetchJobController>>
136 active_fetches_; 129 active_fetches_;
137 130
131 base::WeakPtrFactory<BackgroundFetchContext> weak_factory_; // Must be last.
132
138 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); 133 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext);
139 }; 134 };
140 135
141 } // namespace content 136 } // namespace content
142 137
143 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ 138 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698