OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 5 #ifndef CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/supports_user_data.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
14 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
15 | 16 |
16 class WebDatabase; | 17 class WebDatabase; |
17 class WebDatabaseService; | 18 class WebDatabaseService; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class Thread; | 21 class Thread; |
21 } | 22 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 63 |
63 // Returns true if the database load has completetd successfully, and | 64 // Returns true if the database load has completetd successfully, and |
64 // ShutdownOnUIThread has not yet been called. | 65 // ShutdownOnUIThread has not yet been called. |
65 virtual bool IsDatabaseLoaded(); | 66 virtual bool IsDatabaseLoaded(); |
66 | 67 |
67 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | 68 // Returns a pointer to the DB (used by SyncableServices). May return NULL if |
68 // the database is not loaded or otherwise unavailable. Must be called on | 69 // the database is not loaded or otherwise unavailable. Must be called on |
69 // DBThread. | 70 // DBThread. |
70 virtual WebDatabase* GetDatabase(); | 71 virtual WebDatabase* GetDatabase(); |
71 | 72 |
| 73 // Returns a SupportsUserData objects that may be used to store data |
| 74 // owned by the DB thread on this object. Should be called only from |
| 75 // the DB thread, and will be destroyed on the DB thread soon after |
| 76 // |ShutdownOnUIThread()| is called. |
| 77 base::SupportsUserData* GetDBUserData(); |
| 78 |
72 protected: | 79 protected: |
73 virtual ~WebDataServiceBase(); | 80 virtual ~WebDataServiceBase(); |
| 81 virtual void ShutdownOnDBThread(); |
74 | 82 |
75 // Our database service. | 83 // Our database service. |
76 scoped_ptr<WebDatabaseService> wdbs_; | 84 scoped_ptr<WebDatabaseService> wdbs_; |
77 | 85 |
78 // True if we've received a notification that the WebDatabase has loaded. | 86 // True if we've received a notification that the WebDatabase has loaded. |
79 bool db_loaded_; | 87 bool db_loaded_; |
80 | 88 |
81 private: | 89 private: |
82 friend struct content::BrowserThread::DeleteOnThread< | 90 friend struct content::BrowserThread::DeleteOnThread< |
83 content::BrowserThread::UI>; | 91 content::BrowserThread::UI>; |
84 friend class base::DeleteHelper<WebDataServiceBase>; | 92 friend class base::DeleteHelper<WebDataServiceBase>; |
85 | 93 |
86 ProfileErrorCallback profile_error_callback_; | 94 ProfileErrorCallback profile_error_callback_; |
87 | 95 |
| 96 // Storage for user data to be accessed only on the DB thread. May |
| 97 // be used e.g. for SyncableService subclasses that need to be owned |
| 98 // by this object. Is created on first call to |GetDBUserData()|. |
| 99 scoped_ptr<base::SupportsUserData> db_thread_user_data_; |
| 100 |
88 void DBInitFailed(sql::InitStatus sql_status); | 101 void DBInitFailed(sql::InitStatus sql_status); |
89 void NotifyDatabaseLoadedOnUIThread(); | 102 void NotifyDatabaseLoadedOnUIThread(); |
90 void DatabaseInitOnDB(sql::InitStatus status); | 103 void DatabaseInitOnDB(sql::InitStatus status); |
91 }; | 104 }; |
92 | 105 |
93 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 106 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |