| 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/mock_browsing_data_database_helper.h" | 5 #include "chrome/browser/mock_browsing_data_database_helper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 | 8 |
| 9 MockBrowsingDataDatabaseHelper::MockBrowsingDataDatabaseHelper( | 9 MockBrowsingDataDatabaseHelper::MockBrowsingDataDatabaseHelper( |
| 10 Profile* profile) | 10 Profile* profile) |
| 11 : BrowsingDataDatabaseHelper(profile), | 11 : BrowsingDataDatabaseHelper(profile), |
| 12 profile_(profile) { | 12 profile_(profile) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 MockBrowsingDataDatabaseHelper::~MockBrowsingDataDatabaseHelper() { | 15 MockBrowsingDataDatabaseHelper::~MockBrowsingDataDatabaseHelper() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 void MockBrowsingDataDatabaseHelper::StartFetching( | 18 void MockBrowsingDataDatabaseHelper::StartFetching( |
| 19 Callback1<const std::list<DatabaseInfo>& >::Type* callback) { | 19 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { |
| 20 callback_.reset(callback); | 20 callback_ = callback; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void MockBrowsingDataDatabaseHelper::CancelNotification() { | 23 void MockBrowsingDataDatabaseHelper::CancelNotification() { |
| 24 callback_.reset(NULL); | 24 callback_.Reset(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void MockBrowsingDataDatabaseHelper::DeleteDatabase( | 27 void MockBrowsingDataDatabaseHelper::DeleteDatabase( |
| 28 const std::string& origin, | 28 const std::string& origin, |
| 29 const std::string& name) { | 29 const std::string& name) { |
| 30 std::string key = origin + ":" + name; | 30 std::string key = origin + ":" + name; |
| 31 CHECK(databases_.find(key) != databases_.end()); | 31 CHECK(databases_.find(key) != databases_.end()); |
| 32 last_deleted_origin_ = origin; | 32 last_deleted_origin_ = origin; |
| 33 last_deleted_db_ = name; | 33 last_deleted_db_ = name; |
| 34 databases_[key] = false; | 34 databases_[key] = false; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void MockBrowsingDataDatabaseHelper::AddDatabaseSamples() { | 37 void MockBrowsingDataDatabaseHelper::AddDatabaseSamples() { |
| 38 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( | 38 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( |
| 39 "gdbhost1", "db1", "http_gdbhost1_1", "description 1", | 39 "gdbhost1", "db1", "http_gdbhost1_1", "description 1", |
| 40 "http://gdbhost1:1/", 1, base::Time())); | 40 "http://gdbhost1:1/", 1, base::Time())); |
| 41 databases_["http_gdbhost1_1:db1"] = true; | 41 databases_["http_gdbhost1_1:db1"] = true; |
| 42 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( | 42 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( |
| 43 "gdbhost2", "db2", "http_gdbhost2_2", "description 2", | 43 "gdbhost2", "db2", "http_gdbhost2_2", "description 2", |
| 44 "http://gdbhost2:2/", 2, base::Time())); | 44 "http://gdbhost2:2/", 2, base::Time())); |
| 45 databases_["http_gdbhost2_2:db2"] = true; | 45 databases_["http_gdbhost2_2:db2"] = true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void MockBrowsingDataDatabaseHelper::Notify() { | 48 void MockBrowsingDataDatabaseHelper::Notify() { |
| 49 CHECK(callback_.get()); | 49 CHECK_EQ(false, callback_.is_null()); |
| 50 callback_->Run(response_); | 50 callback_.Run(response_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void MockBrowsingDataDatabaseHelper::Reset() { | 53 void MockBrowsingDataDatabaseHelper::Reset() { |
| 54 for (std::map<const std::string, bool>::iterator i = databases_.begin(); | 54 for (std::map<const std::string, bool>::iterator i = databases_.begin(); |
| 55 i != databases_.end(); ++i) | 55 i != databases_.end(); ++i) |
| 56 i->second = true; | 56 i->second = true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool MockBrowsingDataDatabaseHelper::AllDeleted() { | 59 bool MockBrowsingDataDatabaseHelper::AllDeleted() { |
| 60 for (std::map<const std::string, bool>::const_iterator i = databases_.begin(); | 60 for (std::map<const std::string, bool>::const_iterator i = databases_.begin(); |
| 61 i != databases_.end(); ++i) | 61 i != databases_.end(); ++i) |
| 62 if (i->second) | 62 if (i->second) |
| 63 return false; | 63 return false; |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| OLD | NEW |