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

Side by Side Diff: components/webdata/common/web_database_backend.h

Issue 962903003: Rename WebDataServiceBackend to WebDatabaseBackend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback_forward.h" 9 #include "base/callback_forward.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
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/ref_counted_delete_on_message_loop.h" 13 #include "base/memory/ref_counted_delete_on_message_loop.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "components/webdata/common/web_database_service.h" 16 #include "components/webdata/common/web_database_service.h"
17 #include "components/webdata/common/webdata_export.h" 17 #include "components/webdata/common/webdata_export.h"
18 18
19 class WebDatabase; 19 class WebDatabase;
20 class WebDatabaseTable; 20 class WebDatabaseTable;
21 class WebDataRequest; 21 class WebDataRequest;
22 class WebDataRequestManager; 22 class WebDataRequestManager;
23 23
24 namespace tracked_objects { 24 namespace tracked_objects {
25 class Location; 25 class Location;
26 } 26 }
27 27
28 // WebDataServiceBackend handles all database tasks posted by 28 // WebDatabaseBackend handles all database tasks posted by
29 // WebDatabaseService. It is refcounted to allow asynchronous destruction on the 29 // WebDatabaseService. It is refcounted to allow asynchronous destruction on the
30 // DB thread. 30 // DB thread.
31 31
32 // TODO(caitkp): Rename this class to WebDatabaseBackend. 32 // TODO(caitkp): Rename this class to WebDatabaseBackend.
Cait (Slow) 2015/03/11 14:49:27 This TODO can be removed now :)
zhuoyu.qian 2015/03/12 01:50:09 Done.
33 33
34 class WEBDATA_EXPORT WebDataServiceBackend 34 class WEBDATA_EXPORT WebDatabaseBackend
35 : public base::RefCountedDeleteOnMessageLoop<WebDataServiceBackend> { 35 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend> {
36 public: 36 public:
37 class Delegate { 37 class Delegate {
38 public: 38 public:
39 virtual ~Delegate() {} 39 virtual ~Delegate() {}
40 40
41 // Invoked when the backend has finished loading the db. 41 // Invoked when the backend has finished loading the db.
42 virtual void DBLoaded(sql::InitStatus status) = 0; 42 virtual void DBLoaded(sql::InitStatus status) = 0;
43 }; 43 };
44 44
45 WebDataServiceBackend(const base::FilePath& path, 45 WebDatabaseBackend(const base::FilePath& path,
46 Delegate* delegate, 46 Delegate* delegate,
47 const scoped_refptr<base::MessageLoopProxy>& db_thread); 47 const scoped_refptr<base::MessageLoopProxy>& db_thread);
48 48
49 // Must call only before InitDatabaseWithCallback. 49 // Must call only before InitDatabaseWithCallback.
50 void AddTable(scoped_ptr<WebDatabaseTable> table); 50 void AddTable(scoped_ptr<WebDatabaseTable> table);
51 51
52 // Initializes the database and notifies caller via callback when complete. 52 // Initializes the database and notifies caller via callback when complete.
53 // Callback is called synchronously. 53 // Callback is called synchronously.
54 void InitDatabase(); 54 void InitDatabase();
55 55
56 // Opens the database file from the profile path if an init has not yet been 56 // Opens the database file from the profile path if an init has not yet been
57 // attempted. Separated from the constructor to ease construction/destruction 57 // attempted. Separated from the constructor to ease construction/destruction
58 // of this object on one thread but database access on the DB thread. Returns 58 // of this object on one thread but database access on the DB thread. Returns
59 // the status of the database. 59 // the status of the database.
60 sql::InitStatus LoadDatabaseIfNecessary(); 60 sql::InitStatus LoadDatabaseIfNecessary();
61 61
62 // Shuts down the database. 62 // Shuts down the database.
63 void ShutdownDatabase(); 63 void ShutdownDatabase();
64 64
65 // Task wrappers to update requests and and notify |request_manager_|. These 65 // Task wrappers to update requests and and notify |request_manager_|. These
66 // are used in cases where the request is being made from the UI thread and an 66 // are used in cases where the request is being made from the UI thread and an
67 // asyncronous callback is required to notify the client of |request|'s 67 // asyncronous callback is required to notify the client of |request|'s
68 // completion. 68 // completion.
69 void DBWriteTaskWrapper( 69 void DBWriteTaskWrapper(const WebDatabaseService::WriteTask& task,
70 const WebDatabaseService::WriteTask& task, 70 scoped_ptr<WebDataRequest> request);
71 scoped_ptr<WebDataRequest> request); 71 void DBReadTaskWrapper(const WebDatabaseService::ReadTask& task,
72 void DBReadTaskWrapper( 72 scoped_ptr<WebDataRequest> request);
73 const WebDatabaseService::ReadTask& task,
74 scoped_ptr<WebDataRequest> request);
75 73
76 // Task runners to run database tasks. 74 // Task runners to run database tasks.
77 void ExecuteWriteTask(const WebDatabaseService::WriteTask& task); 75 void ExecuteWriteTask(const WebDatabaseService::WriteTask& task);
78 scoped_ptr<WDTypedResult> ExecuteReadTask( 76 scoped_ptr<WDTypedResult> ExecuteReadTask(
79 const WebDatabaseService::ReadTask& task); 77 const WebDatabaseService::ReadTask& task);
80 78
81 const scoped_refptr<WebDataRequestManager>& request_manager() { 79 const scoped_refptr<WebDataRequestManager>& request_manager() {
82 return request_manager_; 80 return request_manager_;
83 } 81 }
84 82
85 WebDatabase* database() { return db_.get(); } 83 WebDatabase* database() { return db_.get(); }
86 84
87 protected: 85 protected:
88 friend class base::RefCountedDeleteOnMessageLoop<WebDataServiceBackend>; 86 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>;
89 friend class base::DeleteHelper<WebDataServiceBackend>; 87 friend class base::DeleteHelper<WebDatabaseBackend>;
90 88
91 virtual ~WebDataServiceBackend(); 89 virtual ~WebDatabaseBackend();
92 90
93 private: 91 private:
94 // Commit the current transaction. 92 // Commit the current transaction.
95 void Commit(); 93 void Commit();
96 94
97 // Path to database file. 95 // Path to database file.
98 base::FilePath db_path_; 96 base::FilePath db_path_;
99 97
100 // The tables that participate in managing the database. These are 98 // The tables that participate in managing the database. These are
101 // owned here but other than that this class does nothing with 99 // owned here but other than that this class does nothing with
(...skipping 14 matching lines...) Expand all
116 // before the db is ready. 114 // before the db is ready.
117 sql::InitStatus init_status_; 115 sql::InitStatus init_status_;
118 116
119 // True if an attempt has been made to load the database (even if the attempt 117 // True if an attempt has been made to load the database (even if the attempt
120 // fails), used to avoid continually trying to reinit if the db init fails. 118 // fails), used to avoid continually trying to reinit if the db init fails.
121 bool init_complete_; 119 bool init_complete_;
122 120
123 // Delegate. See the class definition above for more information. 121 // Delegate. See the class definition above for more information.
124 scoped_ptr<Delegate> delegate_; 122 scoped_ptr<Delegate> delegate_;
125 123
126 DISALLOW_COPY_AND_ASSIGN(WebDataServiceBackend); 124 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend);
127 }; 125 };
128 126
129 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ 127 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698