| 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_indexed_db_helper.h" | 5 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 6 | 6 |
| 7 #include "base/callback_old.h" | 7 #include "base/callback_old.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.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 "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "content/browser/in_process_webkit/webkit_context.h" | 18 #include "content/browser/in_process_webkit/webkit_context.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 | 20 |
| 21 using WebKit::WebSecurityOrigin; | 21 using WebKit::WebSecurityOrigin; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { | 25 class BrowsingDataIndexedDBHelperImpl : public BrowsingDataIndexedDBHelper { |
| 26 public: | 26 public: |
| 27 explicit BrowsingDataIndexedDBHelperImpl(Profile* profile); | 27 explicit BrowsingDataIndexedDBHelperImpl(Profile* profile); |
| 28 | 28 |
| 29 virtual void StartFetching( | 29 virtual void StartFetching( |
| 30 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback); | 30 Callback1<const std::list<IndexedDBInfo>& >::Type* callback); |
| 31 virtual void CancelNotification(); | 31 virtual void CancelNotification(); |
| 32 virtual void DeleteIndexedDBFile(const FilePath& file_path); | 32 virtual void DeleteIndexedDBFile(const FilePath& file_path); |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 virtual ~BrowsingDataIndexedDBHelperImpl(); | 35 virtual ~BrowsingDataIndexedDBHelperImpl(); |
| 36 | 36 |
| 37 // Enumerates all indexed database files in the WEBKIT thread. | 37 // Enumerates all indexed database files in the WEBKIT thread. |
| 38 void FetchIndexedDBInfoInWebKitThread(); | 38 void FetchIndexedDBInfoInWebKitThread(); |
| 39 // Notifies the completion callback in the UI thread. | 39 // Notifies the completion callback in the UI thread. |
| 40 void NotifyInUIThread(); | 40 void NotifyInUIThread(); |
| 41 // Delete a single indexed database file in the WEBKIT thread. | 41 // Delete a single indexed database file in the WEBKIT thread. |
| 42 void DeleteIndexedDBFileInWebKitThread(const FilePath& file_path); | 42 void DeleteIndexedDBFileInWebKitThread(const FilePath& file_path); |
| 43 | 43 |
| 44 Profile* profile_; | 44 Profile* profile_; |
| 45 | 45 |
| 46 // This only mutates in the WEBKIT thread. | 46 // This only mutates in the WEBKIT thread. |
| 47 std::vector<IndexedDBInfo> indexed_db_info_; | 47 std::list<IndexedDBInfo> indexed_db_info_; |
| 48 | 48 |
| 49 // This only mutates on the UI thread. | 49 // This only mutates on the UI thread. |
| 50 scoped_ptr<Callback1<const std::vector<IndexedDBInfo>& >::Type > | 50 scoped_ptr<Callback1<const std::list<IndexedDBInfo>& >::Type > |
| 51 completion_callback_; | 51 completion_callback_; |
| 52 // Indicates whether or not we're currently fetching information: | 52 // Indicates whether or not we're currently fetching information: |
| 53 // it's true when StartFetching() is called in the UI thread, and it's reset | 53 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 54 // after we notified the callback in the UI thread. | 54 // after we notified the callback in the UI thread. |
| 55 // This only mutates on the UI thread. | 55 // This only mutates on the UI thread. |
| 56 bool is_fetching_; | 56 bool is_fetching_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataIndexedDBHelperImpl); | 58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataIndexedDBHelperImpl); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 BrowsingDataIndexedDBHelperImpl::BrowsingDataIndexedDBHelperImpl( | 61 BrowsingDataIndexedDBHelperImpl::BrowsingDataIndexedDBHelperImpl( |
| 62 Profile* profile) | 62 Profile* profile) |
| 63 : profile_(profile), | 63 : profile_(profile), |
| 64 completion_callback_(NULL), | 64 completion_callback_(NULL), |
| 65 is_fetching_(false) { | 65 is_fetching_(false) { |
| 66 DCHECK(profile_); | 66 DCHECK(profile_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 BrowsingDataIndexedDBHelperImpl::~BrowsingDataIndexedDBHelperImpl() { | 69 BrowsingDataIndexedDBHelperImpl::~BrowsingDataIndexedDBHelperImpl() { |
| 70 } | 70 } |
| 71 | 71 |
| 72 void BrowsingDataIndexedDBHelperImpl::StartFetching( | 72 void BrowsingDataIndexedDBHelperImpl::StartFetching( |
| 73 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) { | 73 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 DCHECK(!is_fetching_); | 75 DCHECK(!is_fetching_); |
| 76 DCHECK(callback); | 76 DCHECK(callback); |
| 77 is_fetching_ = true; | 77 is_fetching_ = true; |
| 78 completion_callback_.reset(callback); | 78 completion_callback_.reset(callback); |
| 79 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 80 BrowserThread::WEBKIT, FROM_HERE, | 80 BrowserThread::WEBKIT, FROM_HERE, |
| 81 NewRunnableMethod( | 81 NewRunnableMethod( |
| 82 this, | 82 this, |
| 83 &BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread)); | 83 &BrowsingDataIndexedDBHelperImpl::FetchIndexedDBInfoInWebKitThread)); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 indexed_db_info_.clear(); | 231 indexed_db_info_.clear(); |
| 232 pending_indexed_db_info_.clear(); | 232 pending_indexed_db_info_.clear(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool CannedBrowsingDataIndexedDBHelper::empty() const { | 235 bool CannedBrowsingDataIndexedDBHelper::empty() const { |
| 236 base::AutoLock auto_lock(lock_); | 236 base::AutoLock auto_lock(lock_); |
| 237 return indexed_db_info_.empty() && pending_indexed_db_info_.empty(); | 237 return indexed_db_info_.empty() && pending_indexed_db_info_.empty(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void CannedBrowsingDataIndexedDBHelper::StartFetching( | 240 void CannedBrowsingDataIndexedDBHelper::StartFetching( |
| 241 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) { | 241 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 DCHECK(!is_fetching_); | 243 DCHECK(!is_fetching_); |
| 244 DCHECK(callback); | 244 DCHECK(callback); |
| 245 is_fetching_ = true; | 245 is_fetching_ = true; |
| 246 completion_callback_.reset(callback); | 246 completion_callback_.reset(callback); |
| 247 BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, NewRunnableMethod( | 247 BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 248 this, | 248 this, |
| 249 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread)); | 249 &CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} | 252 CannedBrowsingDataIndexedDBHelper::~CannedBrowsingDataIndexedDBHelper() {} |
| 253 | 253 |
| 254 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { | 254 void CannedBrowsingDataIndexedDBHelper::ConvertPendingInfoInWebKitThread() { |
| 255 base::AutoLock auto_lock(lock_); | 255 base::AutoLock auto_lock(lock_); |
| 256 for (std::vector<PendingIndexedDBInfo>::const_iterator | 256 for (std::list<PendingIndexedDBInfo>::const_iterator |
| 257 info = pending_indexed_db_info_.begin(); | 257 info = pending_indexed_db_info_.begin(); |
| 258 info != pending_indexed_db_info_.end(); ++info) { | 258 info != pending_indexed_db_info_.end(); ++info) { |
| 259 WebSecurityOrigin web_security_origin = | 259 WebSecurityOrigin web_security_origin = |
| 260 WebSecurityOrigin::createFromString( | 260 WebSecurityOrigin::createFromString( |
| 261 UTF8ToUTF16(info->origin.spec())); | 261 UTF8ToUTF16(info->origin.spec())); |
| 262 std::string security_origin(web_security_origin.toString().utf8()); | 262 std::string security_origin(web_security_origin.toString().utf8()); |
| 263 | 263 |
| 264 bool duplicate = false; | 264 bool duplicate = false; |
| 265 for (std::vector<IndexedDBInfo>::iterator | 265 for (std::list<IndexedDBInfo>::iterator |
| 266 indexed_db = indexed_db_info_.begin(); | 266 indexed_db = indexed_db_info_.begin(); |
| 267 indexed_db != indexed_db_info_.end(); ++indexed_db) { | 267 indexed_db != indexed_db_info_.end(); ++indexed_db) { |
| 268 if (indexed_db->origin == security_origin) { | 268 if (indexed_db->origin == security_origin) { |
| 269 duplicate = true; | 269 duplicate = true; |
| 270 break; | 270 break; |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 if (duplicate) | 273 if (duplicate) |
| 274 continue; | 274 continue; |
| 275 | 275 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 301 completion_callback_->Run(indexed_db_info_); | 301 completion_callback_->Run(indexed_db_info_); |
| 302 completion_callback_.reset(); | 302 completion_callback_.reset(); |
| 303 } | 303 } |
| 304 is_fetching_ = false; | 304 is_fetching_ = false; |
| 305 } | 305 } |
| 306 | 306 |
| 307 void CannedBrowsingDataIndexedDBHelper::CancelNotification() { | 307 void CannedBrowsingDataIndexedDBHelper::CancelNotification() { |
| 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 309 completion_callback_.reset(); | 309 completion_callback_.reset(); |
| 310 } | 310 } |
| OLD | NEW |