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 #include "chrome/browser/browsing_data_local_storage_helper.h" | 5 #include "chrome/browser/browsing_data_local_storage_helper.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
17 #include "webkit/glue/webkit_glue.h" | 17 #include "webkit/glue/webkit_glue.h" |
18 | 18 |
| 19 using WebKit::WebSecurityOrigin; |
| 20 |
19 BrowsingDataLocalStorageHelper::LocalStorageInfo::LocalStorageInfo() {} | 21 BrowsingDataLocalStorageHelper::LocalStorageInfo::LocalStorageInfo() {} |
20 | 22 |
21 BrowsingDataLocalStorageHelper::LocalStorageInfo::LocalStorageInfo( | 23 BrowsingDataLocalStorageHelper::LocalStorageInfo::LocalStorageInfo( |
22 const std::string& protocol, | 24 const std::string& protocol, |
23 const std::string& host, | 25 const std::string& host, |
24 unsigned short port, | 26 unsigned short port, |
25 const std::string& database_identifier, | 27 const std::string& database_identifier, |
26 const std::string& origin, | 28 const std::string& origin, |
27 const FilePath& file_path, | 29 const FilePath& file_path, |
28 int64 size, | 30 int64 size, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 86 |
85 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { | 87 void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() { |
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
87 file_util::FileEnumerator file_enumerator( | 89 file_util::FileEnumerator file_enumerator( |
88 profile_->GetWebKitContext()->data_path().Append( | 90 profile_->GetWebKitContext()->data_path().Append( |
89 DOMStorageContext::kLocalStorageDirectory), | 91 DOMStorageContext::kLocalStorageDirectory), |
90 false, file_util::FileEnumerator::FILES); | 92 false, file_util::FileEnumerator::FILES); |
91 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 93 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
92 file_path = file_enumerator.Next()) { | 94 file_path = file_enumerator.Next()) { |
93 if (file_path.Extension() == DOMStorageContext::kLocalStorageExtension) { | 95 if (file_path.Extension() == DOMStorageContext::kLocalStorageExtension) { |
94 WebKit::WebSecurityOrigin web_security_origin = | 96 WebSecurityOrigin web_security_origin = |
95 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( | 97 WebSecurityOrigin::createFromDatabaseIdentifier( |
96 webkit_glue::FilePathToWebString(file_path.BaseName())); | 98 webkit_glue::FilePathToWebString(file_path.BaseName())); |
97 if (EqualsASCII(web_security_origin.protocol(), | 99 if (EqualsASCII(web_security_origin.protocol(), |
98 chrome::kExtensionScheme)) { | 100 chrome::kExtensionScheme)) { |
99 // Extension state is not considered browsing data. | 101 // Extension state is not considered browsing data. |
100 continue; | 102 continue; |
101 } | 103 } |
102 base::PlatformFileInfo file_info; | 104 base::PlatformFileInfo file_info; |
103 bool ret = file_util::GetFileInfo(file_path, &file_info); | 105 bool ret = file_util::GetFileInfo(file_path, &file_info); |
104 if (ret) { | 106 if (ret) { |
105 local_storage_info_.push_back(LocalStorageInfo( | 107 local_storage_info_.push_back(LocalStorageInfo( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 file_path); | 142 file_path); |
141 } | 143 } |
142 | 144 |
143 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( | 145 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( |
144 Profile* profile) | 146 Profile* profile) |
145 : BrowsingDataLocalStorageHelper(profile) { | 147 : BrowsingDataLocalStorageHelper(profile) { |
146 } | 148 } |
147 | 149 |
148 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( | 150 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( |
149 const GURL& origin) { | 151 const GURL& origin) { |
150 WebKit::WebSecurityOrigin web_security_origin = | 152 base::AutoLock auto_lock(lock_); |
151 WebKit::WebSecurityOrigin::createFromString( | 153 pending_local_storage_info_.push_back(origin); |
152 UTF8ToUTF16(origin.spec())); | |
153 std::string security_origin(web_security_origin.toString().utf8()); | |
154 | |
155 for (std::vector<LocalStorageInfo>::iterator | |
156 local_storage = local_storage_info_.begin(); | |
157 local_storage != local_storage_info_.end(); ++local_storage) { | |
158 if (local_storage->origin == security_origin) | |
159 return; | |
160 } | |
161 | |
162 local_storage_info_.push_back(LocalStorageInfo( | |
163 web_security_origin.protocol().utf8(), | |
164 web_security_origin.host().utf8(), | |
165 web_security_origin.port(), | |
166 web_security_origin.databaseIdentifier().utf8(), | |
167 security_origin, | |
168 profile_->GetWebKitContext()->dom_storage_context()-> | |
169 GetLocalStorageFilePath(web_security_origin.databaseIdentifier()), | |
170 0, | |
171 base::Time())); | |
172 } | 154 } |
173 | 155 |
174 void CannedBrowsingDataLocalStorageHelper::Reset() { | 156 void CannedBrowsingDataLocalStorageHelper::Reset() { |
| 157 base::AutoLock auto_lock(lock_); |
175 local_storage_info_.clear(); | 158 local_storage_info_.clear(); |
| 159 pending_local_storage_info_.clear(); |
176 } | 160 } |
177 | 161 |
178 bool CannedBrowsingDataLocalStorageHelper::empty() const { | 162 bool CannedBrowsingDataLocalStorageHelper::empty() const { |
179 return local_storage_info_.empty(); | 163 base::AutoLock auto_lock(lock_); |
| 164 return local_storage_info_.empty() && pending_local_storage_info_.empty(); |
180 } | 165 } |
181 | 166 |
182 void CannedBrowsingDataLocalStorageHelper::StartFetching( | 167 void CannedBrowsingDataLocalStorageHelper::StartFetching( |
183 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) { | 168 Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) { |
184 callback->Run(local_storage_info_); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
185 delete callback; | 170 DCHECK(!is_fetching_); |
| 171 DCHECK(callback); |
| 172 is_fetching_ = true; |
| 173 completion_callback_.reset(callback); |
| 174 BrowserThread::PostTask( |
| 175 BrowserThread::WEBKIT, FROM_HERE, |
| 176 NewRunnableMethod( |
| 177 this, |
| 178 &CannedBrowsingDataLocalStorageHelper:: |
| 179 ConvertPendingInfoInWebKitThread)); |
186 } | 180 } |
| 181 |
| 182 void CannedBrowsingDataLocalStorageHelper::ConvertPendingInfoInWebKitThread() { |
| 183 base::AutoLock auto_lock(lock_); |
| 184 for (std::vector<GURL>::iterator info = pending_local_storage_info_.begin(); |
| 185 info != pending_local_storage_info_.end(); ++info) { |
| 186 WebSecurityOrigin web_security_origin = |
| 187 WebSecurityOrigin::createFromString( |
| 188 UTF8ToUTF16(info->spec())); |
| 189 std::string security_origin(web_security_origin.toString().utf8()); |
| 190 |
| 191 bool duplicate = false; |
| 192 for (std::vector<LocalStorageInfo>::iterator |
| 193 local_storage = local_storage_info_.begin(); |
| 194 local_storage != local_storage_info_.end(); ++local_storage) { |
| 195 if (local_storage->origin == security_origin) { |
| 196 duplicate = true; |
| 197 break; |
| 198 } |
| 199 } |
| 200 if (duplicate) |
| 201 continue; |
| 202 |
| 203 local_storage_info_.push_back(LocalStorageInfo( |
| 204 web_security_origin.protocol().utf8(), |
| 205 web_security_origin.host().utf8(), |
| 206 web_security_origin.port(), |
| 207 web_security_origin.databaseIdentifier().utf8(), |
| 208 security_origin, |
| 209 profile_->GetWebKitContext()->dom_storage_context()-> |
| 210 GetLocalStorageFilePath(web_security_origin.databaseIdentifier()), |
| 211 0, |
| 212 base::Time())); |
| 213 } |
| 214 pending_local_storage_info_.clear(); |
| 215 |
| 216 BrowserThread::PostTask( |
| 217 BrowserThread::UI, FROM_HERE, |
| 218 NewRunnableMethod( |
| 219 this, &CannedBrowsingDataLocalStorageHelper::NotifyInUIThread)); |
| 220 } |
OLD | NEW |