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

Side by Side Diff: content/browser/dom_storage/session_storage_database.h

Issue 1310513004: [tracing] Add memory statistics from level db clients to tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@skia_res
Patch Set: Rebase. Created 5 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_
6 #define CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ 6 #define CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/trace_event/memory_dump_provider.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 #include "content/common/dom_storage/dom_storage_types.h" 17 #include "content/common/dom_storage/dom_storage_types.h"
17 #include "third_party/leveldatabase/src/include/leveldb/status.h" 18 #include "third_party/leveldatabase/src/include/leveldb/status.h"
18 19
19 class GURL; 20 class GURL;
20 21
21 namespace leveldb { 22 namespace leveldb {
22 class DB; 23 class DB;
23 struct ReadOptions; 24 struct ReadOptions;
24 class WriteBatch; 25 class WriteBatch;
25 } // namespace leveldb 26 } // namespace leveldb
26 27
27 namespace content { 28 namespace content {
28 29
29 // SessionStorageDatabase holds the data from multiple namespaces and multiple 30 // SessionStorageDatabase holds the data from multiple namespaces and multiple
30 // origins. All DOMStorageAreas for session storage share the same 31 // origins. All DOMStorageAreas for session storage share the same
31 // SessionStorageDatabase. 32 // SessionStorageDatabase.
32 33
33 // Only one thread is allowed to call the public functions other than 34 // Only one thread is allowed to call the public functions other than
34 // ReadAreaValues and ReadNamespacesAndOrigins. Other threads are allowed to 35 // ReadAreaValues and ReadNamespacesAndOrigins. Other threads are allowed to
35 // call ReadAreaValues and ReadNamespacesAndOrigins. 36 // call ReadAreaValues and ReadNamespacesAndOrigins.
36 class CONTENT_EXPORT SessionStorageDatabase : 37 class CONTENT_EXPORT SessionStorageDatabase
37 public base::RefCountedThreadSafe<SessionStorageDatabase> { 38 : public base::RefCountedThreadSafe<SessionStorageDatabase>,
39 public base::trace_event::MemoryDumpProvider {
38 public: 40 public:
39 explicit SessionStorageDatabase(const base::FilePath& file_path); 41 explicit SessionStorageDatabase(const base::FilePath& file_path);
40 42
41 // Reads the (key, value) pairs for |namespace_id| and |origin|. |result| is 43 // Reads the (key, value) pairs for |namespace_id| and |origin|. |result| is
42 // assumed to be empty and any duplicate keys will be overwritten. If the 44 // assumed to be empty and any duplicate keys will be overwritten. If the
43 // database exists on disk then it will be opened. If it does not exist then 45 // database exists on disk then it will be opened. If it does not exist then
44 // it will not be created and |result| will be unmodified. 46 // it will not be created and |result| will be unmodified.
45 void ReadAreaValues(const std::string& namespace_id, 47 void ReadAreaValues(const std::string& namespace_id,
46 const GURL& origin, 48 const GURL& origin,
47 DOMStorageValuesMap* result); 49 DOMStorageValuesMap* result);
(...skipping 17 matching lines...) Expand all
65 // Deletes the data for |namespace_id| and |origin|. 67 // Deletes the data for |namespace_id| and |origin|.
66 bool DeleteArea(const std::string& namespace_id, const GURL& origin); 68 bool DeleteArea(const std::string& namespace_id, const GURL& origin);
67 69
68 // Deletes the data for |namespace_id|. 70 // Deletes the data for |namespace_id|.
69 bool DeleteNamespace(const std::string& namespace_id); 71 bool DeleteNamespace(const std::string& namespace_id);
70 72
71 // Reads the namespace IDs and origins present in the database. 73 // Reads the namespace IDs and origins present in the database.
72 bool ReadNamespacesAndOrigins( 74 bool ReadNamespacesAndOrigins(
73 std::map<std::string, std::vector<GURL> >* namespaces_and_origins); 75 std::map<std::string, std::vector<GURL> >* namespaces_and_origins);
74 76
77 // base::trace_event::MemoryDumpProvider implementation.
78 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
79 base::trace_event::ProcessMemoryDump* pmd) override;
80
75 private: 81 private:
76 friend class base::RefCountedThreadSafe<SessionStorageDatabase>; 82 friend class base::RefCountedThreadSafe<SessionStorageDatabase>;
77 class DBOperation; 83 class DBOperation;
78 friend class SessionStorageDatabase::DBOperation; 84 friend class SessionStorageDatabase::DBOperation;
79 friend class SessionStorageDatabaseTest; 85 friend class SessionStorageDatabaseTest;
80 86
81 ~SessionStorageDatabase(); 87 ~SessionStorageDatabase() override;
82 88
83 // Opens the database at file_path_ if it exists already and creates it if 89 // Opens the database at file_path_ if it exists already and creates it if
84 // |create_if_needed| is true. Returns true if the database was opened, false 90 // |create_if_needed| is true. Returns true if the database was opened, false
85 // if the opening failed or was not necessary (the database doesn't exist and 91 // if the opening failed or was not necessary (the database doesn't exist and
86 // |create_if_needed| is false). The possible failures are: 92 // |create_if_needed| is false). The possible failures are:
87 // - leveldb cannot open the database. 93 // - leveldb cannot open the database.
88 // - The database is in an inconsistent or errored state. 94 // - The database is in an inconsistent or errored state.
89 bool LazyOpen(bool create_if_needed); 95 bool LazyOpen(bool create_if_needed);
90 96
91 // Tries to open the database at file_path_, assigns |db| to point to the 97 // Tries to open the database at file_path_, assigns |db| to point to the
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // The number of database operations in progress. We need this so that we can 211 // The number of database operations in progress. We need this so that we can
206 // delete an inconsistent database at the right moment. 212 // delete an inconsistent database at the right moment.
207 int operation_count_; 213 int operation_count_;
208 214
209 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabase); 215 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabase);
210 }; 216 };
211 217
212 } // namespace content 218 } // namespace content
213 219
214 #endif // CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_ 220 #endif // CONTENT_BROWSER_DOM_STORAGE_SESSION_STORAGE_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698