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

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

Issue 2770343002: Teach Background Fetch how to start a new fetch. (Closed)
Patch Set: Teach Background Fetch how to start a new fetch. 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
« 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 <string>
9 #include <vector>
8 #include <unordered_map> 10 #include <unordered_map>
9 11
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
12 #include "content/browser/background_fetch/background_fetch_data_manager.h" 14 #include "content/browser/background_fetch/background_fetch_data_manager.h"
13 #include "content/browser/background_fetch/background_fetch_job_controller.h" 15 #include "content/browser/background_fetch/background_fetch_job_controller.h"
14 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "third_party/WebKit/public/platform/modules/background_fetch/background _fetch.mojom.h"
19
20 namespace url {
21 class Origin;
22 }
16 23
17 namespace content { 24 namespace content {
18 25
19 class BackgroundFetchJobInfo; 26 class BackgroundFetchJobInfo;
27 struct BackgroundFetchOptions;
28 class BackgroundFetchRegistrationId;
20 class BackgroundFetchRequestInfo; 29 class BackgroundFetchRequestInfo;
21 class BrowserContext; 30 class BrowserContext;
22 class ServiceWorkerContextWrapper; 31 class ServiceWorkerContextWrapper;
32 struct ServiceWorkerFetchRequest;
23 33
24 // The BackgroundFetchContext is the central moderator of ongoing background 34 // The BackgroundFetchContext is the central moderator of ongoing background
25 // fetch requests from the Mojo service and from other callers. 35 // fetch requests from the Mojo service and from other callers.
26 // Background Fetch requests function similar to normal fetches except that 36 // Background Fetch requests function similar to normal fetches except that
27 // they are persistent across Chromium or service worker shutdown. 37 // they are persistent across Chromium or service worker shutdown.
28 class CONTENT_EXPORT BackgroundFetchContext 38 class CONTENT_EXPORT BackgroundFetchContext
29 : public base::RefCountedThreadSafe<BackgroundFetchContext, 39 : public base::RefCountedThreadSafe<BackgroundFetchContext,
30 BrowserThread::DeleteOnUIThread> { 40 BrowserThread::DeleteOnUIThread> {
31 public: 41 public:
32 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so 42 // The BackgroundFetchContext will watch the ServiceWorkerContextWrapper so
33 // that it can respond to service worker events such as unregister. 43 // that it can respond to service worker events such as unregister.
34 BackgroundFetchContext( 44 BackgroundFetchContext(
35 BrowserContext* browser_context, 45 BrowserContext* browser_context,
36 StoragePartition* storage_partition, 46 StoragePartition* storage_partition,
37 const scoped_refptr<ServiceWorkerContextWrapper>& context); 47 const scoped_refptr<ServiceWorkerContextWrapper>& context);
38 48
39 // Init and Shutdown are for use on the UI thread when the StoragePartition is
40 // being setup and torn down.
41 void Init();
42
43 // Shutdown must be called before deleting this. Call on the UI thread. 49 // Shutdown must be called before deleting this. Call on the UI thread.
44 void Shutdown(); 50 void Shutdown();
45 51
52 // Starts a Background Fetch for the |registration_id|. The |requests| will be
53 // asynchronously fetched. The |callback| will be invoked when the fetch has
54 // been registered, or an error occurred that avoids it from doing so.
55 void StartFetch(
56 const BackgroundFetchRegistrationId& registration_id,
57 const std::vector<ServiceWorkerFetchRequest>& requests,
58 const BackgroundFetchOptions& options,
59 const blink::mojom::BackgroundFetchService::FetchCallback& callback);
60
61 // Returns the active Background Fetch job for the |registration_id|. Will
62 // return a nullptr when there is no such job. The value returned from this
63 // method should not be cached for later use.
64 BackgroundFetchJobController* GetActiveJobForRegistrationId(
65 const BackgroundFetchRegistrationId& registration_id) const;
66
46 BackgroundFetchDataManager* GetDataManagerForTesting() { 67 BackgroundFetchDataManager* GetDataManagerForTesting() {
47 return &background_fetch_data_manager_; 68 return &background_fetch_data_manager_;
48 } 69 }
49 70
50 private: 71 private:
51 friend class base::DeleteHelper<BackgroundFetchContext>; 72 friend class base::DeleteHelper<BackgroundFetchContext>;
52 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 73 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
53 friend class base::RefCountedThreadSafe<BackgroundFetchContext, 74 friend class base::RefCountedThreadSafe<BackgroundFetchContext,
54 BrowserThread::DeleteOnUIThread>; 75 BrowserThread::DeleteOnUIThread>;
55 76
56 ~BackgroundFetchContext(); 77 ~BackgroundFetchContext();
57 78
58 void CreateRequest(std::unique_ptr<BackgroundFetchJobInfo> job_info, 79 // Called when a new registration has been created by the data manager.
59 std::vector<BackgroundFetchRequestInfo>& request_infos); 80 void DidCreateCreateRegistration(
81 const BackgroundFetchRegistrationId& registration_id,
82 const BackgroundFetchOptions& options,
83 const blink::mojom::BackgroundFetchService::FetchCallback& callback,
84 blink::mojom::BackgroundFetchError error,
85 std::unique_ptr<BackgroundFetchJobData> job_data);
60 86
61 // Callback for the JobController when the job is complete. 87 // Callback for the JobController when the job is complete.
62 void DidCompleteJob(const std::string& job_guid); 88 void DidCompleteJob(const std::string& job_guid);
63 89
64 void ShutdownOnIO(); 90 void ShutdownOnIO();
65 91
66 // |this| is owned by the BrowserContext via the StoragePartition. 92 // |this| is owned by the BrowserContext via the StoragePartition.
67 BrowserContext* browser_context_; 93 BrowserContext* browser_context_;
68 StoragePartition* storage_partition_; 94 StoragePartition* storage_partition_;
69 95
70 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 96 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
71 BackgroundFetchDataManager background_fetch_data_manager_; 97 BackgroundFetchDataManager background_fetch_data_manager_;
72 98
73 std::unordered_map<std::string, std::unique_ptr<BackgroundFetchJobController>> 99 std::vector<std::unique_ptr<BackgroundFetchJobController>> controllers_;
74 job_map_;
75 100
76 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext); 101 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchContext);
77 }; 102 };
78 103
79 } // namespace content 104 } // namespace content
80 105
81 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_CONTEXT_H_ 106 #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