| 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_indexed_db_helper.h" | 5 #include "chrome/browser/mock_browsing_data_indexed_db_helper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( | 10 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper() { |
| 11 Profile* profile) | |
| 12 : profile_(profile) { | |
| 13 } | 11 } |
| 14 | 12 |
| 15 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { | 13 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { |
| 16 } | 14 } |
| 17 | 15 |
| 18 void MockBrowsingDataIndexedDBHelper::StartFetching( | 16 void MockBrowsingDataIndexedDBHelper::StartFetching( |
| 19 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { | 17 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { |
| 20 callback_.reset(callback); | 18 callback_.reset(callback); |
| 21 } | 19 } |
| 22 | 20 |
| 23 void MockBrowsingDataIndexedDBHelper::CancelNotification() { | 21 void MockBrowsingDataIndexedDBHelper::CancelNotification() { |
| 24 callback_.reset(NULL); | 22 callback_.reset(NULL); |
| 25 } | 23 } |
| 26 | 24 |
| 27 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDBFile( | 25 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( |
| 28 const FilePath& file_path) { | 26 const GURL& origin) { |
| 29 CHECK(files_.find(file_path.value()) != files_.end()); | 27 CHECK(origins_.find(origin) != origins_.end()); |
| 30 last_deleted_file_ = file_path; | 28 origins_[origin] = false; |
| 31 files_[file_path.value()] = false; | |
| 32 } | 29 } |
| 33 | 30 |
| 34 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { | 31 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { |
| 32 const GURL kOrigin1("http://idbhost1:1/"); |
| 33 const GURL kOrigin2("http://idbhost2:2/"); |
| 35 response_.push_back( | 34 response_.push_back( |
| 36 BrowsingDataIndexedDBHelper::IndexedDBInfo( | 35 BrowsingDataIndexedDBHelper::IndexedDBInfo( |
| 37 "http", "idbhost1", 1, "idb1", "http://idbhost1:1/", | 36 kOrigin1, 1, base::Time())); |
| 38 FilePath(FILE_PATH_LITERAL("file1")), 1, base::Time())); | 37 origins_[kOrigin1] = true; |
| 39 files_[FILE_PATH_LITERAL("file1")] = true; | |
| 40 response_.push_back( | 38 response_.push_back( |
| 41 BrowsingDataIndexedDBHelper::IndexedDBInfo( | 39 BrowsingDataIndexedDBHelper::IndexedDBInfo( |
| 42 "http", "idbhost2", 2, "idb2", "http://idbhost2:2/", | 40 kOrigin2, 2, base::Time())); |
| 43 FilePath(FILE_PATH_LITERAL("file2")), 2, base::Time())); | 41 origins_[kOrigin2] = true; |
| 44 files_[FILE_PATH_LITERAL("file2")] = true; | |
| 45 } | 42 } |
| 46 | 43 |
| 47 void MockBrowsingDataIndexedDBHelper::Notify() { | 44 void MockBrowsingDataIndexedDBHelper::Notify() { |
| 48 CHECK(callback_.get()); | 45 CHECK(callback_.get()); |
| 49 callback_->Run(response_); | 46 callback_->Run(response_); |
| 50 } | 47 } |
| 51 | 48 |
| 52 void MockBrowsingDataIndexedDBHelper::Reset() { | 49 void MockBrowsingDataIndexedDBHelper::Reset() { |
| 53 for (std::map<const FilePath::StringType, bool>::iterator i = files_.begin(); | 50 for (std::map<GURL, bool>::iterator i = origins_.begin(); |
| 54 i != files_.end(); ++i) | 51 i != origins_.end(); ++i) |
| 55 i->second = true; | 52 i->second = true; |
| 56 } | 53 } |
| 57 | 54 |
| 58 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { | 55 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { |
| 59 for (std::map<const FilePath::StringType, bool>::const_iterator i = | 56 for (std::map<GURL, bool>::const_iterator i = origins_.begin(); |
| 60 files_.begin(); i != files_.end(); ++i) | 57 i != origins_.end(); ++i) |
| 61 if (i->second) | 58 if (i->second) |
| 62 return false; | 59 return false; |
| 63 return true; | 60 return true; |
| 64 } | 61 } |
| OLD | NEW |