OLD | NEW |
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 // Chromium settings and storage represent user-selected preferences and | 5 // Chromium settings and storage represent user-selected preferences and |
6 // information and MUST not be extracted, overwritten or modified except | 6 // information and MUST not be extracted, overwritten or modified except |
7 // through Chromium defined APIs. | 7 // through Chromium defined APIs. |
8 | 8 |
9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // | 44 // |
45 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
46 | 46 |
47 class WEBDATA_EXPORT WebDatabaseService | 47 class WEBDATA_EXPORT WebDatabaseService |
48 : public base::RefCountedThreadSafe< | 48 : public base::RefCountedThreadSafe< |
49 WebDatabaseService, | 49 WebDatabaseService, |
50 content::BrowserThread::DeleteOnUIThread> { | 50 content::BrowserThread::DeleteOnUIThread> { |
51 public: | 51 public: |
52 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; | 52 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; |
53 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; | 53 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; |
| 54 typedef base::Callback<void(base::WeakPtr<WebDatabase>)> DBCallback; |
54 | 55 |
55 // Takes the path to the WebDatabase file. | 56 // Takes the path to the WebDatabase file. |
56 explicit WebDatabaseService(const base::FilePath& path); | 57 explicit WebDatabaseService(const base::FilePath& path); |
57 | 58 |
58 // Adds |table| as a WebDatabaseTable that will participate in | 59 // Adds |table| as a WebDatabaseTable that will participate in |
59 // managing the database, transferring ownership. All calls to this | 60 // managing the database, transferring ownership. All calls to this |
60 // method must be made before |LoadDatabase| is called. | 61 // method must be made before |LoadDatabase| is called. |
61 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); | 62 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); |
62 | 63 |
63 // Initializes the web database service. Takes a callback which will return | 64 // Initializes the web database service. Takes a callback which will return |
64 // the status of the DB after the init. | 65 // the status of the DB after the init. |
65 virtual void LoadDatabase(); | 66 virtual void LoadDatabase(); |
66 | 67 |
67 // Unloads the database without actually shutting down the service. This can | 68 // Unloads the database without actually shutting down the service. This can |
68 // be used to temporarily reduce the browser process' memory footprint. | 69 // be used to temporarily reduce the browser process' memory footprint. |
69 virtual void UnloadDatabase(); | 70 virtual void UnloadDatabase(); |
70 | 71 |
71 // Unloads database and will not reload. | 72 // Unloads database and will not reload. |
72 virtual void ShutdownDatabase(); | 73 virtual void ShutdownDatabase(); |
73 | 74 |
74 // Gets a ptr to the WebDatabase (owned by WebDatabaseService). | 75 // Asynchronously gets an instance of |WebDatabase|, which can be |
75 // TODO(caitkp): remove this method once SyncServices no longer depend on it. | 76 // used to do work on the DB thread. This method is meant to be called from |
76 virtual WebDatabase* GetDatabaseOnDB() const; | 77 // the UI thread, but the callback will be called on the DB thread. |
| 78 void GetDatabaseOnDB(const DBCallback& callback); |
77 | 79 |
78 // Schedule an update/write task on the DB thread. | 80 // Schedule an update/write task on the DB thread. |
79 virtual void ScheduleDBTask( | 81 virtual void ScheduleDBTask( |
80 const tracked_objects::Location& from_here, | 82 const tracked_objects::Location& from_here, |
81 const WriteTask& task); | 83 const WriteTask& task); |
82 | 84 |
83 // Schedule a read task on the DB thread. | 85 // Schedule a read task on the DB thread. |
84 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult( | 86 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult( |
85 const tracked_objects::Location& from_here, | 87 const tracked_objects::Location& from_here, |
86 const ReadTask& task, | 88 const ReadTask& task, |
(...skipping 27 matching lines...) Expand all Loading... |
114 // PostTask on DB thread may outlive us. | 116 // PostTask on DB thread may outlive us. |
115 scoped_refptr<WebDataServiceBackend> wds_backend_; | 117 scoped_refptr<WebDataServiceBackend> wds_backend_; |
116 | 118 |
117 ObserverList<WebDatabaseObserver> observer_list_; | 119 ObserverList<WebDatabaseObserver> observer_list_; |
118 | 120 |
119 // All vended weak pointers are invalidated in ShutdownDatabase(). | 121 // All vended weak pointers are invalidated in ShutdownDatabase(). |
120 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; | 122 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; |
121 }; | 123 }; |
122 | 124 |
123 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 125 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
OLD | NEW |