| 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 "webkit/quota/mock_storage_client.h" | 5 #include "webkit/quota/mock_storage_client.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 DISALLOW_COPY_AND_ASSIGN(MockStorageClientIDSequencer); | 40 DISALLOW_COPY_AND_ASSIGN(MockStorageClientIDSequencer); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // anonymous namespace | 43 } // anonymous namespace |
| 44 | 44 |
| 45 MockStorageClient::MockStorageClient( | 45 MockStorageClient::MockStorageClient( |
| 46 QuotaManagerProxy* quota_manager_proxy, | 46 QuotaManagerProxy* quota_manager_proxy, |
| 47 const MockOriginData* mock_data, size_t mock_data_size) | 47 const MockOriginData* mock_data, size_t mock_data_size) |
| 48 : quota_manager_proxy_(quota_manager_proxy), | 48 : quota_manager_proxy_(quota_manager_proxy), |
| 49 id_(MockStorageClientIDSequencer::GetInstance()->NextMockID()), | 49 id_(MockStorageClientIDSequencer::GetInstance()->NextMockID()), |
| 50 virtual_time_counter_(0), |
| 50 runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 51 runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 51 for (size_t i = 0; i < mock_data_size; ++i) { | 52 for (size_t i = 0; i < mock_data_size; ++i) { |
| 52 origin_data_[make_pair(GURL(mock_data[i].origin), mock_data[i].type)] = | 53 origin_data_[make_pair(GURL(mock_data[i].origin), mock_data[i].type)] = |
| 53 mock_data[i].usage; | 54 mock_data[i].usage; |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 MockStorageClient::~MockStorageClient() { | 58 MockStorageClient::~MockStorageClient() { |
| 58 STLDeleteContainerPointers(usage_callbacks_.begin(), usage_callbacks_.end()); | 59 STLDeleteContainerPointers(usage_callbacks_.begin(), usage_callbacks_.end()); |
| 59 STLDeleteContainerPointers( | 60 STLDeleteContainerPointers( |
| 60 origins_callbacks_.begin(), origins_callbacks_.end()); | 61 origins_callbacks_.begin(), origins_callbacks_.end()); |
| 61 STLDeleteContainerPointers( | 62 STLDeleteContainerPointers( |
| 62 deletion_callbacks_.begin(), deletion_callbacks_.end()); | 63 deletion_callbacks_.begin(), deletion_callbacks_.end()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void MockStorageClient::AddOriginAndNotify( | 66 void MockStorageClient::AddOriginAndNotify( |
| 66 const GURL& origin_url, StorageType type, int64 size) { | 67 const GURL& origin_url, StorageType type, int64 size) { |
| 67 DCHECK(origin_data_.find(make_pair(origin_url, type)) == origin_data_.end()); | 68 DCHECK(origin_data_.find(make_pair(origin_url, type)) == origin_data_.end()); |
| 68 DCHECK_GE(size, 0); | 69 DCHECK_GE(size, 0); |
| 69 origin_data_[make_pair(origin_url, type)] = size; | 70 origin_data_[make_pair(origin_url, type)] = size; |
| 70 quota_manager_proxy_->NotifyStorageModified(id(), origin_url, type, size); | 71 quota_manager_proxy_->quota_manager()->NotifyStorageModifiedInternal( |
| 72 id(), origin_url, type, size, GetCurrentMockTime()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void MockStorageClient::ModifyOriginAndNotify( | 75 void MockStorageClient::ModifyOriginAndNotify( |
| 74 const GURL& origin_url, StorageType type, int64 delta) { | 76 const GURL& origin_url, StorageType type, int64 delta) { |
| 75 OriginDataMap::iterator find = origin_data_.find(make_pair(origin_url, type)); | 77 OriginDataMap::iterator find = origin_data_.find(make_pair(origin_url, type)); |
| 76 DCHECK(find != origin_data_.end()); | 78 DCHECK(find != origin_data_.end()); |
| 77 find->second += delta; | 79 find->second += delta; |
| 78 DCHECK_GE(find->second, 0); | 80 DCHECK_GE(find->second, 0); |
| 79 | 81 |
| 80 // TODO(tzik): Check quota to prevent usage exceed | 82 // TODO(tzik): Check quota to prevent usage exceed |
| 81 quota_manager_proxy_->NotifyStorageModified(id(), origin_url, type, delta); | 83 quota_manager_proxy_->quota_manager()->NotifyStorageModifiedInternal( |
| 84 id(), origin_url, type, delta, GetCurrentMockTime()); |
| 82 } | 85 } |
| 83 | 86 |
| 84 void MockStorageClient::AddOriginToErrorSet( | 87 void MockStorageClient::AddOriginToErrorSet( |
| 85 const GURL& origin_url, StorageType type) { | 88 const GURL& origin_url, StorageType type) { |
| 86 error_origins_.insert(make_pair(origin_url, type)); | 89 error_origins_.insert(make_pair(origin_url, type)); |
| 87 } | 90 } |
| 88 | 91 |
| 92 base::Time MockStorageClient::GetCurrentMockTime() { |
| 93 ++virtual_time_counter_; |
| 94 return base::Time::FromDoubleT(virtual_time_counter_ * 10.0); |
| 95 } |
| 96 |
| 89 QuotaClient::ID MockStorageClient::id() const { | 97 QuotaClient::ID MockStorageClient::id() const { |
| 90 return id_; | 98 return id_; |
| 91 } | 99 } |
| 92 | 100 |
| 93 void MockStorageClient::OnQuotaManagerDestroyed() { | 101 void MockStorageClient::OnQuotaManagerDestroyed() { |
| 94 delete this; | 102 delete this; |
| 95 } | 103 } |
| 96 | 104 |
| 97 void MockStorageClient::GetOriginUsage(const GURL& origin_url, | 105 void MockStorageClient::GetOriginUsage(const GURL& origin_url, |
| 98 StorageType type, | 106 StorageType type, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 quota_manager_proxy_-> | 201 quota_manager_proxy_-> |
| 194 NotifyStorageModified(id(), origin_url, type, -delta); | 202 NotifyStorageModified(id(), origin_url, type, -delta); |
| 195 origin_data_.erase(itr); | 203 origin_data_.erase(itr); |
| 196 } | 204 } |
| 197 | 205 |
| 198 deletion_callbacks_.erase(callback_ptr); | 206 deletion_callbacks_.erase(callback_ptr); |
| 199 callback->Run(kQuotaStatusOk); | 207 callback->Run(kQuotaStatusOk); |
| 200 } | 208 } |
| 201 | 209 |
| 202 } // namespace quota | 210 } // namespace quota |
| OLD | NEW |