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

Side by Side Diff: content/browser/service_worker/service_worker_database.h

Issue 2521793004: service worker: Persist NavigationPreloadState (Closed)
Patch Set: expect_ name Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/optional.h" 19 #include "base/optional.h"
20 #include "base/sequence_checker.h" 20 #include "base/sequence_checker.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
23 #include "content/common/origin_trials/trial_token_validator.h" 23 #include "content/common/origin_trials/trial_token_validator.h"
24 #include "content/common/service_worker/service_worker_status_code.h" 24 #include "content/common/service_worker/service_worker_status_code.h"
25 #include "content/common/service_worker/service_worker_types.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 #include "url/origin.h" 27 #include "url/origin.h"
27 28
28 namespace leveldb { 29 namespace leveldb {
29 class DB; 30 class DB;
30 class Env; 31 class Env;
31 class Status; 32 class Status;
32 class WriteBatch; 33 class WriteBatch;
33 } 34 }
34 35
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // the waiting version. Then transition to the active version. The stored 67 // the waiting version. Then transition to the active version. The stored
67 // version may be in the ACTIVATED state or in the INSTALLED state. 68 // version may be in the ACTIVATED state or in the INSTALLED state.
68 GURL script; 69 GURL script;
69 int64_t version_id; 70 int64_t version_id;
70 bool is_active; 71 bool is_active;
71 bool has_fetch_handler; 72 bool has_fetch_handler;
72 base::Time last_update_check; 73 base::Time last_update_check;
73 std::vector<GURL> foreign_fetch_scopes; 74 std::vector<GURL> foreign_fetch_scopes;
74 std::vector<url::Origin> foreign_fetch_origins; 75 std::vector<url::Origin> foreign_fetch_origins;
75 base::Optional<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens; 76 base::Optional<TrialTokenValidator::FeatureToTokensMap> origin_trial_tokens;
77 NavigationPreloadState navigation_preload_state;
76 78
77 // Not populated until ServiceWorkerStorage::StoreRegistration is called. 79 // Not populated until ServiceWorkerStorage::StoreRegistration is called.
78 int64_t resources_total_size_bytes; 80 int64_t resources_total_size_bytes;
79 81
80 RegistrationData(); 82 RegistrationData();
81 RegistrationData(const RegistrationData& other); 83 RegistrationData(const RegistrationData& other);
82 ~RegistrationData(); 84 ~RegistrationData();
83 }; 85 };
84 86
85 struct ResourceRecord { 87 struct ResourceRecord {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Updates a registration for |registration_id| to an active state. Returns OK 159 // Updates a registration for |registration_id| to an active state. Returns OK
158 // if it's successfully updated. Otherwise, returns an error. 160 // if it's successfully updated. Otherwise, returns an error.
159 Status UpdateVersionToActive(int64_t registration_id, const GURL& origin); 161 Status UpdateVersionToActive(int64_t registration_id, const GURL& origin);
160 162
161 // Updates last check time of a registration for |registration_id| by |time|. 163 // Updates last check time of a registration for |registration_id| by |time|.
162 // Returns OK if it's successfully updated. Otherwise, returns an error. 164 // Returns OK if it's successfully updated. Otherwise, returns an error.
163 Status UpdateLastCheckTime(int64_t registration_id, 165 Status UpdateLastCheckTime(int64_t registration_id,
164 const GURL& origin, 166 const GURL& origin,
165 const base::Time& time); 167 const base::Time& time);
166 168
169 // Updates the navigation preload state for the specified registration.
170 // Returns OK if it's successfully updated. Otherwise, returns an error.
171 Status UpdateNavigationPreloadEnabled(int64_t registration_id,
172 const GURL& origin,
173 bool enable);
174 Status UpdateNavigationPreloadHeader(int64_t registration_id,
175 const GURL& origin,
176 const std::string& value);
177
167 // Deletes a registration for |registration_id| and moves resource records 178 // Deletes a registration for |registration_id| and moves resource records
168 // associated with it into the purgeable list. If deletion occurred, sets 179 // associated with it into the purgeable list. If deletion occurred, sets
169 // |version_id| to the id of the version that was deleted and 180 // |version_id| to the id of the version that was deleted and
170 // |newly_purgeable_resources| to its resources; otherwise, sets |version_id| 181 // |newly_purgeable_resources| to its resources; otherwise, sets |version_id|
171 // to -1. Returns OK if it's successfully deleted or not found in the 182 // to -1. Returns OK if it's successfully deleted or not found in the
172 // database. Otherwise, returns an error. 183 // database. Otherwise, returns an error.
173 Status DeleteRegistration(int64_t registration_id, 184 Status DeleteRegistration(int64_t registration_id,
174 const GURL& origin, 185 const GURL& origin,
175 RegistrationData* deleted_version, 186 RegistrationData* deleted_version,
176 std::vector<int64_t>* newly_purgeable_resources); 187 std::vector<int64_t>* newly_purgeable_resources);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // if successfully reads. Otherwise, returns an error. 275 // if successfully reads. Otherwise, returns an error.
265 Status ReadRegistrationData(int64_t registration_id, 276 Status ReadRegistrationData(int64_t registration_id,
266 const GURL& origin, 277 const GURL& origin,
267 RegistrationData* registration); 278 RegistrationData* registration);
268 279
269 // Parses |serialized| as a RegistrationData object and pushes it into |out|. 280 // Parses |serialized| as a RegistrationData object and pushes it into |out|.
270 ServiceWorkerDatabase::Status ParseRegistrationData( 281 ServiceWorkerDatabase::Status ParseRegistrationData(
271 const std::string& serialized, 282 const std::string& serialized,
272 RegistrationData* out); 283 RegistrationData* out);
273 284
285 // Populates |batch| with operations to write |registration|. It does not
286 // actually write to db yet.
274 void WriteRegistrationDataInBatch(const RegistrationData& registration, 287 void WriteRegistrationDataInBatch(const RegistrationData& registration,
275 leveldb::WriteBatch* batch); 288 leveldb::WriteBatch* batch);
276 289
277 // Reads resource records for |registration| from the database. Returns OK if 290 // Reads resource records for |registration| from the database. Returns OK if
278 // it's successfully read or not found in the database. Otherwise, returns an 291 // it's successfully read or not found in the database. Otherwise, returns an
279 // error. 292 // error.
280 Status ReadResourceRecords(const RegistrationData& registration, 293 Status ReadResourceRecords(const RegistrationData& registration,
281 std::vector<ResourceRecord>* resources); 294 std::vector<ResourceRecord>* resources);
282 295
283 // Parses |serialized| as a ResourceRecord object and pushes it into |out|. 296 // Parses |serialized| as a ResourceRecord object and pushes it into |out|.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, 396 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest,
384 UserData_UninitializedDatabase); 397 UserData_UninitializedDatabase);
385 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase); 398 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase);
386 399
387 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); 400 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase);
388 }; 401 };
389 402
390 } // namespace content 403 } // namespace content
391 404
392 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ 405 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698