| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "webkit/quota/quota_manager.h" | 15 #include "webkit/quota/quota_manager.h" |
| 16 | 16 |
| 17 using base::AtomicSequenceNumber; | 17 using base::AtomicSequenceNumber; |
| 18 | 18 |
| 19 namespace quota { | 19 namespace quota { |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 using std::make_pair; | 21 using std::make_pair; |
| 24 | 22 |
| 25 class MockStorageClientIDSequencer { | |
| 26 public: | |
| 27 static MockStorageClientIDSequencer* GetInstance() { | |
| 28 return Singleton<MockStorageClientIDSequencer>::get(); | |
| 29 } | |
| 30 | |
| 31 QuotaClient::ID NextMockID() { | |
| 32 return static_cast<QuotaClient::ID>( | |
| 33 QuotaClient::kMockStart + seq_.GetNext()); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 MockStorageClientIDSequencer() { } | |
| 38 friend struct DefaultSingletonTraits<MockStorageClientIDSequencer>; | |
| 39 AtomicSequenceNumber seq_; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(MockStorageClientIDSequencer); | |
| 42 }; | |
| 43 | |
| 44 } // anonymous namespace | |
| 45 | |
| 46 MockStorageClient::MockStorageClient( | |
| 47 QuotaManagerProxy* quota_manager_proxy, | |
| 48 const MockOriginData* mock_data, size_t mock_data_size) | |
| 49 : quota_manager_proxy_(quota_manager_proxy), | |
| 50 id_(MockStorageClientIDSequencer::GetInstance()->NextMockID()), | |
| 51 mock_time_counter_(0), | |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 53 Populate(mock_data, mock_data_size); | |
| 54 } | |
| 55 | |
| 56 MockStorageClient::MockStorageClient( | 23 MockStorageClient::MockStorageClient( |
| 57 QuotaManagerProxy* quota_manager_proxy, | 24 QuotaManagerProxy* quota_manager_proxy, |
| 58 const MockOriginData* mock_data, QuotaClient::ID id, size_t mock_data_size) | 25 const MockOriginData* mock_data, QuotaClient::ID id, size_t mock_data_size) |
| 59 : quota_manager_proxy_(quota_manager_proxy), | 26 : quota_manager_proxy_(quota_manager_proxy), |
| 60 id_(id), | 27 id_(id), |
| 61 mock_time_counter_(0), | 28 mock_time_counter_(0), |
| 62 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 63 Populate(mock_data, mock_data_size); | 30 Populate(mock_data, mock_data_size); |
| 64 } | 31 } |
| 65 | 32 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 int64 delta = itr->second; | 176 int64 delta = itr->second; |
| 210 quota_manager_proxy_-> | 177 quota_manager_proxy_-> |
| 211 NotifyStorageModified(id(), origin_url, type, -delta); | 178 NotifyStorageModified(id(), origin_url, type, -delta); |
| 212 origin_data_.erase(itr); | 179 origin_data_.erase(itr); |
| 213 } | 180 } |
| 214 | 181 |
| 215 callback.Run(kQuotaStatusOk); | 182 callback.Run(kQuotaStatusOk); |
| 216 } | 183 } |
| 217 | 184 |
| 218 } // namespace quota | 185 } // namespace quota |
| OLD | NEW |