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

Side by Side Diff: components/offline_pages/core/prefetch/prefetch_service.h

Issue 2820263002: [Offline Prefetch] Create a new JobScheduler task to wake up for net activity. (Closed)
Patch Set: Remove the "Is Scheduled" check because it's not supported by BackgroundTaskScheduler. 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 COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_H_
7 7
8 #include "components/keyed_service/core/keyed_service.h" 8 #include "components/keyed_service/core/keyed_service.h"
9 #include "components/offline_pages/core/offline_page_item.h" 9 #include "components/offline_pages/core/offline_page_item.h"
10 10
11 class GURL; 11 class GURL;
12 12
13 namespace offline_pages { 13 namespace offline_pages {
14 14
15 // Main class for the Offline Pages Prefetching feature, which will ask a server 15 // Main class for the Offline Pages Prefetching feature, which will ask a server
16 // to package content from interesting URLs and send it to Chrome for 16 // to package content from interesting URLs and send it to Chrome for
17 // consumption while offline. 17 // consumption while offline.
18 class PrefetchService : public KeyedService { 18 class PrefetchService : public KeyedService {
19 public: 19 public:
20 struct PrefetchURL { 20 struct PrefetchURL {
21 // Used to differentiate URLs from different sources. |name_space| should 21 // Used to differentiate URLs from different sources. |name_space| should
22 // be unique per source. |id| can be anything useful to identify the page, 22 // be unique per source. |id| can be anything useful to identify the page,
23 // but will not be used for deduplication. 23 // but will not be used for deduplication.
24 ClientId client_id; 24 ClientId client_id;
25 25
26 // This URL will be prefetched by the service. 26 // This URL will be prefetched by the service.
27 GURL url; 27 GURL url;
28 }; 28 };
29 29
30 // A |ScopedBackgroundTask| is created when we are running in a background
31 // task. Destroying this object should notify the system that we are done
32 // processing the background task.
33 class ScopedBackgroundTask {
34 public:
35 ScopedBackgroundTask();
36 virtual ~ScopedBackgroundTask();
37
38 virtual void SetNeedsReschedule(bool reschedule) = 0;
39 };
40
30 ~PrefetchService() override = default; 41 ~PrefetchService() override = default;
31 42
32 // Called when a consumer has candidate URLs for the system to prefetch. 43 // Called when a consumer has candidate URLs for the system to prefetch.
33 // Duplicates are accepted by the PrefetchService but ignored. 44 // Duplicates are accepted by the PrefetchService but ignored.
34 virtual void AddCandidatePrefetchURLs( 45 virtual void AddCandidatePrefetchURLs(
35 const std::vector<PrefetchURL>& prefetch_urls) = 0; 46 const std::vector<PrefetchURL>& prefetch_urls) = 0;
36 47
37 // Called when all existing suggestions are no longer considered valid for a 48 // Called when all existing suggestions are no longer considered valid for a
38 // given namespace. The prefetch service should remove any URLs that 49 // given namespace. The prefetch service should remove any URLs that
39 // have not yet started downloading within that namespace. 50 // have not yet started downloading within that namespace.
40 virtual void RemoveAllUnprocessedPrefetchURLs( 51 virtual void RemoveAllUnprocessedPrefetchURLs(
41 const std::string& name_space) = 0; 52 const std::string& name_space) = 0;
42 53
43 // Called to invalidate a single PrefetchURL entry identified by |client_id|. 54 // Called to invalidate a single PrefetchURL entry identified by |client_id|.
44 // If multiple have the same |client_id|, they will all be removed. 55 // If multiple have the same |client_id|, they will all be removed.
45 virtual void RemovePrefetchURLsByClientId(const ClientId& client_id) = 0; 56 virtual void RemovePrefetchURLsByClientId(const ClientId& client_id) = 0;
57
58 virtual void BeginBackgroundTask(
carlosk 2017/04/19 23:01:38 nit: add descriptive comment.
59 std::unique_ptr<ScopedBackgroundTask> task) = 0;
60
61 // Called when a task must stop immediately due to system constraints. After
62 // this call completes, the system will reschedule the task based on whether
63 // SetNeedsReschedule has been called.
64 virtual void StopBackgroundTask(ScopedBackgroundTask* task) = 0;
46 }; 65 };
47 66
48 } // namespace offline_pages 67 } // namespace offline_pages
49 68
50 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_IMPL_H_ 69 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698