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_LOCAL_STORAGE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback_old.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" |
14 #include "base/file_path.h" | 15 #include "base/file_path.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 | 21 |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 // This class fetches local storage information in the WebKit thread, and | 24 // This class fetches local storage information in the WebKit thread, and |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 int64 size; | 58 int64 size; |
58 base::Time last_modified; | 59 base::Time last_modified; |
59 }; | 60 }; |
60 | 61 |
61 explicit BrowsingDataLocalStorageHelper(Profile* profile); | 62 explicit BrowsingDataLocalStorageHelper(Profile* profile); |
62 | 63 |
63 // Starts the fetching process, which will notify its completion via | 64 // Starts the fetching process, which will notify its completion via |
64 // callback. | 65 // callback. |
65 // This must be called only in the UI thread. | 66 // This must be called only in the UI thread. |
66 virtual void StartFetching( | 67 virtual void StartFetching( |
67 Callback1<const std::list<LocalStorageInfo>& >::Type* callback); | 68 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback); |
68 // Cancels the notification callback (i.e., the window that created it no | 69 // Cancels the notification callback (i.e., the window that created it no |
69 // longer exists). | 70 // longer exists). |
70 // This must be called only in the UI thread. | 71 // This must be called only in the UI thread. |
71 virtual void CancelNotification(); | 72 virtual void CancelNotification(); |
72 // Requests a single local storage file to be deleted in the WEBKIT thread. | 73 // Requests a single local storage file to be deleted in the WEBKIT thread. |
73 virtual void DeleteLocalStorageFile(const FilePath& file_path); | 74 virtual void DeleteLocalStorageFile(const FilePath& file_path); |
74 | 75 |
75 protected: | 76 protected: |
76 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; | 77 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; |
77 virtual ~BrowsingDataLocalStorageHelper(); | 78 virtual ~BrowsingDataLocalStorageHelper(); |
78 | 79 |
79 // Notifies the completion callback in the UI thread. | 80 // Notifies the completion callback in the UI thread. |
80 void NotifyInUIThread(); | 81 void NotifyInUIThread(); |
81 | 82 |
82 Profile* profile_; | 83 Profile* profile_; |
83 | 84 |
84 // This only mutates on the UI thread. | 85 // This only mutates on the UI thread. |
85 scoped_ptr<Callback1<const std::list<LocalStorageInfo>& >::Type > | 86 base::Callback<void(const std::list<LocalStorageInfo>&)> completion_callback_; |
86 completion_callback_; | |
87 | 87 |
88 // Indicates whether or not we're currently fetching information: | 88 // Indicates whether or not we're currently fetching information: |
89 // it's true when StartFetching() is called in the UI thread, and it's reset | 89 // it's true when StartFetching() is called in the UI thread, and it's reset |
90 // after we notified the callback in the UI thread. | 90 // after we notified the callback in the UI thread. |
91 // This only mutates on the UI thread. | 91 // This only mutates on the UI thread. |
92 bool is_fetching_; | 92 bool is_fetching_; |
93 | 93 |
94 // This only mutates in the WEBKIT thread. | 94 // This only mutates in the WEBKIT thread. |
95 std::list<LocalStorageInfo> local_storage_info_; | 95 std::list<LocalStorageInfo> local_storage_info_; |
96 | 96 |
97 private: | 97 private: |
98 // Enumerates all local storage files in the WEBKIT thread. | 98 // Enumerates all local storage files in the WEBKIT thread. |
99 void FetchLocalStorageInfoInWebKitThread(); | 99 void FetchLocalStorageInfoInWebKitThread(); |
100 // Delete a single local storage file in the WEBKIT thread. | 100 // Delete a single local storage file in the WEBKIT thread. |
101 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); | 101 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); | 103 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); |
104 }; | 104 }; |
105 | 105 |
106 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does | 106 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does |
107 // not fetch its information from the local storage tracker, but gets them | 107 // not fetch its information from the local storage tracker, but gets them |
108 // passed as a parameter during construction. | 108 // passed as a parameter during construction. |
109 class CannedBrowsingDataLocalStorageHelper | 109 class CannedBrowsingDataLocalStorageHelper |
110 : public BrowsingDataLocalStorageHelper { | 110 : public BrowsingDataLocalStorageHelper { |
111 public: | 111 public: |
112 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); | 112 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); |
113 | 113 |
114 // Return a copy of the local storage helper. Only one consumer can use the | 114 // Return a copy of the local storage helper. Only one consumer can use the |
115 // StartFetching method at a time, so we need to create a copy of the helper | 115 // StartFetching method at a time, so we need to create a copy of the helper |
116 // everytime we instantiate a cookies tree model for it. | 116 // every time we instantiate a cookies tree model for it. |
117 CannedBrowsingDataLocalStorageHelper* Clone(); | 117 CannedBrowsingDataLocalStorageHelper* Clone(); |
118 | 118 |
119 // Add a local storage to the set of canned local storages that is returned | 119 // Add a local storage to the set of canned local storages that is returned |
120 // by this helper. | 120 // by this helper. |
121 void AddLocalStorage(const GURL& origin); | 121 void AddLocalStorage(const GURL& origin); |
122 | 122 |
123 // Clear the list of canned local storages. | 123 // Clear the list of canned local storages. |
124 void Reset(); | 124 void Reset(); |
125 | 125 |
126 // True if no local storages are currently stored. | 126 // True if no local storages are currently stored. |
127 bool empty() const; | 127 bool empty() const; |
128 | 128 |
129 // BrowsingDataLocalStorageHelper methods. | 129 // BrowsingDataLocalStorageHelper implementation. |
130 virtual void StartFetching( | 130 virtual void StartFetching( |
131 Callback1<const std::list<LocalStorageInfo>& >::Type* callback); | 131 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) |
132 virtual void CancelNotification() {} | 132 OVERRIDE; |
| 133 virtual void CancelNotification() OVERRIDE {} |
133 | 134 |
134 private: | 135 private: |
135 virtual ~CannedBrowsingDataLocalStorageHelper(); | 136 virtual ~CannedBrowsingDataLocalStorageHelper(); |
136 | 137 |
137 // Convert the pending local storage info to local storage info objects. | 138 // Convert the pending local storage info to local storage info objects. |
138 void ConvertPendingInfoInWebKitThread(); | 139 void ConvertPendingInfoInWebKitThread(); |
139 | 140 |
140 // Used to protect access to pending_local_storage_info_. | 141 // Used to protect access to pending_local_storage_info_. |
141 mutable base::Lock lock_; | 142 mutable base::Lock lock_; |
142 | 143 |
143 // May mutate on WEBKIT and UI threads. | 144 // May mutate on WEBKIT and UI threads. |
144 std::set<GURL> pending_local_storage_info_; | 145 std::set<GURL> pending_local_storage_info_; |
145 | 146 |
146 Profile* profile_; | 147 Profile* profile_; |
147 | 148 |
148 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); | 149 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); |
149 }; | 150 }; |
150 | 151 |
151 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ | 152 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ |
OLD | NEW |