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

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

Issue 303483007: ServiceWorker: Add UMA for ServiceWorkerDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revamp (separate read/write operation results) Created 6 years, 6 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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/sequence_checker.h" 16 #include "base/sequence_checker.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/service_worker/service_worker_status_code.h" 19 #include "content/common/service_worker/service_worker_status_code.h"
20 #include "url/gurl.h" 20 #include "url/gurl.h"
21 21
22 namespace leveldb { 22 namespace leveldb {
23 class DB; 23 class DB;
24 class Env; 24 class Env;
25 class Status;
26 class WriteBatch; 25 class WriteBatch;
27 } 26 }
28 27
29 namespace content { 28 namespace content {
30 29
31 // Class to persist serviceworker registration data in a database. 30 // Class to persist serviceworker registration data in a database.
32 // Should NOT be used on the IO thread since this does blocking 31 // Should NOT be used on the IO thread since this does blocking
33 // file io. The ServiceWorkerStorage class owns this class and 32 // file io. The ServiceWorkerStorage class owns this class and
34 // is responsible for only calling it serially on background 33 // is responsible for only calling it serially on background
35 // non-IO threads (ala SequencedWorkerPool). 34 // non-IO threads (ala SequencedWorkerPool).
36 class CONTENT_EXPORT ServiceWorkerDatabase { 35 class CONTENT_EXPORT ServiceWorkerDatabase {
37 public: 36 public:
38 // We do leveldb stuff in |path| or in memory if |path| is empty. 37 // We do leveldb stuff in |path| or in memory if |path| is empty.
39 explicit ServiceWorkerDatabase(const base::FilePath& path); 38 explicit ServiceWorkerDatabase(const base::FilePath& path);
40 ~ServiceWorkerDatabase(); 39 ~ServiceWorkerDatabase();
41 40
41 // Used in UMA. A new value must be appended only.
42 enum Status { 42 enum Status {
43 STATUS_OK, 43 STATUS_OK,
44 STATUS_ERROR_NOT_FOUND, 44 STATUS_ERROR_NOT_FOUND,
45 STATUS_ERROR_IO_ERROR,
45 STATUS_ERROR_CORRUPTED, 46 STATUS_ERROR_CORRUPTED,
46 STATUS_ERROR_FAILED, 47 STATUS_ERROR_FAILED,
48 STATUS_ERROR_MAX,
47 }; 49 };
48 50
49 struct CONTENT_EXPORT RegistrationData { 51 struct CONTENT_EXPORT RegistrationData {
50 // These values are immutable for the life of a registration. 52 // These values are immutable for the life of a registration.
51 int64 registration_id; 53 int64 registration_id;
52 GURL scope; 54 GURL scope;
53 GURL script; 55 GURL script;
54 56
55 // Versions are first stored once they successfully install and become 57 // Versions are first stored once they successfully install and become
56 // the waiting version. Then transition to the active version. The stored 58 // the waiting version. Then transition to the active version. The stored
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Bumps the next available id if |used_id| is greater than or equal to the 267 // Bumps the next available id if |used_id| is greater than or equal to the
266 // cached one. 268 // cached one.
267 void BumpNextRegistrationIdIfNeeded( 269 void BumpNextRegistrationIdIfNeeded(
268 int64 used_id, 270 int64 used_id,
269 leveldb::WriteBatch* batch); 271 leveldb::WriteBatch* batch);
270 void BumpNextVersionIdIfNeeded( 272 void BumpNextVersionIdIfNeeded(
271 int64 used_id, 273 int64 used_id,
272 leveldb::WriteBatch* batch); 274 leveldb::WriteBatch* batch);
273 275
274 bool IsOpen(); 276 bool IsOpen();
275 277 void Disable();
276 void HandleError(
277 const tracked_objects::Location& from_here,
278 const leveldb::Status& status);
279 278
280 base::FilePath path_; 279 base::FilePath path_;
281 scoped_ptr<leveldb::Env> env_; 280 scoped_ptr<leveldb::Env> env_;
282 scoped_ptr<leveldb::DB> db_; 281 scoped_ptr<leveldb::DB> db_;
283 282
284 int64 next_avail_registration_id_; 283 int64 next_avail_registration_id_;
285 int64 next_avail_resource_id_; 284 int64 next_avail_resource_id_;
286 int64 next_avail_version_id_; 285 int64 next_avail_version_id_;
287 286
288 enum State { 287 enum State {
289 UNINITIALIZED, 288 UNINITIALIZED,
290 INITIALIZED, 289 INITIALIZED,
291 DISABLED, 290 DISABLED,
292 }; 291 };
293 State state_; 292 State state_;
294 293
295 base::SequenceChecker sequence_checker_; 294 base::SequenceChecker sequence_checker_;
296 295
297 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); 296 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase);
298 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); 297 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory);
299 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); 298 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion);
300 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); 299 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds);
301 300
302 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); 301 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase);
303 }; 302 };
304 303
305 } // namespace content 304 } // namespace content
306 305
307 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ 306 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698