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

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

Issue 10805015: Move browsing_data_helper files into a separate directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix chrome_frame build Created 8 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_
7
8 #include <list>
9 #include <set>
10 #include <string>
11
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/synchronization/lock.h"
16 #include "chrome/common/url_constants.h"
17 #include "googleurl/src/gurl.h"
18 #include "webkit/database/database_tracker.h"
19
20 class Profile;
21
22 // This class fetches database information in the FILE thread, and notifies
23 // the UI thread upon completion.
24 // A client of this class need to call StartFetching from the UI thread to
25 // initiate the flow, and it'll be notified by the callback in its UI
26 // thread at some later point.
27 class BrowsingDataDatabaseHelper
28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> {
29 public:
30 // Contains detailed information about a web database.
31 struct DatabaseInfo {
32 DatabaseInfo(const std::string& host,
33 const std::string& database_name,
34 const std::string& origin_identifier,
35 const std::string& description,
36 const std::string& origin,
37 int64 size,
38 base::Time last_modified);
39 ~DatabaseInfo();
40
41 std::string host;
42 std::string database_name;
43 std::string origin_identifier;
44 std::string description;
45 std::string origin;
46 int64 size;
47 base::Time last_modified;
48 };
49
50 explicit BrowsingDataDatabaseHelper(Profile* profile);
51
52 // Starts the fetching process, which will notify its completion via
53 // callback.
54 // This must be called only in the UI thread.
55 virtual void StartFetching(
56 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback);
57
58 // Requests a single database to be deleted in the FILE thread. This must be
59 // called in the UI thread.
60 virtual void DeleteDatabase(const std::string& origin,
61 const std::string& name);
62
63 protected:
64 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>;
65 virtual ~BrowsingDataDatabaseHelper();
66
67 // Notifies the completion callback. This must be called in the UI thread.
68 void NotifyInUIThread();
69
70 // Access to |database_info_| is triggered indirectly via the UI thread and
71 // guarded by |is_fetching_|. This means |database_info_| is only accessed
72 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on
73 // the UI thread.
74 // In the context of this class |database_info_| is only accessed on the FILE
75 // thread.
76 std::list<DatabaseInfo> database_info_;
77
78 // This only mutates on the UI thread.
79 base::Callback<void(const std::list<DatabaseInfo>&)> completion_callback_;
80
81 // Indicates whether or not we're currently fetching information:
82 // it's true when StartFetching() is called in the UI thread, and it's reset
83 // after we notify the callback in the UI thread.
84 // This only mutates on the UI thread.
85 bool is_fetching_;
86
87 private:
88 // Enumerates all databases. This must be called in the FILE thread.
89 void FetchDatabaseInfoOnFileThread();
90
91 // Delete a single database file. This must be called in the FILE thread.
92 void DeleteDatabaseOnFileThread(const std::string& origin,
93 const std::string& name);
94
95 scoped_refptr<webkit_database::DatabaseTracker> tracker_;
96
97 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper);
98 };
99
100 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not
101 // fetch its information from the database tracker, but gets them passed as
102 // a parameter during construction.
103 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper {
104 public:
105 struct PendingDatabaseInfo {
106 PendingDatabaseInfo(const GURL& origin,
107 const std::string& name,
108 const std::string& description);
109 ~PendingDatabaseInfo();
110
111 // The operator is needed to store |PendingDatabaseInfo| objects in a set.
112 bool operator<(const PendingDatabaseInfo& other) const;
113
114 GURL origin;
115 std::string name;
116 std::string description;
117 };
118
119 explicit CannedBrowsingDataDatabaseHelper(Profile* profile);
120
121 // Return a copy of the database helper. Only one consumer can use the
122 // StartFetching method at a time, so we need to create a copy of the helper
123 // everytime we instantiate a cookies tree model for it.
124 CannedBrowsingDataDatabaseHelper* Clone();
125
126 // Add a database to the set of canned databases that is returned by this
127 // helper.
128 void AddDatabase(const GURL& origin,
129 const std::string& name,
130 const std::string& description);
131
132 // Clear the list of canned databases.
133 void Reset();
134
135 // True if no databases are currently stored.
136 bool empty() const;
137
138 // Returns the number of currently stored databases.
139 size_t GetDatabaseCount() const;
140
141 // Returns the current list of web databases.
142 const std::set<PendingDatabaseInfo>& GetPendingDatabaseInfo();
143
144 // BrowsingDataDatabaseHelper implementation.
145 virtual void StartFetching(
146 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback)
147 OVERRIDE;
148
149 private:
150 virtual ~CannedBrowsingDataDatabaseHelper();
151
152 // Converts the pending database info structs to database info structs.
153 void ConvertInfoInWebKitThread();
154
155 // Used to protect access to pending_database_info_.
156 mutable base::Lock lock_;
157
158 // Access to |pending_database_info_| is protected by |lock_| since it may
159 // be accessed on the UI or the WEBKIT thread.
160 std::set<PendingDatabaseInfo> pending_database_info_;
161
162 Profile* profile_;
163
164 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper);
165 };
166
167 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_cookie_helper_unittest.cc ('k') | chrome/browser/browsing_data_database_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698