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

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

Issue 257593003: ServiceWorker: Clean up ServiceWorkerDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/sequence_checker.h" 11 #include "base/sequence_checker.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/browser/service_worker/service_worker_version.h" 13 #include "content/browser/service_worker/service_worker_version.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace leveldb { 17 namespace leveldb {
18 class DB; 18 class DB;
19 class Env; 19 class Env;
20 class Slice; 20 class Status;
21 class WriteBatch; 21 class WriteBatch;
22 } 22 }
23 23
24 namespace content { 24 namespace content {
25 25
26 // Class to persist serviceworker regitration data in a database. 26 // Class to persist serviceworker registration data in a database.
27 // Should NOT be used on the IO thread since this does blocking 27 // Should NOT be used on the IO thread since this does blocking
28 // file io. The ServiceWorkerStorage class owns this class and 28 // file io. The ServiceWorkerStorage class owns this class and
29 // is responsible for only calling it serially on background 29 // is responsible for only calling it serially on background
30 // nonIO threads (ala SequencedWorkerPool). 30 // non-IO threads (ala SequencedWorkerPool).
31 class CONTENT_EXPORT ServiceWorkerDatabase { 31 class CONTENT_EXPORT ServiceWorkerDatabase {
32 public: 32 public:
33 // We do leveldb stuff in |path| or in memory if |path| is empty. 33 // We do leveldb stuff in |path| or in memory if |path| is empty.
34 explicit ServiceWorkerDatabase(const base::FilePath& path); 34 explicit ServiceWorkerDatabase(const base::FilePath& path);
35 ~ServiceWorkerDatabase(); 35 ~ServiceWorkerDatabase();
36 36
37 struct RegistrationData { 37 struct RegistrationData {
38 // These values are immutable for the life of a registration. 38 // These values are immutable for the life of a registration.
39 int64 registration_id; 39 int64 registration_id;
40 GURL scope; 40 GURL scope;
(...skipping 29 matching lines...) Expand all
70 // Opens the database at the |path_|. This is lazily called when the first 70 // Opens the database at the |path_|. This is lazily called when the first
71 // database API is called. Returns true if the database was opened. Returns 71 // database API is called. Returns true if the database was opened. Returns
72 // false if the opening failed or was not neccessary, that is, the database 72 // false if the opening failed or was not neccessary, that is, the database
73 // does not exist and |create_if_needed| is false. 73 // does not exist and |create_if_needed| is false.
74 bool LazyOpen(bool create_if_needed); 74 bool LazyOpen(bool create_if_needed);
75 75
76 // Populates the database with initial data, namely, database schema version 76 // Populates the database with initial data, namely, database schema version
77 // and next available IDs. 77 // and next available IDs.
78 bool PopulateInitialData(); 78 bool PopulateInitialData();
79 79
80 bool ReadInt64(const leveldb::Slice& key, int64* value_out); 80 bool ReadNextAvailableId(const char* id_key,
81 bool WriteBatch(scoped_ptr<leveldb::WriteBatch> batch); 81 int64* next_avail_id);
82 bool WriteBatch(leveldb::WriteBatch* batch);
82 83
83 bool IsOpen(); 84 bool IsOpen();
84 bool IsEmpty(); 85 bool IsEmpty();
85 86
87 void HandleError(const tracked_objects::Location& from_here,
88 const leveldb::Status& status);
89
86 base::FilePath path_; 90 base::FilePath path_;
87 scoped_ptr<leveldb::Env> env_; 91 scoped_ptr<leveldb::Env> env_;
88 scoped_ptr<leveldb::DB> db_; 92 scoped_ptr<leveldb::DB> db_;
89 93
90 // True if a database error has occurred (e.g. cannot read data). 94 // True if a database error has occurred (e.g. cannot read data).
91 // If true, all database accesses will fail. 95 // If true, all database accesses will fail.
92 bool is_disabled_; 96 bool is_disabled_;
93 97
94 // True if a database corruption was detected. 98 // True if a database corruption was detected.
95 bool was_corruption_detected_; 99 bool was_corruption_detected_;
96 100
97 base::SequenceChecker sequence_checker_; 101 base::SequenceChecker sequence_checker_;
98 102
99 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); 103 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase);
100 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); 104 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory);
101 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); 105 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds);
102 106
103 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); 107 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase);
104 }; 108 };
105 109
106 } // namespace content 110 } // namespace content
107 111
108 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ 112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698