| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSING_DATA_DATABASE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "webkit/database/database_tracker.h" | 17 #include "webkit/database/database_tracker.h" |
| 18 | 18 |
| 19 class Profile; | 19 class Profile; |
| 20 | 20 |
| 21 // This class fetches database information in the WEBKIT thread, and notifies | 21 // This class fetches database information in the FILE thread, and notifies |
| 22 // the UI thread upon completion. | 22 // the UI thread upon completion. |
| 23 // A client of this class need to call StartFetching from the UI thread to | 23 // A client of this class need to call StartFetching from the UI thread to |
| 24 // initiate the flow, and it'll be notified by the callback in its UI | 24 // initiate the flow, and it'll be notified by the callback in its UI |
| 25 // thread at some later point. | 25 // thread at some later point. |
| 26 // The client must call CancelNotification() if it's destroyed before the | 26 // The client must call CancelNotification() if it's destroyed before the |
| 27 // callback is notified. | 27 // callback is notified. |
| 28 class BrowsingDataDatabaseHelper | 28 class BrowsingDataDatabaseHelper |
| 29 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { | 29 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { |
| 30 public: | 30 public: |
| 31 // Contains detailed information about a web database. | 31 // Contains detailed information about a web database. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 // callback. | 57 // callback. |
| 58 // This must be called only in the UI thread. | 58 // This must be called only in the UI thread. |
| 59 virtual void StartFetching( | 59 virtual void StartFetching( |
| 60 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); | 60 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); |
| 61 | 61 |
| 62 // Cancels the notification callback (i.e., the window that created it no | 62 // Cancels the notification callback (i.e., the window that created it no |
| 63 // longer exists). | 63 // longer exists). |
| 64 // This must be called only in the UI thread. | 64 // This must be called only in the UI thread. |
| 65 virtual void CancelNotification(); | 65 virtual void CancelNotification(); |
| 66 | 66 |
| 67 // Requests a single database to be deleted in the WEBKIT thread. This must be | 67 // Requests a single database to be deleted in the FILE thread. This must be |
| 68 // called in the UI thread. | 68 // called in the UI thread. |
| 69 virtual void DeleteDatabase(const std::string& origin, | 69 virtual void DeleteDatabase(const std::string& origin, |
| 70 const std::string& name); | 70 const std::string& name); |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; | 73 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; |
| 74 virtual ~BrowsingDataDatabaseHelper(); | 74 virtual ~BrowsingDataDatabaseHelper(); |
| 75 | 75 |
| 76 // Notifies the completion callback. This must be called in the UI thread. | 76 // Notifies the completion callback. This must be called in the UI thread. |
| 77 void NotifyInUIThread(); | 77 void NotifyInUIThread(); |
| 78 | 78 |
| 79 // This only mutates in the WEBKIT thread. | 79 // This only mutates in the FILE thread. |
| 80 std::vector<DatabaseInfo> database_info_; | 80 std::vector<DatabaseInfo> database_info_; |
| 81 | 81 |
| 82 // This only mutates on the UI thread. | 82 // This only mutates on the UI thread. |
| 83 scoped_ptr<Callback1<const std::vector<DatabaseInfo>& >::Type > | 83 scoped_ptr<Callback1<const std::vector<DatabaseInfo>& >::Type > |
| 84 completion_callback_; | 84 completion_callback_; |
| 85 | 85 |
| 86 // Indicates whether or not we're currently fetching information: | 86 // Indicates whether or not we're currently fetching information: |
| 87 // it's true when StartFetching() is called in the UI thread, and it's reset | 87 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 88 // after we notify the callback in the UI thread. | 88 // after we notify the callback in the UI thread. |
| 89 // This only mutates on the UI thread. | 89 // This only mutates on the UI thread. |
| 90 bool is_fetching_; | 90 bool is_fetching_; |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 // Enumerates all databases. This must be called in the WEBKIT thread. | 93 // Enumerates all databases. This must be called in the FILE thread. |
| 94 void FetchDatabaseInfoInWebKitThread(); | 94 void FetchDatabaseInfoOnFileThread(); |
| 95 | 95 |
| 96 // Delete a single database file. This must be called in the WEBKIT thread. | 96 // Delete a single database file. This must be called in the FILE thread. |
| 97 void DeleteDatabaseInWebKitThread(const std::string& origin, | 97 void DeleteDatabaseOnFileThread(const std::string& origin, |
| 98 const std::string& name); | 98 const std::string& name); |
| 99 | 99 |
| 100 scoped_refptr<webkit_database::DatabaseTracker> tracker_; | 100 scoped_refptr<webkit_database::DatabaseTracker> tracker_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); | 102 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not | 105 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not |
| 106 // fetch its information from the database tracker, but gets them passed as | 106 // fetch its information from the database tracker, but gets them passed as |
| 107 // a parameter during construction. | 107 // a parameter during construction. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // This may mutate on WEBKIT and UI threads. | 155 // This may mutate on WEBKIT and UI threads. |
| 156 std::vector<PendingDatabaseInfo> pending_database_info_; | 156 std::vector<PendingDatabaseInfo> pending_database_info_; |
| 157 | 157 |
| 158 Profile* profile_; | 158 Profile* profile_; |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); | 160 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 163 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| OLD | NEW |