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) |
| 69 OVERRIDE; |
68 // Cancels the notification callback (i.e., the window that created it no | 70 // Cancels the notification callback (i.e., the window that created it no |
69 // longer exists). | 71 // longer exists). |
70 // This must be called only in the UI thread. | 72 // This must be called only in the UI thread. |
71 virtual void CancelNotification(); | 73 virtual void CancelNotification() OVERRIDE; |
72 // Requests a single local storage file to be deleted in the WEBKIT thread. | 74 // Requests a single local storage file to be deleted in the WEBKIT thread. |
73 virtual void DeleteLocalStorageFile(const FilePath& file_path); | 75 virtual void DeleteLocalStorageFile(const FilePath& file_path) OVERRIDE; |
74 | 76 |
75 protected: | 77 protected: |
76 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; | 78 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; |
77 virtual ~BrowsingDataLocalStorageHelper(); | 79 virtual ~BrowsingDataLocalStorageHelper(); |
78 | 80 |
79 // Notifies the completion callback in the UI thread. | 81 // Notifies the completion callback in the UI thread. |
80 void NotifyInUIThread(); | 82 void NotifyInUIThread(); |
81 | 83 |
82 Profile* profile_; | 84 Profile* profile_; |
83 | 85 |
84 // This only mutates on the UI thread. | 86 // This only mutates on the UI thread. |
85 scoped_ptr<Callback1<const std::list<LocalStorageInfo>& >::Type > | 87 base::Callback<void(const std::list<LocalStorageInfo>&)> completion_callback_; |
86 completion_callback_; | |
87 | 88 |
88 // Indicates whether or not we're currently fetching information: | 89 // 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 | 90 // 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. | 91 // after we notified the callback in the UI thread. |
91 // This only mutates on the UI thread. | 92 // This only mutates on the UI thread. |
92 bool is_fetching_; | 93 bool is_fetching_; |
93 | 94 |
94 // This only mutates in the WEBKIT thread. | 95 // This only mutates in the WEBKIT thread. |
95 std::list<LocalStorageInfo> local_storage_info_; | 96 std::list<LocalStorageInfo> local_storage_info_; |
96 | 97 |
97 private: | 98 private: |
98 // Enumerates all local storage files in the WEBKIT thread. | 99 // Enumerates all local storage files in the WEBKIT thread. |
99 void FetchLocalStorageInfoInWebKitThread(); | 100 void FetchLocalStorageInfoInWebKitThread(); |
100 // Delete a single local storage file in the WEBKIT thread. | 101 // Delete a single local storage file in the WEBKIT thread. |
101 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); | 102 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); |
102 | 103 |
103 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); | 104 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); |
104 }; | 105 }; |
105 | 106 |
106 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does | 107 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does |
107 // not fetch its information from the local storage tracker, but gets them | 108 // not fetch its information from the local storage tracker, but gets them |
108 // passed as a parameter during construction. | 109 // passed as a parameter during construction. |
109 class CannedBrowsingDataLocalStorageHelper | 110 class CannedBrowsingDataLocalStorageHelper |
110 : public BrowsingDataLocalStorageHelper { | 111 : public BrowsingDataLocalStorageHelper { |
111 public: | 112 public: |
112 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); | 113 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); |
113 | 114 |
114 // Return a copy of the local storage helper. Only one consumer can use the | 115 // 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 | 116 // 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. | 117 // every time we instantiate a cookies tree model for it. |
117 CannedBrowsingDataLocalStorageHelper* Clone(); | 118 CannedBrowsingDataLocalStorageHelper* Clone(); |
118 | 119 |
119 // Add a local storage to the set of canned local storages that is returned | 120 // Add a local storage to the set of canned local storages that is returned |
120 // by this helper. | 121 // by this helper. |
121 void AddLocalStorage(const GURL& origin); | 122 void AddLocalStorage(const GURL& origin); |
122 | 123 |
123 // Clear the list of canned local storages. | 124 // Clear the list of canned local storages. |
124 void Reset(); | 125 void Reset(); |
125 | 126 |
126 // True if no local storages are currently stored. | 127 // True if no local storages are currently stored. |
127 bool empty() const; | 128 bool empty() const; |
128 | 129 |
129 // BrowsingDataLocalStorageHelper methods. | 130 // BrowsingDataLocalStorageHelper implementation. |
130 virtual void StartFetching( | 131 virtual void StartFetching( |
131 Callback1<const std::list<LocalStorageInfo>& >::Type* callback); | 132 const base::Callback<void(const std::list<LocalStorageInfo>&)>& callback) |
132 virtual void CancelNotification() {} | 133 OVERRIDE; |
| 134 virtual void CancelNotification() OVERRIDE {} |
133 | 135 |
134 private: | 136 private: |
135 virtual ~CannedBrowsingDataLocalStorageHelper(); | 137 virtual ~CannedBrowsingDataLocalStorageHelper(); |
136 | 138 |
137 // Convert the pending local storage info to local storage info objects. | 139 // Convert the pending local storage info to local storage info objects. |
138 void ConvertPendingInfoInWebKitThread(); | 140 void ConvertPendingInfoInWebKitThread(); |
139 | 141 |
140 // Used to protect access to pending_local_storage_info_. | 142 // Used to protect access to pending_local_storage_info_. |
141 mutable base::Lock lock_; | 143 mutable base::Lock lock_; |
142 | 144 |
143 // May mutate on WEBKIT and UI threads. | 145 // May mutate on WEBKIT and UI threads. |
144 std::set<GURL> pending_local_storage_info_; | 146 std::set<GURL> pending_local_storage_info_; |
145 | 147 |
146 Profile* profile_; | 148 Profile* profile_; |
147 | 149 |
148 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); | 150 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); |
149 }; | 151 }; |
150 | 152 |
151 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ | 153 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ |
OLD | NEW |