Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: chrome/browser/browsing_data_database_helper.h

Issue 6246105: Only invoke WebKit methods in browsing data helpers on the WEBKIT thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "webkit/database/database_tracker.h" 17 #include "webkit/database/database_tracker.h"
17 18
18 class Profile; 19 class Profile;
19 20
20 // This class fetches database information in the FILE thread, and notifies the 21 // This class fetches database information in the WEBKIT thread, and notifies
21 // UI thread upon completion. 22 // the UI thread upon completion.
22 // 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
23 // 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
24 // thread at some later point. 25 // thread at some later point.
25 // The client must call CancelNotification() if it's destroyed before the 26 // The client must call CancelNotification() if it's destroyed before the
26 // callback is notified. 27 // callback is notified.
27 class BrowsingDataDatabaseHelper 28 class BrowsingDataDatabaseHelper
28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { 29 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> {
29 public: 30 public:
30 // Contains detailed information about a web database. 31 // Contains detailed information about a web database.
31 struct DatabaseInfo { 32 struct DatabaseInfo {
(...skipping 24 matching lines...) Expand all
56 // callback. 57 // callback.
57 // This must be called only in the UI thread. 58 // This must be called only in the UI thread.
58 virtual void StartFetching( 59 virtual void StartFetching(
59 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); 60 Callback1<const std::vector<DatabaseInfo>& >::Type* callback);
60 61
61 // 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
62 // longer exists). 63 // longer exists).
63 // This must be called only in the UI thread. 64 // This must be called only in the UI thread.
64 virtual void CancelNotification(); 65 virtual void CancelNotification();
65 66
66 // Requests a single database to be deleted in the FILE thread. This must be 67 // Requests a single database to be deleted in the WEBKIT thread. This must be
67 // called in the UI thread. 68 // called in the UI thread.
68 virtual void DeleteDatabase(const std::string& origin, 69 virtual void DeleteDatabase(const std::string& origin,
69 const std::string& name); 70 const std::string& name);
70 71
71 protected: 72 protected:
72 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; 73 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>;
73 virtual ~BrowsingDataDatabaseHelper(); 74 virtual ~BrowsingDataDatabaseHelper();
74 75
75 // This only mutates in the FILE thread.
76 std::vector<DatabaseInfo> database_info_;
77
78 private:
79 // Enumerates all databases. This must be called in the FILE thread.
80 void FetchDatabaseInfoInFileThread();
81
82 // 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.
83 void NotifyInUIThread(); 77 void NotifyInUIThread();
84 78
85 // Delete a single database file. This must be called in the FILE thread. 79 // This only mutates in the WEBKIT thread.
86 void DeleteDatabaseInFileThread(const std::string& origin, 80 std::vector<DatabaseInfo> database_info_;
87 const std::string& name);
88
89 scoped_refptr<webkit_database::DatabaseTracker> tracker_;
90 81
91 // This only mutates on the UI thread. 82 // This only mutates on the UI thread.
92 scoped_ptr<Callback1<const std::vector<DatabaseInfo>& >::Type > 83 scoped_ptr<Callback1<const std::vector<DatabaseInfo>& >::Type >
93 completion_callback_; 84 completion_callback_;
94 85
95 // Indicates whether or not we're currently fetching information: 86 // Indicates whether or not we're currently fetching information:
96 // 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
97 // after we notify the callback in the UI thread. 88 // after we notify the callback in the UI thread.
98 // This only mutates on the UI thread. 89 // This only mutates on the UI thread.
99 bool is_fetching_; 90 bool is_fetching_;
100 91
92 private:
93 // Enumerates all databases. This must be called in the WEBKIT thread.
94 void FetchDatabaseInfoInWebKitThread();
95
96 // Delete a single database file. This must be called in the WEBKIT thread.
97 void DeleteDatabaseInWebKitThread(const std::string& origin,
98 const std::string& name);
99
100 scoped_refptr<webkit_database::DatabaseTracker> tracker_;
101
101 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); 102 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper);
102 }; 103 };
103 104
104 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not 105 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not
105 // 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
106 // a parameter during construction. 107 // a parameter during construction.
107 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { 108 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper {
108 public: 109 public:
109 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); 110 explicit CannedBrowsingDataDatabaseHelper(Profile* profile);
110 111
111 // Add a database to the set of canned databases that is returned by this 112 // Add a database to the set of canned databases that is returned by this
112 // helper. 113 // helper.
113 void AddDatabase(const GURL& origin, 114 void AddDatabase(const GURL& origin,
114 const std::string& name, 115 const std::string& name,
115 const std::string& description); 116 const std::string& description);
116 117
117 // Clear the list of canned databases. 118 // Clear the list of canned databases.
118 void Reset(); 119 void Reset();
119 120
120 // True if no databases are currently stored. 121 // True if no databases are currently stored.
121 bool empty() const; 122 bool empty() const;
122 123
123 // BrowsingDataDatabaseHelper methods. 124 // BrowsingDataDatabaseHelper methods.
124 virtual void StartFetching( 125 virtual void StartFetching(
125 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); 126 Callback1<const std::vector<DatabaseInfo>& >::Type* callback);
126 virtual void CancelNotification() {} 127 virtual void CancelNotification() {}
127 128
128 private: 129 private:
130 struct PendingDatabaseInfo {
131 PendingDatabaseInfo();
132 PendingDatabaseInfo(const GURL& origin,
133 const std::string& name,
134 const std::string& description);
135 ~PendingDatabaseInfo();
136
137 GURL origin;
138 std::string name;
139 std::string description;
140 };
141
129 virtual ~CannedBrowsingDataDatabaseHelper() {} 142 virtual ~CannedBrowsingDataDatabaseHelper() {}
130 143
144 // Converts the pending database info structs to database info structs.
145 void ConvertInfoInWebKitThread();
146
147 // Used to protect access to pending_database_info_.
148 mutable base::Lock lock_;
149
150 // This may mutate on WEBKIT and UI threads.
151 std::vector<PendingDatabaseInfo> pending_database_info_;
152
131 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); 153 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper);
132 }; 154 };
133 155
134 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ 156 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data_database_helper.cc » ('j') | chrome/browser/browsing_data_database_helper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698