| 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/ref_counted_delete_on_message_loop.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/message_loop/message_loop_proxy.h" |
| 19 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 20 #include "components/webdata/common/web_data_service_base.h" | 22 #include "components/webdata/common/web_data_service_base.h" |
| 21 #include "components/webdata/common/web_database.h" | 23 #include "components/webdata/common/web_database.h" |
| 22 #include "components/webdata/common/webdata_export.h" | 24 #include "components/webdata/common/webdata_export.h" |
| 23 | 25 |
| 24 class WebDataServiceBackend; | 26 class WebDataServiceBackend; |
| 25 class WebDataRequestManager; | 27 class WebDataRequestManager; |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 class BrowserContext; | 30 class BrowserContext; |
| 29 } | 31 } |
| 30 | 32 |
| 31 namespace tracked_objects { | 33 namespace tracked_objects { |
| 32 class Location; | 34 class Location; |
| 33 } | 35 } |
| 34 | 36 |
| 35 class WDTypedResult; | 37 class WDTypedResult; |
| 36 class WebDataServiceConsumer; | 38 class WebDataServiceConsumer; |
| 37 | 39 |
| 38 | 40 |
| 39 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
| 40 // | 42 // |
| 41 // WebDatabaseService defines the interface to a generic data repository | 43 // WebDatabaseService defines the interface to a generic data repository |
| 42 // responsible for controlling access to the web database (metadata associated | 44 // responsible for controlling access to the web database (metadata associated |
| 43 // with web pages). | 45 // with web pages). |
| 44 // | 46 // |
| 45 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 46 | 48 |
| 47 class WEBDATA_EXPORT WebDatabaseService | 49 class WEBDATA_EXPORT WebDatabaseService |
| 48 : public base::RefCountedThreadSafe< | 50 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseService> { |
| 49 WebDatabaseService, | |
| 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 | 54 |
| 55 // Takes the path to the WebDatabase file. | 55 // Takes the path to the WebDatabase file. |
| 56 explicit WebDatabaseService(const base::FilePath& path); | 56 WebDatabaseService(const base::FilePath& path, |
| 57 const scoped_refptr<base::MessageLoopProxy>& ui_thread); |
| 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. | 64 // Initializes the web database service. |
| 64 virtual void LoadDatabase(); | 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // (following a database load failure), then cleared. | 106 // (following a database load failure), then cleared. |
| 106 // Note: if the database load is already complete, then the callback will NOT | 107 // Note: if the database load is already complete, then the callback will NOT |
| 107 // be stored or called. | 108 // be stored or called. |
| 108 void RegisterDBErrorCallback( | 109 void RegisterDBErrorCallback( |
| 109 const base::Callback<void(sql::InitStatus)>& callback); | 110 const base::Callback<void(sql::InitStatus)>& callback); |
| 110 | 111 |
| 111 bool db_loaded() { return db_loaded_; }; | 112 bool db_loaded() { return db_loaded_; }; |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 class BackendDelegate; | 115 class BackendDelegate; |
| 115 friend struct content::BrowserThread::DeleteOnThread< | 116 friend class BackendDelegate; |
| 116 content::BrowserThread::UI>; | 117 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseService>; |
| 117 friend class base::DeleteHelper<WebDatabaseService>; | 118 friend class base::DeleteHelper<WebDatabaseService>; |
| 118 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). | |
| 119 friend class base::RefCountedThreadSafe<WebDatabaseService, | |
| 120 content::BrowserThread::DeleteOnUIThread>; | |
| 121 friend class BackendDelegate; | |
| 122 | 119 |
| 123 virtual ~WebDatabaseService(); | 120 virtual ~WebDatabaseService(); |
| 124 | 121 |
| 125 void OnDatabaseLoadDone(sql::InitStatus status); | 122 void OnDatabaseLoadDone(sql::InitStatus status); |
| 126 | 123 |
| 127 base::FilePath path_; | 124 base::FilePath path_; |
| 128 | 125 |
| 129 // The primary owner is |WebDatabaseService| but is refcounted because | 126 // The primary owner is |WebDatabaseService| but is refcounted because |
| 130 // PostTask on DB thread may outlive us. | 127 // PostTask on DB thread may outlive us. |
| 131 scoped_refptr<WebDataServiceBackend> wds_backend_; | 128 scoped_refptr<WebDataServiceBackend> wds_backend_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 LoadedCallbacks loaded_callbacks_; | 141 LoadedCallbacks loaded_callbacks_; |
| 145 | 142 |
| 146 // Callbacks to be called if the DB has failed to load. | 143 // Callbacks to be called if the DB has failed to load. |
| 147 ErrorCallbacks error_callbacks_; | 144 ErrorCallbacks error_callbacks_; |
| 148 | 145 |
| 149 // True if the WebDatabase has loaded. | 146 // True if the WebDatabase has loaded. |
| 150 bool db_loaded_; | 147 bool db_loaded_; |
| 151 }; | 148 }; |
| 152 | 149 |
| 153 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 150 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
| OLD | NEW |