| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_database_helper.h" | 5 #include "chrome/browser/browsing_data_database_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 "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| 11 #include "net/base/net_errors.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 14 #include "webkit/database/database_tracker.h" | |
| 15 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
| 16 | 16 |
| 17 BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) | 17 BrowsingDataDatabaseHelper::BrowsingDataDatabaseHelper(Profile* profile) |
| 18 : profile_(profile), | 18 : tracker_(profile->GetDatabaseTracker()), |
| 19 completion_callback_(NULL), | 19 completion_callback_(NULL), |
| 20 is_fetching_(false) { | 20 is_fetching_(false) { |
| 21 DCHECK(profile_); | |
| 22 } | 21 } |
| 23 | 22 |
| 24 BrowsingDataDatabaseHelper::~BrowsingDataDatabaseHelper() { | 23 BrowsingDataDatabaseHelper::~BrowsingDataDatabaseHelper() { |
| 25 } | 24 } |
| 26 | 25 |
| 27 void BrowsingDataDatabaseHelper::StartFetching( | 26 void BrowsingDataDatabaseHelper::StartFetching( |
| 28 Callback1<const std::vector<DatabaseInfo>& >::Type* callback) { | 27 Callback1<const std::vector<DatabaseInfo>& >::Type* callback) { |
| 29 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 28 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 30 DCHECK(!is_fetching_); | 29 DCHECK(!is_fetching_); |
| 31 DCHECK(callback); | 30 DCHECK(callback); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 45 const std::string& name) { | 44 const std::string& name) { |
| 46 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 45 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 47 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,NewRunnableMethod( | 46 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,NewRunnableMethod( |
| 48 this, &BrowsingDataDatabaseHelper::DeleteDatabaseInFileThread, origin, | 47 this, &BrowsingDataDatabaseHelper::DeleteDatabaseInFileThread, origin, |
| 49 name)); | 48 name)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void BrowsingDataDatabaseHelper::FetchDatabaseInfoInFileThread() { | 51 void BrowsingDataDatabaseHelper::FetchDatabaseInfoInFileThread() { |
| 53 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 54 std::vector<webkit_database::OriginInfo> origins_info; | 53 std::vector<webkit_database::OriginInfo> origins_info; |
| 55 scoped_refptr<webkit_database::DatabaseTracker> tracker = | 54 if (tracker_.get() && tracker_->GetAllOriginsInfo(&origins_info)) { |
| 56 profile_->GetDatabaseTracker(); | |
| 57 if (tracker.get() && tracker->GetAllOriginsInfo(&origins_info)) { | |
| 58 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = | 55 for (std::vector<webkit_database::OriginInfo>::const_iterator ori = |
| 59 origins_info.begin(); ori != origins_info.end(); ++ori) { | 56 origins_info.begin(); ori != origins_info.end(); ++ori) { |
| 60 scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( | 57 scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( |
| 61 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( | 58 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( |
| 62 ori->GetOrigin())); | 59 ori->GetOrigin())); |
| 63 std::vector<string16> databases; | 60 std::vector<string16> databases; |
| 64 ori->GetAllDatabaseNames(&databases); | 61 ori->GetAllDatabaseNames(&databases); |
| 65 for (std::vector<string16>::const_iterator db = databases.begin(); | 62 for (std::vector<string16>::const_iterator db = databases.begin(); |
| 66 db != databases.end(); ++db) { | 63 db != databases.end(); ++db) { |
| 67 FilePath file_path = tracker->GetFullDBFilePath(ori->GetOrigin(), *db); | 64 FilePath file_path = tracker_->GetFullDBFilePath(ori->GetOrigin(), *db); |
| 68 file_util::FileInfo file_info; | 65 file_util::FileInfo file_info; |
| 69 if (file_util::GetFileInfo(file_path, &file_info)) { | 66 if (file_util::GetFileInfo(file_path, &file_info)) { |
| 70 database_info_.push_back(DatabaseInfo( | 67 database_info_.push_back(DatabaseInfo( |
| 71 web_security_origin->host().utf8(), | 68 web_security_origin->host().utf8(), |
| 72 UTF16ToUTF8(*db), | 69 UTF16ToUTF8(*db), |
| 73 UTF16ToUTF8(ori->GetOrigin()), | 70 UTF16ToUTF8(ori->GetOrigin()), |
| 74 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), | 71 UTF16ToUTF8(ori->GetDatabaseDescription(*db)), |
| 75 file_info.size, | 72 file_info.size, |
| 76 file_info.last_modified)); | 73 file_info.last_modified)); |
| 77 } | 74 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 91 if (completion_callback_ != NULL) | 88 if (completion_callback_ != NULL) |
| 92 completion_callback_->Run(database_info_); | 89 completion_callback_->Run(database_info_); |
| 93 is_fetching_ = false; | 90 is_fetching_ = false; |
| 94 database_info_.clear(); | 91 database_info_.clear(); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void BrowsingDataDatabaseHelper::DeleteDatabaseInFileThread( | 94 void BrowsingDataDatabaseHelper::DeleteDatabaseInFileThread( |
| 98 const std::string& origin, | 95 const std::string& origin, |
| 99 const std::string& name) { | 96 const std::string& name) { |
| 100 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 97 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 101 // TODO(jochen): delete the given database. | 98 if (!tracker_.get()) |
| 99 return; |
| 100 tracker_->DeleteDatabase(UTF8ToUTF16(origin), UTF8ToUTF16(name), NULL); |
| 102 } | 101 } |
| OLD | NEW |