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

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

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
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 #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 <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/background_fetch_delegate.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h" 16 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 class BackgroundFetchDataManager; 20 class BackgroundFetchDataManager;
20 class BackgroundFetchJobController; 21 class BackgroundFetchJobController;
21 struct BackgroundFetchOptions; 22 struct BackgroundFetchOptions;
22 class BackgroundFetchRegistrationId; 23 class BackgroundFetchRegistrationId;
23 class BrowserContext; 24 class BrowserContext;
24 class ServiceWorkerContextWrapper; 25 class ServiceWorkerContextWrapper;
25 struct ServiceWorkerFetchRequest; 26 struct ServiceWorkerFetchRequest;
26 class StoragePartitionImpl; 27 class StoragePartitionImpl;
27 28
28 // The BackgroundFetchContext is the central moderator of ongoing background 29 // The BackgroundFetchContext is the central moderator of ongoing background
29 // fetch requests from the Mojo service and from other callers. 30 // fetch requests from the Mojo service and from other callers.
30 // Background Fetch requests function similar to normal fetches except that 31 // Background Fetch requests function similar to normal fetches except that
31 // they are persistent across Chromium or service worker shutdown. 32 // they are persistent across Chromium or service worker shutdown.
32 class CONTENT_EXPORT BackgroundFetchContext 33 class CONTENT_EXPORT BackgroundFetchContext
33 : public base::RefCountedThreadSafe<BackgroundFetchContext, 34 : public BackgroundFetchDelegate,
35 public base::RefCountedThreadSafe<BackgroundFetchContext,
34 BrowserThread::DeleteOnUIThread> { 36 BrowserThread::DeleteOnUIThread> {
35 public: 37 public:
36 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so 38 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so
37 // that it can respond to service worker events such as unregister. 39 // that it can respond to service worker events such as unregister.
38 BackgroundFetchContext( 40 BackgroundFetchContext(
39 BrowserContext* browser_context, 41 BrowserContext* browser_context,
40 StoragePartitionImpl* storage_partition, 42 StoragePartitionImpl* storage_partition,
41 const scoped_refptr<ServiceWorkerContextWrapper>& context); 43 const scoped_refptr<ServiceWorkerContextWrapper>& context);
42 44
43 // Shutdown must be called before deleting this. Call on the UI thread. 45 // Shutdown must be called before deleting this. Call on the UI thread.
44 void Shutdown(); 46 void Shutdown();
45 47
46 // Starts a Background Fetch for the |registration_id|. The |requests| will be 48 // Starts a Background Fetch for the |registration_id|. The |requests| will be
47 // asynchronously fetched. The |callback| will be invoked when the fetch has 49 // asynchronously fetched. The |callback| will be invoked when the fetch has
48 // been registered, or an error occurred that avoids it from doing so. 50 // been registered, or an error occurred that avoids it from doing so.
49 void StartFetch( 51 void StartFetch(
50 const BackgroundFetchRegistrationId& registration_id, 52 const BackgroundFetchRegistrationId& registration_id,
51 const std::vector<ServiceWorkerFetchRequest>& requests, 53 const std::vector<ServiceWorkerFetchRequest>& requests,
52 const BackgroundFetchOptions& options, 54 const BackgroundFetchOptions& options,
53 const blink::mojom::BackgroundFetchService::FetchCallback& callback); 55 const blink::mojom::BackgroundFetchService::FetchCallback& callback);
54 56
57 // BackgroundFetchDelegate method overrides;
Peter Beverloo 2017/03/29 14:32:12 nit: s/method overrides;/implementation:/ (They'r
harkness 2017/03/30 12:42:35 Done.
58 void CancelDownload(const std::string& id) override;
59 void PauseDownload(const std::string& id) override;
60 void ResumeDownload(const std::string& id) override;
Peter Beverloo 2017/03/29 14:32:12 nit: could we s/id/serialized_registration_id/ to
harkness 2017/03/30 12:42:35 Done.
61
55 private: 62 private:
56 friend class base::DeleteHelper<BackgroundFetchContext>; 63 friend class base::DeleteHelper<BackgroundFetchContext>;
57 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 64 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
58 friend class base::RefCountedThreadSafe<BackgroundFetchContext, 65 friend class base::RefCountedThreadSafe<BackgroundFetchContext,
59 BrowserThread::DeleteOnUIThread>; 66 BrowserThread::DeleteOnUIThread>;
60 67
61 ~BackgroundFetchContext(); 68 ~BackgroundFetchContext() override;
62 69
63 // Shuts down the active Job Controllers on the IO thread. 70 // Shuts down the active Job Controllers on the IO thread.
64 void ShutdownOnIO(); 71 void ShutdownOnIO();
65 72
66 // Creates a new Job Controller for the given |registration_id| and |options|, 73 // Creates a new Job Controller for the given |registration_id| and |options|,
67 // which will start fetching the files that are part of the registration. 74 // which will start fetching the files that are part of the registration.
68 void CreateController(const BackgroundFetchRegistrationId& registration_id, 75 void CreateController(const BackgroundFetchRegistrationId& registration_id,
69 const BackgroundFetchOptions& options); 76 const BackgroundFetchOptions& options);
70 77
71 // Called when a new registration has been created by the data manager. 78 // Called when a new registration has been created by the data manager.
(...skipping 18 matching lines...) Expand all
90 std::map<BackgroundFetchRegistrationId, 97 std::map<BackgroundFetchRegistrationId,
91 std::unique_ptr<BackgroundFetchJobController>> 98 std::unique_ptr<BackgroundFetchJobController>>
92 active_fetches_; 99 active_fetches_;
93 100
94 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); 101 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext);
95 }; 102 };
96 103
97 } // namespace content 104 } // namespace content
98 105
99 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ 106 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698