Chromium Code Reviews| 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_ |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | |
| 19 #include "base/observer_list.h" | |
| 18 #include "components/webdata/common/web_data_service_base.h" | 20 #include "components/webdata/common/web_data_service_base.h" |
| 19 #include "components/webdata/common/web_database.h" | 21 #include "components/webdata/common/web_database.h" |
| 20 #include "components/webdata/common/webdata_export.h" | 22 #include "components/webdata/common/webdata_export.h" |
| 21 | 23 |
| 22 class WebDataServiceBackend; | 24 class WebDataServiceBackend; |
| 23 class WebDataRequestManager; | 25 class WebDataRequestManager; |
| 24 | 26 |
| 25 namespace content { | 27 namespace content { |
| 26 class BrowserContext; | 28 class BrowserContext; |
| 27 } | 29 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 42 // | 44 // |
| 43 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
| 44 | 46 |
| 45 class WEBDATA_EXPORT WebDatabaseService | 47 class WEBDATA_EXPORT WebDatabaseService |
| 46 : public base::RefCountedThreadSafe< | 48 : public base::RefCountedThreadSafe< |
| 47 WebDatabaseService, | 49 WebDatabaseService, |
| 48 content::BrowserThread::DeleteOnUIThread> { | 50 content::BrowserThread::DeleteOnUIThread> { |
| 49 public: | 51 public: |
| 50 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; | 52 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; |
| 51 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; | 53 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; |
| 52 typedef base::Callback<void(sql::InitStatus)> InitCallback; | |
| 53 | 54 |
| 54 // Takes the path to the WebDatabase file. | 55 // Takes the path to the WebDatabase file. |
| 55 explicit WebDatabaseService(const base::FilePath& path); | 56 explicit WebDatabaseService(const base::FilePath& path); |
| 56 | 57 |
| 57 // Adds |table| as a WebDatabaseTable that will participate in | 58 // Adds |table| as a WebDatabaseTable that will participate in |
| 58 // managing the database, transferring ownership. All calls to this | 59 // managing the database, transferring ownership. All calls to this |
| 59 // method must be made before |LoadDatabase| is called. | 60 // method must be made before |LoadDatabase| is called. |
| 60 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); | 61 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); |
| 61 | 62 |
| 62 // Initializes the web database service. Takes a callback which will return | 63 // Initializes the web database service. Takes a callback which will return |
| 63 // the status of the DB after the init. | 64 // the status of the DB after the init. |
| 64 virtual void LoadDatabase(const InitCallback& callback); | 65 virtual void LoadDatabase(); |
| 65 | 66 |
| 66 // Unloads the database without actually shutting down the service. This can | 67 // Unloads the database without actually shutting down the service. This can |
| 67 // be used to temporarily reduce the browser process' memory footprint. | 68 // be used to temporarily reduce the browser process' memory footprint. |
| 68 virtual void UnloadDatabase(); | 69 virtual void UnloadDatabase(); |
| 69 | 70 |
| 70 // Unloads database and will not reload. | 71 // Unloads database and will not reload. |
| 71 virtual void ShutdownDatabase(); | 72 virtual void ShutdownDatabase(); |
| 72 | 73 |
| 73 // Gets a ptr to the WebDatabase (owned by WebDatabaseService). | 74 // Gets a ptr to the WebDatabase (owned by WebDatabaseService). |
| 74 // TODO(caitkp): remove this method once SyncServices no longer depend on it. | 75 // TODO(caitkp): remove this method once SyncServices no longer depend on it. |
| 75 virtual WebDatabase* GetDatabaseOnDB() const; | 76 virtual WebDatabase* GetDatabaseOnDB() const; |
| 76 | 77 |
| 77 // Schedule an update/write task on the DB thread. | 78 // Schedule an update/write task on the DB thread. |
| 78 virtual void ScheduleDBTask( | 79 virtual void ScheduleDBTask( |
| 79 const tracked_objects::Location& from_here, | 80 const tracked_objects::Location& from_here, |
| 80 const WriteTask& task); | 81 const WriteTask& task); |
| 81 | 82 |
| 82 // Schedule a read task on the DB thread. | 83 // Schedule a read task on the DB thread. |
| 83 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult( | 84 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult( |
| 84 const tracked_objects::Location& from_here, | 85 const tracked_objects::Location& from_here, |
| 85 const ReadTask& task, | 86 const ReadTask& task, |
| 86 WebDataServiceConsumer* consumer); | 87 WebDataServiceConsumer* consumer); |
| 87 | 88 |
| 88 // Cancel an existing request for a task on the DB thread. | 89 // Cancel an existing request for a task on the DB thread. |
| 89 // TODO(caitkp): Think about moving the definition of the Handle type to | 90 // TODO(caitkp): Think about moving the definition of the Handle type to |
| 90 // somewhere else. | 91 // somewhere else. |
| 91 virtual void CancelRequest(WebDataServiceBase::Handle h); | 92 virtual void CancelRequest(WebDataServiceBase::Handle h); |
| 92 | 93 |
| 94 void AddObserver(WebDatabaseObserver* observer); | |
| 95 void RemoveObserver(WebDatabaseObserver* observer); | |
| 96 | |
| 93 private: | 97 private: |
| 98 class BackendDelegate; | |
| 94 friend struct content::BrowserThread::DeleteOnThread< | 99 friend struct content::BrowserThread::DeleteOnThread< |
| 95 content::BrowserThread::UI>; | 100 content::BrowserThread::UI>; |
| 96 friend class base::DeleteHelper<WebDatabaseService>; | 101 friend class base::DeleteHelper<WebDatabaseService>; |
| 97 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). | 102 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). |
| 98 friend class base::RefCountedThreadSafe<WebDatabaseService, | 103 friend class base::RefCountedThreadSafe<WebDatabaseService, |
| 99 content::BrowserThread::DeleteOnUIThread>; | 104 content::BrowserThread::DeleteOnUIThread>; |
| 105 friend class BackendDelegate; | |
| 100 | 106 |
| 101 virtual ~WebDatabaseService(); | 107 virtual ~WebDatabaseService(); |
| 102 | 108 |
| 109 void OnDatabaseLoadDone(sql::InitStatus status); | |
| 110 | |
| 103 base::FilePath path_; | 111 base::FilePath path_; |
| 104 | 112 |
| 105 // The primary owner is |WebDatabaseService| but is refcounted because | 113 // The primary owner is |WebDatabaseService| but is refcounted because |
| 106 // PostTask on DB thread may outlive us. | 114 // PostTask on DB thread may outlive us. |
| 107 scoped_refptr<WebDataServiceBackend> wds_backend_; | 115 scoped_refptr<WebDataServiceBackend> wds_backend_; |
| 116 | |
| 117 ObserverList<WebDatabaseObserver> observer_list_; | |
| 118 | |
| 119 // All vended weak pointers are invalidated in Cleanup(). | |
|
Jói
2013/04/17 10:52:04
Cleanup -> ShutdownDatabase
Cait (Slow)
2013/04/18 15:07:48
Done.
| |
| 120 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; | |
| 108 }; | 121 }; |
| 109 | 122 |
| 110 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 123 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
| OLD | NEW |