| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "storage/browser/quota/storage_monitor.h" | 5 #include "storage/browser/quota/storage_monitor.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 it != host_observers_map_.end();) { | 270 it != host_observers_map_.end();) { |
| 271 it->second->RemoveObserver(observer); | 271 it->second->RemoveObserver(observer); |
| 272 if (!it->second->ContainsObservers()) { | 272 if (!it->second->ContainsObservers()) { |
| 273 it = host_observers_map_.erase(it); | 273 it = host_observers_map_.erase(it); |
| 274 } else { | 274 } else { |
| 275 ++it; | 275 ++it; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 void StorageTypeObservers::RemoveObserverForFilter( | |
| 281 StorageObserver* observer, const StorageObserver::Filter& filter) { | |
| 282 std::string host = net::GetHostOrSpecFromURL(filter.origin); | |
| 283 auto it = host_observers_map_.find(host); | |
| 284 if (it == host_observers_map_.end()) | |
| 285 return; | |
| 286 | |
| 287 it->second->RemoveObserver(observer); | |
| 288 if (!it->second->ContainsObservers()) | |
| 289 host_observers_map_.erase(it); | |
| 290 } | |
| 291 | |
| 292 const HostStorageObservers* StorageTypeObservers::GetHostObservers( | 280 const HostStorageObservers* StorageTypeObservers::GetHostObservers( |
| 293 const std::string& host) const { | 281 const std::string& host) const { |
| 294 auto it = host_observers_map_.find(host); | 282 auto it = host_observers_map_.find(host); |
| 295 if (it != host_observers_map_.end()) | 283 if (it != host_observers_map_.end()) |
| 296 return it->second.get(); | 284 return it->second.get(); |
| 297 | 285 |
| 298 return nullptr; | 286 return nullptr; |
| 299 } | 287 } |
| 300 | 288 |
| 301 void StorageTypeObservers::NotifyUsageChange( | 289 void StorageTypeObservers::NotifyUsageChange( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 type_observers->AddObserver(observer, params); | 327 type_observers->AddObserver(observer, params); |
| 340 } | 328 } |
| 341 | 329 |
| 342 void StorageMonitor::RemoveObserver(StorageObserver* observer) { | 330 void StorageMonitor::RemoveObserver(StorageObserver* observer) { |
| 343 for (auto it = storage_type_observers_map_.begin(); | 331 for (auto it = storage_type_observers_map_.begin(); |
| 344 it != storage_type_observers_map_.end(); ++it) { | 332 it != storage_type_observers_map_.end(); ++it) { |
| 345 it->second->RemoveObserver(observer); | 333 it->second->RemoveObserver(observer); |
| 346 } | 334 } |
| 347 } | 335 } |
| 348 | 336 |
| 349 void StorageMonitor::RemoveObserverForFilter( | |
| 350 StorageObserver* observer, const StorageObserver::Filter& filter) { | |
| 351 auto it = storage_type_observers_map_.find(filter.storage_type); | |
| 352 if (it == storage_type_observers_map_.end()) | |
| 353 return; | |
| 354 | |
| 355 it->second->RemoveObserverForFilter(observer, filter); | |
| 356 } | |
| 357 | |
| 358 const StorageTypeObservers* StorageMonitor::GetStorageTypeObservers( | 337 const StorageTypeObservers* StorageMonitor::GetStorageTypeObservers( |
| 359 StorageType storage_type) const { | 338 StorageType storage_type) const { |
| 360 auto it = storage_type_observers_map_.find(storage_type); | 339 auto it = storage_type_observers_map_.find(storage_type); |
| 361 if (it != storage_type_observers_map_.end()) | 340 if (it != storage_type_observers_map_.end()) |
| 362 return it->second.get(); | 341 return it->second.get(); |
| 363 | 342 |
| 364 return nullptr; | 343 return nullptr; |
| 365 } | 344 } |
| 366 | 345 |
| 367 void StorageMonitor::NotifyUsageChange(const StorageObserver::Filter& filter, | 346 void StorageMonitor::NotifyUsageChange(const StorageObserver::Filter& filter, |
| 368 int64_t delta) { | 347 int64_t delta) { |
| 369 // Check preconditions. | 348 // Check preconditions. |
| 370 if (filter.storage_type == kStorageTypeUnknown || | 349 if (filter.storage_type == kStorageTypeUnknown || |
| 371 filter.storage_type == kStorageTypeQuotaNotManaged || | 350 filter.storage_type == kStorageTypeQuotaNotManaged || |
| 372 filter.origin.is_empty()) { | 351 filter.origin.is_empty()) { |
| 373 NOTREACHED(); | 352 NOTREACHED(); |
| 374 return; | 353 return; |
| 375 } | 354 } |
| 376 | 355 |
| 377 auto it = storage_type_observers_map_.find(filter.storage_type); | 356 auto it = storage_type_observers_map_.find(filter.storage_type); |
| 378 if (it == storage_type_observers_map_.end()) | 357 if (it == storage_type_observers_map_.end()) |
| 379 return; | 358 return; |
| 380 | 359 |
| 381 it->second->NotifyUsageChange(filter, delta); | 360 it->second->NotifyUsageChange(filter, delta); |
| 382 } | 361 } |
| 383 | 362 |
| 384 } // namespace storage | 363 } // namespace storage |
| OLD | NEW |