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 <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/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 class Profile; | 20 class Profile; |
20 | 21 |
21 // This class fetches local storage information in the WebKit thread, and | 22 // This class fetches local storage information in the WebKit thread, and |
22 // notifies the UI thread upon completion. | 23 // notifies the UI thread upon completion. |
23 // A client of this class need to call StartFetching from the UI thread to | 24 // 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 | 25 // initiate the flow, and it'll be notified by the callback in its UI |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // longer exists). | 68 // longer exists). |
68 // This must be called only in the UI thread. | 69 // This must be called only in the UI thread. |
69 virtual void CancelNotification(); | 70 virtual void CancelNotification(); |
70 // Requests a single local storage file to be deleted in the WEBKIT thread. | 71 // Requests a single local storage file to be deleted in the WEBKIT thread. |
71 virtual void DeleteLocalStorageFile(const FilePath& file_path); | 72 virtual void DeleteLocalStorageFile(const FilePath& file_path); |
72 | 73 |
73 protected: | 74 protected: |
74 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; | 75 friend class base::RefCountedThreadSafe<BrowsingDataLocalStorageHelper>; |
75 virtual ~BrowsingDataLocalStorageHelper(); | 76 virtual ~BrowsingDataLocalStorageHelper(); |
76 | 77 |
| 78 // Notifies the completion callback in the UI thread. |
| 79 void NotifyInUIThread(); |
| 80 |
77 Profile* profile_; | 81 Profile* profile_; |
78 | 82 |
| 83 // This only mutates on the UI thread. |
| 84 scoped_ptr<Callback1<const std::vector<LocalStorageInfo>& >::Type > |
| 85 completion_callback_; |
| 86 |
| 87 // Indicates whether or not we're currently fetching information: |
| 88 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 89 // after we notified the callback in the UI thread. |
| 90 // This only mutates on the UI thread. |
| 91 bool is_fetching_; |
| 92 |
79 // This only mutates in the WEBKIT thread. | 93 // This only mutates in the WEBKIT thread. |
80 std::vector<LocalStorageInfo> local_storage_info_; | 94 std::vector<LocalStorageInfo> local_storage_info_; |
81 | 95 |
82 private: | 96 private: |
83 // Enumerates all local storage files in the WEBKIT thread. | 97 // Enumerates all local storage files in the WEBKIT thread. |
84 void FetchLocalStorageInfoInWebKitThread(); | 98 void FetchLocalStorageInfoInWebKitThread(); |
85 // Notifies the completion callback in the UI thread. | |
86 void NotifyInUIThread(); | |
87 // Delete a single local storage file in the WEBKIT thread. | 99 // Delete a single local storage file in the WEBKIT thread. |
88 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); | 100 void DeleteLocalStorageFileInWebKitThread(const FilePath& file_path); |
89 | 101 |
90 // This only mutates on the UI thread. | |
91 scoped_ptr<Callback1<const std::vector<LocalStorageInfo>& >::Type > | |
92 completion_callback_; | |
93 // Indicates whether or not we're currently fetching information: | |
94 // it's true when StartFetching() is called in the UI thread, and it's reset | |
95 // after we notified the callback in the UI thread. | |
96 // This only mutates on the UI thread. | |
97 bool is_fetching_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); | 102 DISALLOW_COPY_AND_ASSIGN(BrowsingDataLocalStorageHelper); |
100 }; | 103 }; |
101 | 104 |
102 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does | 105 // This class is a thin wrapper around BrowsingDataLocalStorageHelper that does |
103 // not fetch its information from the local storage tracker, but gets them | 106 // not fetch its information from the local storage tracker, but gets them |
104 // passed as a parameter during construction. | 107 // passed as a parameter during construction. |
105 class CannedBrowsingDataLocalStorageHelper | 108 class CannedBrowsingDataLocalStorageHelper |
106 : public BrowsingDataLocalStorageHelper { | 109 : public BrowsingDataLocalStorageHelper { |
107 public: | 110 public: |
108 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); | 111 explicit CannedBrowsingDataLocalStorageHelper(Profile* profile); |
109 | 112 |
110 // Add a local storage to the set of canned local storages that is returned | 113 // Add a local storage to the set of canned local storages that is returned |
111 // by this helper. | 114 // by this helper. |
112 void AddLocalStorage(const GURL& origin); | 115 void AddLocalStorage(const GURL& origin); |
113 | 116 |
114 // Clear the list of canned local storages. | 117 // Clear the list of canned local storages. |
115 void Reset(); | 118 void Reset(); |
116 | 119 |
117 // True if no local storages are currently stored. | 120 // True if no local storages are currently stored. |
118 bool empty() const; | 121 bool empty() const; |
119 | 122 |
120 // BrowsingDataLocalStorageHelper methods. | 123 // BrowsingDataLocalStorageHelper methods. |
121 virtual void StartFetching( | 124 virtual void StartFetching( |
122 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback); | 125 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback); |
123 virtual void CancelNotification() {} | 126 virtual void CancelNotification() {} |
124 | 127 |
125 private: | 128 private: |
126 virtual ~CannedBrowsingDataLocalStorageHelper() {} | 129 virtual ~CannedBrowsingDataLocalStorageHelper() {} |
127 | 130 |
| 131 // Convert the pending local storage info to local storage info objects. |
| 132 void ConvertPendingInfoInWebKitThread(); |
| 133 |
| 134 // Used to protect access to pending_local_storage_info_. |
| 135 mutable base::Lock lock_; |
| 136 |
| 137 // May mutate on WEBKIT and UI threads. |
| 138 std::vector<GURL> pending_local_storage_info_; |
| 139 |
128 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); | 140 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataLocalStorageHelper); |
129 }; | 141 }; |
130 | 142 |
131 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ | 143 #endif // CHROME_BROWSER_BROWSING_DATA_LOCAL_STORAGE_HELPER_H_ |
OLD | NEW |