| 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/quota_manager.h" | 5 #include "webkit/quota/quota_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/stl_util.h" | |
| 19 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 20 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 21 #include "base/time.h" | 20 #include "base/time.h" |
| 22 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 23 #include "webkit/quota/quota_database.h" | 22 #include "webkit/quota/quota_database.h" |
| 24 #include "webkit/quota/quota_temporary_storage_evictor.h" | 23 #include "webkit/quota/quota_temporary_storage_evictor.h" |
| 25 #include "webkit/quota/quota_types.h" | 24 #include "webkit/quota/quota_types.h" |
| 26 #include "webkit/quota/usage_tracker.h" | 25 #include "webkit/quota/usage_tracker.h" |
| 27 | 26 |
| 28 #define UMA_HISTOGRAM_MBYTES(name, sample) \ | 27 #define UMA_HISTOGRAM_MBYTES(name, sample) \ |
| 29 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 28 UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 30 (name), static_cast<int>((sample) / kMBytes), \ | 29 (name), static_cast<int>((sample) / kMBytes), \ |
| 31 1, 10 * 1024 * 1024 /* 10TB */, 100) | 30 1, 10 * 1024 * 1024 /* 10TB */, 100) |
| 32 | 31 |
| 33 using base::ScopedCallbackFactory; | |
| 34 | |
| 35 namespace quota { | 32 namespace quota { |
| 36 | 33 |
| 37 namespace { | 34 namespace { |
| 38 | 35 |
| 39 const char kEnableQuotaEviction[] = "enable-quota-eviction"; | 36 const char kEnableQuotaEviction[] = "enable-quota-eviction"; |
| 40 const int64 kMBytes = 1024 * 1024; | 37 const int64 kMBytes = 1024 * 1024; |
| 41 const int kMinutesInMilliSeconds = 60 * 1000; | 38 const int kMinutesInMilliSeconds = 60 * 1000; |
| 42 | 39 |
| 43 // Returns the initial size of the temporary storage quota. | 40 // Returns the initial size of the temporary storage quota. |
| 44 // (This just gives a default initial size; once its initial size is determined | 41 // (This just gives a default initial size; once its initial size is determined |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 30 * kMinutesInMilliSeconds; | 104 30 * kMinutesInMilliSeconds; |
| 108 | 105 |
| 109 const base::TimeDelta QuotaManager::kReportHistogramInterval = | 106 const base::TimeDelta QuotaManager::kReportHistogramInterval = |
| 110 base::TimeDelta::FromMilliseconds(60 * 60 * 1000); // 1 hour | 107 base::TimeDelta::FromMilliseconds(60 * 60 * 1000); // 1 hour |
| 111 | 108 |
| 112 // This class is for posting GetUsage/GetQuota tasks, gathering | 109 // This class is for posting GetUsage/GetQuota tasks, gathering |
| 113 // results and dispatching GetAndQuota callbacks. | 110 // results and dispatching GetAndQuota callbacks. |
| 114 // This class is self-destructed. | 111 // This class is self-destructed. |
| 115 class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask { | 112 class QuotaManager::UsageAndQuotaDispatcherTask : public QuotaTask { |
| 116 public: | 113 public: |
| 117 typedef std::deque<GetUsageAndQuotaCallback*> CallbackList; | 114 typedef std::deque<GetUsageAndQuotaCallback> CallbackList; |
| 118 | 115 |
| 119 static UsageAndQuotaDispatcherTask* Create( | 116 static UsageAndQuotaDispatcherTask* Create( |
| 120 QuotaManager* manager, const std::string& host, StorageType type); | 117 QuotaManager* manager, const std::string& host, StorageType type); |
| 121 | 118 |
| 122 // Returns true if it is the first call for this task; which means | 119 // Returns true if it is the first call for this task; which means |
| 123 // the caller needs to call Start(). | 120 // the caller needs to call Start(). |
| 124 bool AddCallback(GetUsageAndQuotaCallback* callback, bool unlimited) { | 121 bool AddCallback(GetUsageAndQuotaCallback callback, bool unlimited) { |
| 125 if (unlimited) | 122 if (unlimited) |
| 126 unlimited_callbacks_.push_back(callback); | 123 unlimited_callbacks_.push_back(callback); |
| 127 else | 124 else |
| 128 callbacks_.push_back(callback); | 125 callbacks_.push_back(callback); |
| 129 return (callbacks_.size() + unlimited_callbacks_.size() == 1); | 126 return (callbacks_.size() + unlimited_callbacks_.size() == 1); |
| 130 } | 127 } |
| 131 | 128 |
| 132 void DidGetGlobalUsage(StorageType type, int64 usage, | 129 void DidGetGlobalUsage(StorageType type, int64 usage, |
| 133 int64 unlimited_usage) { | 130 int64 unlimited_usage) { |
| 134 DCHECK_EQ(type_, type); | 131 DCHECK_EQ(type_, type); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 StorageType type) | 171 StorageType type) |
| 175 : QuotaTask(manager), | 172 : QuotaTask(manager), |
| 176 host_(host), | 173 host_(host), |
| 177 type_(type), | 174 type_(type), |
| 178 quota_(-1), | 175 quota_(-1), |
| 179 global_usage_(-1), | 176 global_usage_(-1), |
| 180 global_unlimited_usage_(-1), | 177 global_unlimited_usage_(-1), |
| 181 host_usage_(-1), | 178 host_usage_(-1), |
| 182 quota_status_(kQuotaStatusUnknown), | 179 quota_status_(kQuotaStatusUnknown), |
| 183 waiting_callbacks_(1), | 180 waiting_callbacks_(1), |
| 184 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} | 181 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
| 185 | 182 |
| 186 virtual ~UsageAndQuotaDispatcherTask() { | 183 virtual ~UsageAndQuotaDispatcherTask() {} |
| 187 STLDeleteContainerPointers(callbacks_.begin(), callbacks_.end()); | |
| 188 STLDeleteContainerPointers(unlimited_callbacks_.begin(), | |
| 189 unlimited_callbacks_.end()); | |
| 190 } | |
| 191 | 184 |
| 192 // Subclasses must implement them. | 185 // Subclasses must implement them. |
| 193 virtual void RunBody() = 0; | 186 virtual void RunBody() = 0; |
| 194 virtual void DispatchCallbacks() = 0; | 187 virtual void DispatchCallbacks() = 0; |
| 195 | 188 |
| 196 virtual void Run() OVERRIDE { | 189 virtual void Run() OVERRIDE { |
| 197 RunBody(); | 190 RunBody(); |
| 198 // We initialize waiting_callbacks to 1 so that we won't run | 191 // We initialize waiting_callbacks to 1 so that we won't run |
| 199 // the completion callback until here even some of the callbacks | 192 // the completion callback until here even some of the callbacks |
| 200 // are dispatched synchronously. | 193 // are dispatched synchronously. |
| 201 CheckCompleted(); | 194 CheckCompleted(); |
| 202 } | 195 } |
| 203 | 196 |
| 204 virtual void Aborted() OVERRIDE { | 197 virtual void Aborted() OVERRIDE { |
| 205 CallCallbacksAndClear(&callbacks_, kQuotaErrorAbort, 0, 0); | 198 CallCallbacksAndClear(&callbacks_, kQuotaErrorAbort, 0, 0); |
| 206 CallCallbacksAndClear(&unlimited_callbacks_, kQuotaErrorAbort, 0, 0); | 199 CallCallbacksAndClear(&unlimited_callbacks_, kQuotaErrorAbort, 0, 0); |
| 207 DeleteSoon(); | 200 DeleteSoon(); |
| 208 } | 201 } |
| 209 | 202 |
| 210 virtual void Completed() OVERRIDE { | 203 virtual void Completed() OVERRIDE { |
| 211 DeleteSoon(); | 204 DeleteSoon(); |
| 212 } | 205 } |
| 213 | 206 |
| 214 void CallCallbacksAndClear( | 207 void CallCallbacksAndClear( |
| 215 CallbackList* callbacks, QuotaStatusCode status, | 208 CallbackList* callbacks, QuotaStatusCode status, |
| 216 int64 usage, int64 quota) { | 209 int64 usage, int64 quota) { |
| 217 for (CallbackList::iterator iter = callbacks->begin(); | 210 for (CallbackList::iterator iter = callbacks->begin(); |
| 218 iter != callbacks->end(); ++iter) { | 211 iter != callbacks->end(); ++iter) { |
| 219 (*iter)->Run(status, usage, quota); | 212 iter->Run(status, usage, quota); |
| 220 delete *iter; | |
| 221 } | 213 } |
| 222 callbacks->clear(); | 214 callbacks->clear(); |
| 223 } | 215 } |
| 224 | 216 |
| 225 QuotaManager* manager() const { | 217 QuotaManager* manager() const { |
| 226 return static_cast<QuotaManager*>(observer()); | 218 return static_cast<QuotaManager*>(observer()); |
| 227 } | 219 } |
| 228 | 220 |
| 229 std::string host() const { return host_; } | 221 std::string host() const { return host_; } |
| 230 StorageType type() const { return type_; } | 222 StorageType type() const { return type_; } |
| 231 int64 quota() const { return quota_; } | 223 int64 quota() const { return quota_; } |
| 232 int64 global_usage() const { return global_usage_; } | 224 int64 global_usage() const { return global_usage_; } |
| 233 int64 global_unlimited_usage() const { return global_unlimited_usage_; } | 225 int64 global_unlimited_usage() const { return global_unlimited_usage_; } |
| 234 int64 host_usage() const { return host_usage_; } | 226 int64 host_usage() const { return host_usage_; } |
| 235 QuotaStatusCode quota_status() const { return quota_status_; } | 227 QuotaStatusCode quota_status() const { return quota_status_; } |
| 236 CallbackList& callbacks() { return callbacks_; } | 228 CallbackList& callbacks() { return callbacks_; } |
| 237 CallbackList& unlimited_callbacks() { return unlimited_callbacks_; } | 229 CallbackList& unlimited_callbacks() { return unlimited_callbacks_; } |
| 238 | 230 |
| 239 // Subclasses must call following methods to create a new 'waitable' | 231 // Subclasses must call following methods to create a new 'waitable' |
| 240 // callback, which decrements waiting_callbacks when it is called. | 232 // callback, which decrements waiting_callbacks when it is called. |
| 241 GlobalUsageCallback* NewWaitableGlobalUsageCallback() { | 233 GlobalUsageCallback NewWaitableGlobalUsageCallback() { |
| 242 ++waiting_callbacks_; | 234 ++waiting_callbacks_; |
| 243 return callback_factory_.NewCallback( | 235 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalUsage, |
| 244 &UsageAndQuotaDispatcherTask::DidGetGlobalUsage); | 236 weak_factory_.GetWeakPtr()); |
| 245 } | 237 } |
| 246 HostUsageCallback* NewWaitableHostUsageCallback() { | 238 HostUsageCallback NewWaitableHostUsageCallback() { |
| 247 ++waiting_callbacks_; | 239 ++waiting_callbacks_; |
| 248 return callback_factory_.NewCallback( | 240 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostUsage, |
| 249 &UsageAndQuotaDispatcherTask::DidGetHostUsage); | 241 weak_factory_.GetWeakPtr()); |
| 250 } | 242 } |
| 251 QuotaCallback* NewWaitableGlobalQuotaCallback() { | 243 QuotaCallback NewWaitableGlobalQuotaCallback() { |
| 252 ++waiting_callbacks_; | 244 ++waiting_callbacks_; |
| 253 return callback_factory_.NewCallback( | 245 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetGlobalQuota, |
| 254 &UsageAndQuotaDispatcherTask::DidGetGlobalQuota); | 246 weak_factory_.GetWeakPtr()); |
| 255 } | 247 } |
| 256 HostQuotaCallback* NewWaitableHostQuotaCallback() { | 248 HostQuotaCallback NewWaitableHostQuotaCallback() { |
| 257 ++waiting_callbacks_; | 249 ++waiting_callbacks_; |
| 258 return callback_factory_.NewCallback( | 250 return base::Bind(&UsageAndQuotaDispatcherTask::DidGetHostQuota, |
| 259 &UsageAndQuotaDispatcherTask::DidGetHostQuota); | 251 weak_factory_.GetWeakPtr()); |
| 260 } | 252 } |
| 261 | 253 |
| 262 private: | 254 private: |
| 263 void CheckCompleted() { | 255 void CheckCompleted() { |
| 264 if (--waiting_callbacks_ <= 0) { | 256 if (--waiting_callbacks_ <= 0) { |
| 265 DispatchCallbacks(); | 257 DispatchCallbacks(); |
| 266 DCHECK(callbacks_.empty()); | 258 DCHECK(callbacks_.empty()); |
| 267 DCHECK(unlimited_callbacks_.empty()); | 259 DCHECK(unlimited_callbacks_.empty()); |
| 268 | 260 |
| 269 UsageAndQuotaDispatcherTaskMap& dispatcher_map = | 261 UsageAndQuotaDispatcherTaskMap& dispatcher_map = |
| 270 manager()->usage_and_quota_dispatchers_; | 262 manager()->usage_and_quota_dispatchers_; |
| 271 DCHECK(dispatcher_map.find(std::make_pair(host_, type_)) != | 263 DCHECK(dispatcher_map.find(std::make_pair(host_, type_)) != |
| 272 dispatcher_map.end()); | 264 dispatcher_map.end()); |
| 273 dispatcher_map.erase(std::make_pair(host_, type_)); | 265 dispatcher_map.erase(std::make_pair(host_, type_)); |
| 274 CallCompleted(); | 266 CallCompleted(); |
| 275 } | 267 } |
| 276 } | 268 } |
| 277 | 269 |
| 278 const std::string host_; | 270 const std::string host_; |
| 279 const StorageType type_; | 271 const StorageType type_; |
| 280 int64 quota_; | 272 int64 quota_; |
| 281 int64 global_usage_; | 273 int64 global_usage_; |
| 282 int64 global_unlimited_usage_; | 274 int64 global_unlimited_usage_; |
| 283 int64 host_usage_; | 275 int64 host_usage_; |
| 284 QuotaStatusCode quota_status_; | 276 QuotaStatusCode quota_status_; |
| 285 CallbackList callbacks_; | 277 CallbackList callbacks_; |
| 286 CallbackList unlimited_callbacks_; | 278 CallbackList unlimited_callbacks_; |
| 287 int waiting_callbacks_; | 279 int waiting_callbacks_; |
| 288 ScopedCallbackFactory<UsageAndQuotaDispatcherTask> callback_factory_; | 280 base::WeakPtrFactory<UsageAndQuotaDispatcherTask> weak_factory_; |
| 289 | 281 |
| 290 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaDispatcherTask); | 282 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaDispatcherTask); |
| 291 }; | 283 }; |
| 292 | 284 |
| 293 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporary | 285 class QuotaManager::UsageAndQuotaDispatcherTaskForTemporary |
| 294 : public QuotaManager::UsageAndQuotaDispatcherTask { | 286 : public QuotaManager::UsageAndQuotaDispatcherTask { |
| 295 public: | 287 public: |
| 296 UsageAndQuotaDispatcherTaskForTemporary( | 288 UsageAndQuotaDispatcherTaskForTemporary( |
| 297 QuotaManager* manager, const std::string& host) | 289 QuotaManager* manager, const std::string& host) |
| 298 : UsageAndQuotaDispatcherTask(manager, host, kStorageTypeTemporary) {} | 290 : UsageAndQuotaDispatcherTask(manager, host, kStorageTypeTemporary) {} |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 NOTREACHED(); | 364 NOTREACHED(); |
| 373 } | 365 } |
| 374 return NULL; | 366 return NULL; |
| 375 } | 367 } |
| 376 | 368 |
| 377 class QuotaManager::OriginDataDeleter : public QuotaTask { | 369 class QuotaManager::OriginDataDeleter : public QuotaTask { |
| 378 public: | 370 public: |
| 379 OriginDataDeleter(QuotaManager* manager, | 371 OriginDataDeleter(QuotaManager* manager, |
| 380 const GURL& origin, | 372 const GURL& origin, |
| 381 StorageType type, | 373 StorageType type, |
| 382 StatusCallback* callback) | 374 StatusCallback callback) |
| 383 : QuotaTask(manager), | 375 : QuotaTask(manager), |
| 384 origin_(origin), | 376 origin_(origin), |
| 385 type_(type), | 377 type_(type), |
| 386 error_count_(0), | 378 error_count_(0), |
| 387 remaining_clients_(-1), | 379 remaining_clients_(-1), |
| 388 callback_(callback), | 380 callback_(callback), |
| 389 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} | 381 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} |
| 390 | 382 |
| 391 protected: | 383 protected: |
| 392 virtual void Run() OVERRIDE { | 384 virtual void Run() OVERRIDE { |
| 393 error_count_ = 0; | 385 error_count_ = 0; |
| 394 remaining_clients_ = manager()->clients_.size(); | 386 remaining_clients_ = manager()->clients_.size(); |
| 395 for (QuotaClientList::iterator iter = manager()->clients_.begin(); | 387 for (QuotaClientList::iterator iter = manager()->clients_.begin(); |
| 396 iter != manager()->clients_.end(); ++iter) { | 388 iter != manager()->clients_.end(); ++iter) { |
| 397 (*iter)->DeleteOriginData(origin_, type_, callback_factory_.NewCallback( | 389 (*iter)->DeleteOriginData( |
| 398 &OriginDataDeleter::DidDeleteOriginData)); | 390 origin_, type_, |
| 391 base::Bind(&OriginDataDeleter::DidDeleteOriginData, |
| 392 weak_factory_.GetWeakPtr())); |
| 399 } | 393 } |
| 400 } | 394 } |
| 401 | 395 |
| 402 virtual void Completed() OVERRIDE { | 396 virtual void Completed() OVERRIDE { |
| 403 if (error_count_ == 0) { | 397 if (error_count_ == 0) { |
| 404 manager()->DeleteOriginFromDatabase(origin_, type_); | 398 manager()->DeleteOriginFromDatabase(origin_, type_); |
| 405 callback_->Run(kQuotaStatusOk); | 399 callback_.Run(kQuotaStatusOk); |
| 406 } else { | 400 } else { |
| 407 callback_->Run(kQuotaErrorInvalidModification); | 401 callback_.Run(kQuotaErrorInvalidModification); |
| 408 } | 402 } |
| 409 DeleteSoon(); | 403 DeleteSoon(); |
| 410 } | 404 } |
| 411 | 405 |
| 412 virtual void Aborted() OVERRIDE { | 406 virtual void Aborted() OVERRIDE { |
| 413 callback_->Run(kQuotaErrorAbort); | 407 callback_.Run(kQuotaErrorAbort); |
| 414 DeleteSoon(); | 408 DeleteSoon(); |
| 415 } | 409 } |
| 416 | 410 |
| 417 void DidDeleteOriginData(QuotaStatusCode status) { | 411 void DidDeleteOriginData(QuotaStatusCode status) { |
| 418 DCHECK_GT(remaining_clients_, 0); | 412 DCHECK_GT(remaining_clients_, 0); |
| 419 | 413 |
| 420 if (status != kQuotaStatusOk) | 414 if (status != kQuotaStatusOk) |
| 421 ++error_count_; | 415 ++error_count_; |
| 422 | 416 |
| 423 if (--remaining_clients_ == 0) | 417 if (--remaining_clients_ == 0) |
| 424 CallCompleted(); | 418 CallCompleted(); |
| 425 } | 419 } |
| 426 | 420 |
| 427 QuotaManager* manager() const { | 421 QuotaManager* manager() const { |
| 428 return static_cast<QuotaManager*>(observer()); | 422 return static_cast<QuotaManager*>(observer()); |
| 429 } | 423 } |
| 430 | 424 |
| 431 GURL origin_; | 425 GURL origin_; |
| 432 StorageType type_; | 426 StorageType type_; |
| 433 int error_count_; | 427 int error_count_; |
| 434 int remaining_clients_; | 428 int remaining_clients_; |
| 435 scoped_ptr<StatusCallback> callback_; | 429 StatusCallback callback_; |
| 436 | 430 |
| 437 ScopedCallbackFactory<OriginDataDeleter> callback_factory_; | 431 base::WeakPtrFactory<OriginDataDeleter> weak_factory_; |
| 438 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter); | 432 DISALLOW_COPY_AND_ASSIGN(OriginDataDeleter); |
| 439 }; | 433 }; |
| 440 | 434 |
| 441 class QuotaManager::DatabaseTaskBase : public QuotaThreadTask { | 435 class QuotaManager::DatabaseTaskBase : public QuotaThreadTask { |
| 442 public: | 436 public: |
| 443 explicit DatabaseTaskBase(QuotaManager* manager) | 437 explicit DatabaseTaskBase(QuotaManager* manager) |
| 444 : QuotaThreadTask(manager, manager->db_thread_), | 438 : QuotaThreadTask(manager, manager->db_thread_), |
| 445 manager_(manager), | 439 manager_(manager), |
| 446 database_(manager->database_.get()), | 440 database_(manager->database_.get()), |
| 447 db_disabled_(false) { | 441 db_disabled_(false) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 bool need_initialize_origins_; | 513 bool need_initialize_origins_; |
| 520 int64 temporary_storage_quota_; | 514 int64 temporary_storage_quota_; |
| 521 }; | 515 }; |
| 522 | 516 |
| 523 class QuotaManager::UpdateTemporaryGlobalQuotaTask | 517 class QuotaManager::UpdateTemporaryGlobalQuotaTask |
| 524 : public QuotaManager::DatabaseTaskBase { | 518 : public QuotaManager::DatabaseTaskBase { |
| 525 public: | 519 public: |
| 526 UpdateTemporaryGlobalQuotaTask( | 520 UpdateTemporaryGlobalQuotaTask( |
| 527 QuotaManager* manager, | 521 QuotaManager* manager, |
| 528 int64 new_quota, | 522 int64 new_quota, |
| 529 QuotaCallback* callback) | 523 QuotaCallback callback) |
| 530 : DatabaseTaskBase(manager), | 524 : DatabaseTaskBase(manager), |
| 531 new_quota_(new_quota), | 525 new_quota_(new_quota), |
| 532 callback_(callback) { | 526 callback_(callback) { |
| 533 DCHECK_GE(new_quota, 0); | 527 DCHECK_GE(new_quota, 0); |
| 534 } | 528 } |
| 535 | 529 |
| 536 protected: | 530 protected: |
| 537 virtual void RunOnTargetThread() OVERRIDE { | 531 virtual void RunOnTargetThread() OVERRIDE { |
| 538 if (!database()->SetGlobalQuota(kStorageTypeTemporary, new_quota_)) { | 532 if (!database()->SetGlobalQuota(kStorageTypeTemporary, new_quota_)) { |
| 539 set_db_disabled(true); | 533 set_db_disabled(true); |
| 540 new_quota_ = 0; | 534 new_quota_ = 0; |
| 541 } | 535 } |
| 542 } | 536 } |
| 543 | 537 |
| 544 virtual void DatabaseTaskCompleted() OVERRIDE { | 538 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 545 callback_->Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk, | 539 callback_.Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk, |
| 546 kStorageTypeTemporary, new_quota_); | 540 kStorageTypeTemporary, new_quota_); |
| 547 if (!db_disabled()) { | 541 if (!db_disabled()) { |
| 548 manager()->temporary_global_quota_ = new_quota_; | 542 manager()->temporary_global_quota_ = new_quota_; |
| 549 } | 543 } |
| 550 } | 544 } |
| 551 | 545 |
| 552 private: | 546 private: |
| 553 int64 new_quota_; | 547 int64 new_quota_; |
| 554 scoped_ptr<QuotaCallback> callback_; | 548 QuotaCallback callback_; |
| 555 }; | 549 }; |
| 556 | 550 |
| 557 class QuotaManager::GetPersistentHostQuotaTask | 551 class QuotaManager::GetPersistentHostQuotaTask |
| 558 : public QuotaManager::DatabaseTaskBase { | 552 : public QuotaManager::DatabaseTaskBase { |
| 559 public: | 553 public: |
| 560 GetPersistentHostQuotaTask( | 554 GetPersistentHostQuotaTask( |
| 561 QuotaManager* manager, | 555 QuotaManager* manager, |
| 562 const std::string& host, | 556 const std::string& host, |
| 563 HostQuotaCallback* callback) | 557 HostQuotaCallback callback) |
| 564 : DatabaseTaskBase(manager), | 558 : DatabaseTaskBase(manager), |
| 565 host_(host), | 559 host_(host), |
| 566 quota_(-1), | 560 quota_(-1), |
| 567 callback_(callback) { | 561 callback_(callback) { |
| 568 } | 562 } |
| 569 protected: | 563 protected: |
| 570 virtual void RunOnTargetThread() OVERRIDE { | 564 virtual void RunOnTargetThread() OVERRIDE { |
| 571 if (!database()->GetHostQuota(host_, kStorageTypePersistent, "a_)) | 565 if (!database()->GetHostQuota(host_, kStorageTypePersistent, "a_)) |
| 572 quota_ = 0; | 566 quota_ = 0; |
| 573 } | 567 } |
| 574 virtual void DatabaseTaskCompleted() OVERRIDE { | 568 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 575 callback_->Run(kQuotaStatusOk, | 569 callback_.Run(kQuotaStatusOk, |
| 576 host_, kStorageTypePersistent, quota_); | 570 host_, kStorageTypePersistent, quota_); |
| 577 } | 571 } |
| 578 private: | 572 private: |
| 579 std::string host_; | 573 std::string host_; |
| 580 int64 quota_; | 574 int64 quota_; |
| 581 scoped_ptr<HostQuotaCallback> callback_; | 575 HostQuotaCallback callback_; |
| 582 }; | 576 }; |
| 583 | 577 |
| 584 class QuotaManager::UpdatePersistentHostQuotaTask | 578 class QuotaManager::UpdatePersistentHostQuotaTask |
| 585 : public QuotaManager::DatabaseTaskBase { | 579 : public QuotaManager::DatabaseTaskBase { |
| 586 public: | 580 public: |
| 587 UpdatePersistentHostQuotaTask( | 581 UpdatePersistentHostQuotaTask( |
| 588 QuotaManager* manager, | 582 QuotaManager* manager, |
| 589 const std::string& host, | 583 const std::string& host, |
| 590 int new_quota, | 584 int new_quota, |
| 591 HostQuotaCallback* callback) | 585 HostQuotaCallback callback) |
| 592 : DatabaseTaskBase(manager), | 586 : DatabaseTaskBase(manager), |
| 593 host_(host), | 587 host_(host), |
| 594 new_quota_(new_quota), | 588 new_quota_(new_quota), |
| 595 callback_(callback) { | 589 callback_(callback) { |
| 596 DCHECK_GE(new_quota_, 0); | 590 DCHECK_GE(new_quota_, 0); |
| 597 } | 591 } |
| 598 protected: | 592 protected: |
| 599 virtual void RunOnTargetThread() OVERRIDE { | 593 virtual void RunOnTargetThread() OVERRIDE { |
| 600 if (!database()->SetHostQuota(host_, kStorageTypePersistent, new_quota_)) { | 594 if (!database()->SetHostQuota(host_, kStorageTypePersistent, new_quota_)) { |
| 601 set_db_disabled(true); | 595 set_db_disabled(true); |
| 602 new_quota_ = 0; | 596 new_quota_ = 0; |
| 603 } | 597 } |
| 604 } | 598 } |
| 605 | 599 |
| 606 virtual void DatabaseTaskCompleted() OVERRIDE { | 600 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 607 callback_->Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk, | 601 callback_.Run(db_disabled() ? kQuotaErrorInvalidAccess : kQuotaStatusOk, |
| 608 host_, kStorageTypePersistent, new_quota_); | 602 host_, kStorageTypePersistent, new_quota_); |
| 609 } | 603 } |
| 610 | 604 |
| 611 virtual void Aborted() OVERRIDE { | 605 virtual void Aborted() OVERRIDE { |
| 612 callback_.reset(); | 606 callback_.Reset(); |
| 613 } | 607 } |
| 614 | 608 |
| 615 private: | 609 private: |
| 616 std::string host_; | 610 std::string host_; |
| 617 int64 new_quota_; | 611 int64 new_quota_; |
| 618 scoped_ptr<HostQuotaCallback> callback_; | 612 HostQuotaCallback callback_; |
| 619 }; | 613 }; |
| 620 | 614 |
| 621 class QuotaManager::GetLRUOriginTask | 615 class QuotaManager::GetLRUOriginTask |
| 622 : public QuotaManager::DatabaseTaskBase { | 616 : public QuotaManager::DatabaseTaskBase { |
| 623 public: | 617 public: |
| 624 GetLRUOriginTask( | 618 GetLRUOriginTask( |
| 625 QuotaManager* manager, | 619 QuotaManager* manager, |
| 626 StorageType type, | 620 StorageType type, |
| 627 const std::map<GURL, int>& origins_in_use, | 621 const std::map<GURL, int>& origins_in_use, |
| 628 const std::map<GURL, int>& origins_in_error, | 622 const std::map<GURL, int>& origins_in_error, |
| 629 GetLRUOriginCallback *callback) | 623 GetLRUOriginCallback callback) |
| 630 : DatabaseTaskBase(manager), | 624 : DatabaseTaskBase(manager), |
| 631 type_(type), | 625 type_(type), |
| 632 callback_(callback), | 626 callback_(callback), |
| 633 special_storage_policy_(manager->special_storage_policy_) { | 627 special_storage_policy_(manager->special_storage_policy_) { |
| 634 for (std::map<GURL, int>::const_iterator p = origins_in_use.begin(); | 628 for (std::map<GURL, int>::const_iterator p = origins_in_use.begin(); |
| 635 p != origins_in_use.end(); | 629 p != origins_in_use.end(); |
| 636 ++p) { | 630 ++p) { |
| 637 if (p->second > 0) | 631 if (p->second > 0) |
| 638 exceptions_.insert(p->first); | 632 exceptions_.insert(p->first); |
| 639 } | 633 } |
| 640 for (std::map<GURL, int>::const_iterator p = origins_in_error.begin(); | 634 for (std::map<GURL, int>::const_iterator p = origins_in_error.begin(); |
| 641 p != origins_in_error.end(); | 635 p != origins_in_error.end(); |
| 642 ++p) { | 636 ++p) { |
| 643 if (p->second > QuotaManager::kThresholdOfErrorsToBeBlacklisted) | 637 if (p->second > QuotaManager::kThresholdOfErrorsToBeBlacklisted) |
| 644 exceptions_.insert(p->first); | 638 exceptions_.insert(p->first); |
| 645 } | 639 } |
| 646 } | 640 } |
| 647 | 641 |
| 648 protected: | 642 protected: |
| 649 virtual void RunOnTargetThread() OVERRIDE { | 643 virtual void RunOnTargetThread() OVERRIDE { |
| 650 if (!database()->GetLRUOrigin(type_, exceptions_, | 644 if (!database()->GetLRUOrigin(type_, exceptions_, |
| 651 special_storage_policy_, &url_)) | 645 special_storage_policy_, &url_)) |
| 652 set_db_disabled(true); | 646 set_db_disabled(true); |
| 653 } | 647 } |
| 654 | 648 |
| 655 virtual void DatabaseTaskCompleted() OVERRIDE { | 649 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 656 callback_->Run(url_); | 650 callback_.Run(url_); |
| 657 } | 651 } |
| 658 | 652 |
| 659 virtual void Aborted() OVERRIDE { | 653 virtual void Aborted() OVERRIDE { |
| 660 callback_.reset(); | 654 callback_.Reset(); |
| 661 } | 655 } |
| 662 | 656 |
| 663 private: | 657 private: |
| 664 StorageType type_; | 658 StorageType type_; |
| 665 std::set<GURL> exceptions_; | 659 std::set<GURL> exceptions_; |
| 666 scoped_ptr<GetLRUOriginCallback> callback_; | 660 GetLRUOriginCallback callback_; |
| 667 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 661 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 668 GURL url_; | 662 GURL url_; |
| 669 }; | 663 }; |
| 670 | 664 |
| 671 class QuotaManager::DeleteOriginInfo | 665 class QuotaManager::DeleteOriginInfo |
| 672 : public QuotaManager::DatabaseTaskBase { | 666 : public QuotaManager::DatabaseTaskBase { |
| 673 public: | 667 public: |
| 674 DeleteOriginInfo( | 668 DeleteOriginInfo( |
| 675 QuotaManager* manager, | 669 QuotaManager* manager, |
| 676 const GURL& origin, | 670 const GURL& origin, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 std::set<GURL> origins_; | 720 std::set<GURL> origins_; |
| 727 bool has_registered_origins_; | 721 bool has_registered_origins_; |
| 728 }; | 722 }; |
| 729 | 723 |
| 730 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask { | 724 class QuotaManager::AvailableSpaceQueryTask : public QuotaThreadTask { |
| 731 public: | 725 public: |
| 732 AvailableSpaceQueryTask( | 726 AvailableSpaceQueryTask( |
| 733 QuotaManager* manager, | 727 QuotaManager* manager, |
| 734 scoped_refptr<base::MessageLoopProxy> db_message_loop, | 728 scoped_refptr<base::MessageLoopProxy> db_message_loop, |
| 735 const FilePath& profile_path, | 729 const FilePath& profile_path, |
| 736 AvailableSpaceCallback* callback) | 730 AvailableSpaceCallback callback) |
| 737 : QuotaThreadTask(manager, db_message_loop), | 731 : QuotaThreadTask(manager, db_message_loop), |
| 738 profile_path_(profile_path), | 732 profile_path_(profile_path), |
| 739 space_(-1), | 733 space_(-1), |
| 740 callback_(callback) {} | 734 callback_(callback) {} |
| 741 virtual ~AvailableSpaceQueryTask() {} | 735 virtual ~AvailableSpaceQueryTask() {} |
| 742 | 736 |
| 743 protected: | 737 protected: |
| 744 virtual void RunOnTargetThread() OVERRIDE { | 738 virtual void RunOnTargetThread() OVERRIDE { |
| 745 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); | 739 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); |
| 746 } | 740 } |
| 747 | 741 |
| 748 virtual void Aborted() OVERRIDE { | 742 virtual void Aborted() OVERRIDE { |
| 749 callback_->Run(kQuotaErrorAbort, -1); | 743 callback_.Run(kQuotaErrorAbort, -1); |
| 750 } | 744 } |
| 751 | 745 |
| 752 virtual void Completed() OVERRIDE { | 746 virtual void Completed() OVERRIDE { |
| 753 callback_->Run(kQuotaStatusOk, space_); | 747 callback_.Run(kQuotaStatusOk, space_); |
| 754 } | 748 } |
| 755 | 749 |
| 756 private: | 750 private: |
| 757 FilePath profile_path_; | 751 FilePath profile_path_; |
| 758 int64 space_; | 752 int64 space_; |
| 759 scoped_ptr<AvailableSpaceCallback> callback_; | 753 AvailableSpaceCallback callback_; |
| 760 }; | 754 }; |
| 761 | 755 |
| 762 class QuotaManager::UpdateAccessTimeTask | 756 class QuotaManager::UpdateAccessTimeTask |
| 763 : public QuotaManager::DatabaseTaskBase { | 757 : public QuotaManager::DatabaseTaskBase { |
| 764 public: | 758 public: |
| 765 UpdateAccessTimeTask( | 759 UpdateAccessTimeTask( |
| 766 QuotaManager* manager, | 760 QuotaManager* manager, |
| 767 const GURL& origin, | 761 const GURL& origin, |
| 768 StorageType type, | 762 StorageType type, |
| 769 base::Time accessed_time) | 763 base::Time accessed_time) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 base::Time modified_time_; | 808 base::Time modified_time_; |
| 815 }; | 809 }; |
| 816 | 810 |
| 817 class QuotaManager::GetModifiedSinceTask | 811 class QuotaManager::GetModifiedSinceTask |
| 818 : public QuotaManager::DatabaseTaskBase { | 812 : public QuotaManager::DatabaseTaskBase { |
| 819 public: | 813 public: |
| 820 GetModifiedSinceTask( | 814 GetModifiedSinceTask( |
| 821 QuotaManager* manager, | 815 QuotaManager* manager, |
| 822 StorageType type, | 816 StorageType type, |
| 823 base::Time modified_since, | 817 base::Time modified_since, |
| 824 GetOriginsCallback* callback) | 818 GetOriginsCallback callback) |
| 825 : DatabaseTaskBase(manager), | 819 : DatabaseTaskBase(manager), |
| 826 type_(type), | 820 type_(type), |
| 827 modified_since_(modified_since), | 821 modified_since_(modified_since), |
| 828 callback_(callback) {} | 822 callback_(callback) {} |
| 829 | 823 |
| 830 protected: | 824 protected: |
| 831 virtual void RunOnTargetThread() OVERRIDE { | 825 virtual void RunOnTargetThread() OVERRIDE { |
| 832 if (!database()->GetOriginsModifiedSince( | 826 if (!database()->GetOriginsModifiedSince( |
| 833 type_, &origins_, modified_since_)) { | 827 type_, &origins_, modified_since_)) { |
| 834 set_db_disabled(true); | 828 set_db_disabled(true); |
| 835 } | 829 } |
| 836 } | 830 } |
| 837 | 831 |
| 838 virtual void DatabaseTaskCompleted() OVERRIDE { | 832 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 839 callback_->Run(origins_, type_); | 833 callback_.Run(origins_, type_); |
| 840 } | 834 } |
| 841 | 835 |
| 842 virtual void Aborted() OVERRIDE { | 836 virtual void Aborted() OVERRIDE { |
| 843 callback_->Run(std::set<GURL>(), type_); | 837 callback_.Run(std::set<GURL>(), type_); |
| 844 } | 838 } |
| 845 | 839 |
| 846 private: | 840 private: |
| 847 StorageType type_; | 841 StorageType type_; |
| 848 base::Time modified_since_; | 842 base::Time modified_since_; |
| 849 std::set<GURL> origins_; | 843 std::set<GURL> origins_; |
| 850 scoped_ptr<GetOriginsCallback> callback_; | 844 GetOriginsCallback callback_; |
| 851 }; | 845 }; |
| 852 | 846 |
| 853 class QuotaManager::DumpQuotaTableTask | 847 class QuotaManager::DumpQuotaTableTask |
| 854 : public QuotaManager::DatabaseTaskBase { | 848 : public QuotaManager::DatabaseTaskBase { |
| 855 private: | 849 private: |
| 856 typedef QuotaManager::DumpQuotaTableTask self_type; | 850 typedef QuotaManager::DumpQuotaTableTask self_type; |
| 857 typedef QuotaManager::DumpQuotaTableCallback Callback; | 851 typedef QuotaManager::DumpQuotaTableCallback Callback; |
| 858 typedef QuotaManager::QuotaTableEntry TableEntry; | 852 typedef QuotaManager::QuotaTableEntry TableEntry; |
| 859 typedef QuotaManager::QuotaTableEntries TableEntries; | 853 typedef QuotaManager::QuotaTableEntries TableEntries; |
| 860 typedef QuotaDatabase::QuotaTableCallback TableCallback; | 854 typedef QuotaDatabase::QuotaTableCallback TableCallback; |
| 861 | 855 |
| 862 public: | 856 public: |
| 863 DumpQuotaTableTask( | 857 DumpQuotaTableTask( |
| 864 QuotaManager* manager, | 858 QuotaManager* manager, |
| 865 Callback* callback) | 859 Callback callback) |
| 866 : DatabaseTaskBase(manager), | 860 : DatabaseTaskBase(manager), |
| 867 callback_(callback) { | 861 callback_(callback) { |
| 868 } | 862 } |
| 869 protected: | 863 protected: |
| 870 virtual void RunOnTargetThread() OVERRIDE { | 864 virtual void RunOnTargetThread() OVERRIDE { |
| 871 if (!database()->DumpQuotaTable( | 865 if (!database()->DumpQuotaTable( |
| 872 new TableCallback( | 866 new TableCallback( |
| 873 base::Bind(&self_type::AppendEntry, this)))) | 867 base::Bind(&self_type::AppendEntry, this)))) |
| 874 set_db_disabled(true); | 868 set_db_disabled(true); |
| 875 } | 869 } |
| 876 | 870 |
| 877 virtual void Aborted() OVERRIDE { | 871 virtual void Aborted() OVERRIDE { |
| 878 callback_->Run(TableEntries()); | 872 callback_.Run(TableEntries()); |
| 879 } | 873 } |
| 880 | 874 |
| 881 virtual void DatabaseTaskCompleted() OVERRIDE { | 875 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 882 callback_->Run(entries_); | 876 callback_.Run(entries_); |
| 883 } | 877 } |
| 884 | 878 |
| 885 private: | 879 private: |
| 886 bool AppendEntry(const TableEntry& entry) { | 880 bool AppendEntry(const TableEntry& entry) { |
| 887 entries_.push_back(entry); | 881 entries_.push_back(entry); |
| 888 return true; | 882 return true; |
| 889 } | 883 } |
| 890 | 884 |
| 891 scoped_ptr<Callback> callback_; | 885 Callback callback_; |
| 892 TableEntries entries_; | 886 TableEntries entries_; |
| 893 }; | 887 }; |
| 894 | 888 |
| 895 class QuotaManager::DumpOriginInfoTableTask | 889 class QuotaManager::DumpOriginInfoTableTask |
| 896 : public QuotaManager::DatabaseTaskBase { | 890 : public QuotaManager::DatabaseTaskBase { |
| 897 private: | 891 private: |
| 898 typedef QuotaManager::DumpOriginInfoTableTask self_type; | 892 typedef QuotaManager::DumpOriginInfoTableTask self_type; |
| 899 typedef QuotaManager::DumpOriginInfoTableCallback Callback; | 893 typedef QuotaManager::DumpOriginInfoTableCallback Callback; |
| 900 typedef QuotaManager::OriginInfoTableEntry TableEntry; | 894 typedef QuotaManager::OriginInfoTableEntry TableEntry; |
| 901 typedef QuotaManager::OriginInfoTableEntries TableEntries; | 895 typedef QuotaManager::OriginInfoTableEntries TableEntries; |
| 902 typedef QuotaDatabase::OriginInfoTableCallback TableCallback; | 896 typedef QuotaDatabase::OriginInfoTableCallback TableCallback; |
| 903 | 897 |
| 904 public: | 898 public: |
| 905 DumpOriginInfoTableTask( | 899 DumpOriginInfoTableTask( |
| 906 QuotaManager* manager, | 900 QuotaManager* manager, |
| 907 Callback* callback) | 901 Callback callback) |
| 908 : DatabaseTaskBase(manager), | 902 : DatabaseTaskBase(manager), |
| 909 callback_(callback) { | 903 callback_(callback) { |
| 910 } | 904 } |
| 911 protected: | 905 protected: |
| 912 virtual void RunOnTargetThread() OVERRIDE { | 906 virtual void RunOnTargetThread() OVERRIDE { |
| 913 if (!database()->DumpOriginInfoTable( | 907 if (!database()->DumpOriginInfoTable( |
| 914 new TableCallback( | 908 new TableCallback( |
| 915 base::Bind(&self_type::AppendEntry, this)))) | 909 base::Bind(&self_type::AppendEntry, this)))) |
| 916 set_db_disabled(true); | 910 set_db_disabled(true); |
| 917 } | 911 } |
| 918 | 912 |
| 919 virtual void Aborted() OVERRIDE { | 913 virtual void Aborted() OVERRIDE { |
| 920 callback_->Run(TableEntries()); | 914 callback_.Run(TableEntries()); |
| 921 } | 915 } |
| 922 | 916 |
| 923 virtual void DatabaseTaskCompleted() OVERRIDE { | 917 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 924 callback_->Run(entries_); | 918 callback_.Run(entries_); |
| 925 } | 919 } |
| 926 | 920 |
| 927 private: | 921 private: |
| 928 bool AppendEntry(const TableEntry& entry) { | 922 bool AppendEntry(const TableEntry& entry) { |
| 929 entries_.push_back(entry); | 923 entries_.push_back(entry); |
| 930 return true; | 924 return true; |
| 931 } | 925 } |
| 932 | 926 |
| 933 scoped_ptr<Callback> callback_; | 927 Callback callback_; |
| 934 TableEntries entries_; | 928 TableEntries entries_; |
| 935 }; | 929 }; |
| 936 | 930 |
| 937 // QuotaManager --------------------------------------------------------------- | 931 // QuotaManager --------------------------------------------------------------- |
| 938 | 932 |
| 939 QuotaManager::QuotaManager(bool is_incognito, | 933 QuotaManager::QuotaManager(bool is_incognito, |
| 940 const FilePath& profile_path, | 934 const FilePath& profile_path, |
| 941 base::MessageLoopProxy* io_thread, | 935 base::MessageLoopProxy* io_thread, |
| 942 base::MessageLoopProxy* db_thread, | 936 base::MessageLoopProxy* db_thread, |
| 943 SpecialStoragePolicy* special_storage_policy) | 937 SpecialStoragePolicy* special_storage_policy) |
| 944 : is_incognito_(is_incognito), | 938 : is_incognito_(is_incognito), |
| 945 profile_path_(profile_path), | 939 profile_path_(profile_path), |
| 946 proxy_(new QuotaManagerProxy( | 940 proxy_(new QuotaManagerProxy( |
| 947 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), | 941 ALLOW_THIS_IN_INITIALIZER_LIST(this), io_thread)), |
| 948 db_disabled_(false), | 942 db_disabled_(false), |
| 949 eviction_disabled_(false), | 943 eviction_disabled_(false), |
| 950 io_thread_(io_thread), | 944 io_thread_(io_thread), |
| 951 db_thread_(db_thread), | 945 db_thread_(db_thread), |
| 952 need_initialize_origins_(false), | 946 need_initialize_origins_(false), |
| 953 temporary_global_quota_(-1), | 947 temporary_global_quota_(-1), |
| 954 special_storage_policy_(special_storage_policy), | 948 special_storage_policy_(special_storage_policy), |
| 955 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 949 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 956 } | 950 } |
| 957 | 951 |
| 958 QuotaManager::~QuotaManager() { | 952 QuotaManager::~QuotaManager() { |
| 959 DCHECK(io_thread_->BelongsToCurrentThread()); | 953 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 960 proxy_->manager_ = NULL; | 954 proxy_->manager_ = NULL; |
| 961 std::for_each(clients_.begin(), clients_.end(), | 955 std::for_each(clients_.begin(), clients_.end(), |
| 962 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); | 956 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); |
| 963 if (database_.get()) | 957 if (database_.get()) |
| 964 db_thread_->DeleteSoon(FROM_HERE, database_.release()); | 958 db_thread_->DeleteSoon(FROM_HERE, database_.release()); |
| 965 } | 959 } |
| 966 | 960 |
| 967 void QuotaManager::GetUsageAndQuota( | 961 void QuotaManager::GetUsageAndQuota( |
| 968 const GURL& origin, StorageType type, | 962 const GURL& origin, StorageType type, |
| 969 GetUsageAndQuotaCallback* callback_ptr) { | 963 GetUsageAndQuotaCallback callback) { |
| 970 scoped_ptr<GetUsageAndQuotaCallback> callback(callback_ptr); | |
| 971 LazyInitialize(); | 964 LazyInitialize(); |
| 972 | 965 |
| 973 if (type == kStorageTypeUnknown) { | 966 if (type == kStorageTypeUnknown) { |
| 974 // Quota only supports temporary/persistent types. | 967 // Quota only supports temporary/persistent types. |
| 975 callback->Run(kQuotaErrorNotSupported, 0, 0); | 968 callback.Run(kQuotaErrorNotSupported, 0, 0); |
| 976 return; | 969 return; |
| 977 } | 970 } |
| 978 | 971 |
| 979 // note: returns host usage and quota | 972 // note: returns host usage and quota |
| 980 std::string host = net::GetHostOrSpecFromURL(origin); | 973 std::string host = net::GetHostOrSpecFromURL(origin); |
| 981 UsageAndQuotaDispatcherTaskMap::iterator found = | 974 UsageAndQuotaDispatcherTaskMap::iterator found = |
| 982 usage_and_quota_dispatchers_.find(std::make_pair(host, type)); | 975 usage_and_quota_dispatchers_.find(std::make_pair(host, type)); |
| 983 if (found == usage_and_quota_dispatchers_.end()) { | 976 if (found == usage_and_quota_dispatchers_.end()) { |
| 984 UsageAndQuotaDispatcherTask* dispatcher = | 977 UsageAndQuotaDispatcherTask* dispatcher = |
| 985 UsageAndQuotaDispatcherTask::Create(this, host, type); | 978 UsageAndQuotaDispatcherTask::Create(this, host, type); |
| 986 found = usage_and_quota_dispatchers_.insert( | 979 found = usage_and_quota_dispatchers_.insert( |
| 987 std::make_pair(std::make_pair(host, type), dispatcher)).first; | 980 std::make_pair(std::make_pair(host, type), dispatcher)).first; |
| 988 } | 981 } |
| 989 if (found->second->AddCallback( | 982 if (found->second->AddCallback(callback, IsStorageUnlimited(origin))) { |
| 990 callback.release(), IsStorageUnlimited(origin))) { | |
| 991 found->second->Start(); | 983 found->second->Start(); |
| 992 } | 984 } |
| 993 } | 985 } |
| 994 | 986 |
| 995 void QuotaManager::GetAvailableSpace(AvailableSpaceCallback* callback) { | 987 void QuotaManager::GetAvailableSpace(AvailableSpaceCallback callback) { |
| 996 scoped_refptr<AvailableSpaceQueryTask> task( | 988 scoped_refptr<AvailableSpaceQueryTask> task( |
| 997 new AvailableSpaceQueryTask(this, db_thread_, profile_path_, callback)); | 989 new AvailableSpaceQueryTask(this, db_thread_, profile_path_, callback)); |
| 998 task->Start(); | 990 task->Start(); |
| 999 } | 991 } |
| 1000 | 992 |
| 1001 void QuotaManager::GetTemporaryGlobalQuota(QuotaCallback* callback) { | 993 void QuotaManager::GetTemporaryGlobalQuota(QuotaCallback callback) { |
| 1002 LazyInitialize(); | 994 LazyInitialize(); |
| 1003 if (temporary_global_quota_ >= 0) { | 995 if (temporary_global_quota_ >= 0) { |
| 1004 // TODO(kinuko): We may want to adjust the quota when the current | 996 // TODO(kinuko): We may want to adjust the quota when the current |
| 1005 // available space in the hard drive is getting tight. | 997 // available space in the hard drive is getting tight. |
| 1006 callback->Run(kQuotaStatusOk, | 998 callback.Run(kQuotaStatusOk, |
| 1007 kStorageTypeTemporary, temporary_global_quota_); | 999 kStorageTypeTemporary, temporary_global_quota_); |
| 1008 delete callback; | |
| 1009 return; | 1000 return; |
| 1010 } | 1001 } |
| 1011 // They are called upon completion of InitializeTask. | 1002 // They are called upon completion of InitializeTask. |
| 1012 temporary_global_quota_callbacks_.Add(callback); | 1003 temporary_global_quota_callbacks_.Add(callback); |
| 1013 } | 1004 } |
| 1014 | 1005 |
| 1015 void QuotaManager::SetTemporaryGlobalQuota(int64 new_quota, | 1006 void QuotaManager::SetTemporaryGlobalQuota(int64 new_quota, |
| 1016 QuotaCallback* callback) { | 1007 QuotaCallback callback) { |
| 1017 LazyInitialize(); | 1008 LazyInitialize(); |
| 1018 if (new_quota < 0) { | 1009 if (new_quota < 0) { |
| 1019 callback->Run(kQuotaErrorInvalidModification, | 1010 callback.Run(kQuotaErrorInvalidModification, |
| 1020 kStorageTypeTemporary, -1); | 1011 kStorageTypeTemporary, -1); |
| 1021 delete callback; | |
| 1022 return; | 1012 return; |
| 1023 } | 1013 } |
| 1024 | 1014 |
| 1025 if (!db_disabled_) { | 1015 if (!db_disabled_) { |
| 1026 scoped_refptr<UpdateTemporaryGlobalQuotaTask> task( | 1016 scoped_refptr<UpdateTemporaryGlobalQuotaTask> task( |
| 1027 new UpdateTemporaryGlobalQuotaTask(this, new_quota, callback)); | 1017 new UpdateTemporaryGlobalQuotaTask(this, new_quota, callback)); |
| 1028 task->Start(); | 1018 task->Start(); |
| 1029 } else { | 1019 } else { |
| 1030 callback->Run(kQuotaErrorInvalidAccess, | 1020 callback.Run(kQuotaErrorInvalidAccess, |
| 1031 kStorageTypeTemporary, -1); | 1021 kStorageTypeTemporary, -1); |
| 1032 delete callback; | |
| 1033 } | 1022 } |
| 1034 } | 1023 } |
| 1035 | 1024 |
| 1036 void QuotaManager::GetPersistentHostQuota(const std::string& host, | 1025 void QuotaManager::GetPersistentHostQuota(const std::string& host, |
| 1037 HostQuotaCallback* callback_ptr) { | 1026 HostQuotaCallback callback) { |
| 1038 scoped_ptr<HostQuotaCallback> callback(callback_ptr); | |
| 1039 LazyInitialize(); | 1027 LazyInitialize(); |
| 1040 if (host.empty()) { | 1028 if (host.empty()) { |
| 1041 // This could happen if we are called on file:///. | 1029 // This could happen if we are called on file:///. |
| 1042 // TODO(kinuko) We may want to respect --allow-file-access-from-files | 1030 // TODO(kinuko) We may want to respect --allow-file-access-from-files |
| 1043 // command line switch. | 1031 // command line switch. |
| 1044 callback->Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); | 1032 callback.Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); |
| 1045 return; | 1033 return; |
| 1046 } | 1034 } |
| 1047 scoped_refptr<GetPersistentHostQuotaTask> task( | 1035 scoped_refptr<GetPersistentHostQuotaTask> task( |
| 1048 new GetPersistentHostQuotaTask(this, host, callback.release())); | 1036 new GetPersistentHostQuotaTask(this, host, callback)); |
| 1049 task->Start(); | 1037 task->Start(); |
| 1050 } | 1038 } |
| 1051 | 1039 |
| 1052 void QuotaManager::SetPersistentHostQuota(const std::string& host, | 1040 void QuotaManager::SetPersistentHostQuota(const std::string& host, |
| 1053 int64 new_quota, | 1041 int64 new_quota, |
| 1054 HostQuotaCallback* callback_ptr) { | 1042 HostQuotaCallback callback) { |
| 1055 scoped_ptr<HostQuotaCallback> callback(callback_ptr); | |
| 1056 LazyInitialize(); | 1043 LazyInitialize(); |
| 1057 if (host.empty()) { | 1044 if (host.empty()) { |
| 1058 // This could happen if we are called on file:///. | 1045 // This could happen if we are called on file:///. |
| 1059 callback->Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); | 1046 callback.Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); |
| 1060 return; | 1047 return; |
| 1061 } | 1048 } |
| 1062 if (new_quota < 0) { | 1049 if (new_quota < 0) { |
| 1063 callback->Run(kQuotaErrorInvalidModification, | 1050 callback.Run(kQuotaErrorInvalidModification, |
| 1064 host, kStorageTypePersistent, -1); | 1051 host, kStorageTypePersistent, -1); |
| 1065 return; | 1052 return; |
| 1066 } | 1053 } |
| 1067 | 1054 |
| 1068 if (!db_disabled_) { | 1055 if (!db_disabled_) { |
| 1069 scoped_refptr<UpdatePersistentHostQuotaTask> task( | 1056 scoped_refptr<UpdatePersistentHostQuotaTask> task( |
| 1070 new UpdatePersistentHostQuotaTask( | 1057 new UpdatePersistentHostQuotaTask( |
| 1071 this, host, new_quota, callback.release())); | 1058 this, host, new_quota, callback)); |
| 1072 task->Start(); | 1059 task->Start(); |
| 1073 } else { | 1060 } else { |
| 1074 callback->Run(kQuotaErrorInvalidAccess, | 1061 callback.Run(kQuotaErrorInvalidAccess, |
| 1075 host, kStorageTypePersistent, -1); | 1062 host, kStorageTypePersistent, -1); |
| 1076 } | 1063 } |
| 1077 } | 1064 } |
| 1078 | 1065 |
| 1079 void QuotaManager::GetGlobalUsage( | 1066 void QuotaManager::GetGlobalUsage( |
| 1080 StorageType type, | 1067 StorageType type, |
| 1081 GlobalUsageCallback* callback) { | 1068 GlobalUsageCallback callback) { |
| 1082 LazyInitialize(); | 1069 LazyInitialize(); |
| 1083 GetUsageTracker(type)->GetGlobalUsage(callback); | 1070 GetUsageTracker(type)->GetGlobalUsage(callback); |
| 1084 } | 1071 } |
| 1085 | 1072 |
| 1086 void QuotaManager::GetHostUsage(const std::string& host, StorageType type, | 1073 void QuotaManager::GetHostUsage(const std::string& host, StorageType type, |
| 1087 HostUsageCallback* callback) { | 1074 HostUsageCallback callback) { |
| 1088 LazyInitialize(); | 1075 LazyInitialize(); |
| 1089 GetUsageTracker(type)->GetHostUsage(host, callback); | 1076 GetUsageTracker(type)->GetHostUsage(host, callback); |
| 1090 } | 1077 } |
| 1091 | 1078 |
| 1092 void QuotaManager::GetStatistics( | 1079 void QuotaManager::GetStatistics( |
| 1093 std::map<std::string, std::string>* statistics) { | 1080 std::map<std::string, std::string>* statistics) { |
| 1094 DCHECK(statistics); | 1081 DCHECK(statistics); |
| 1095 if (temporary_storage_evictor_.get()) { | 1082 if (temporary_storage_evictor_.get()) { |
| 1096 std::map<std::string, int64> stats; | 1083 std::map<std::string, int64> stats; |
| 1097 temporary_storage_evictor_->GetStatistics(&stats); | 1084 temporary_storage_evictor_->GetStatistics(&stats); |
| 1098 for (std::map<std::string, int64>::iterator p = stats.begin(); | 1085 for (std::map<std::string, int64>::iterator p = stats.begin(); |
| 1099 p != stats.end(); | 1086 p != stats.end(); |
| 1100 ++p) | 1087 ++p) |
| 1101 (*statistics)[p->first] = base::Int64ToString(p->second); | 1088 (*statistics)[p->first] = base::Int64ToString(p->second); |
| 1102 } | 1089 } |
| 1103 } | 1090 } |
| 1104 | 1091 |
| 1105 void QuotaManager::GetOriginsModifiedSince( | 1092 void QuotaManager::GetOriginsModifiedSince( |
| 1106 StorageType type, | 1093 StorageType type, |
| 1107 base::Time modified_since, | 1094 base::Time modified_since, |
| 1108 GetOriginsCallback* callback) { | 1095 GetOriginsCallback callback) { |
| 1109 LazyInitialize(); | 1096 LazyInitialize(); |
| 1110 make_scoped_refptr(new GetModifiedSinceTask( | 1097 make_scoped_refptr(new GetModifiedSinceTask( |
| 1111 this, type, modified_since, callback))->Start(); | 1098 this, type, modified_since, callback))->Start(); |
| 1112 } | 1099 } |
| 1113 | 1100 |
| 1114 void QuotaManager::LazyInitialize() { | 1101 void QuotaManager::LazyInitialize() { |
| 1115 DCHECK(io_thread_->BelongsToCurrentThread()); | 1102 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1116 if (database_.get()) { | 1103 if (database_.get()) { |
| 1117 // Initialization seems to be done already. | 1104 // Initialization seems to be done already. |
| 1118 return; | 1105 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 | 1147 |
| 1161 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { | 1148 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { |
| 1162 DCHECK(io_thread_->BelongsToCurrentThread()); | 1149 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1163 DCHECK(IsOriginInUse(origin)); | 1150 DCHECK(IsOriginInUse(origin)); |
| 1164 int& count = origins_in_use_[origin]; | 1151 int& count = origins_in_use_[origin]; |
| 1165 if (--count == 0) | 1152 if (--count == 0) |
| 1166 origins_in_use_.erase(origin); | 1153 origins_in_use_.erase(origin); |
| 1167 } | 1154 } |
| 1168 | 1155 |
| 1169 void QuotaManager::DeleteOriginData( | 1156 void QuotaManager::DeleteOriginData( |
| 1170 const GURL& origin, StorageType type, StatusCallback* callback) { | 1157 const GURL& origin, StorageType type, StatusCallback callback) { |
| 1171 LazyInitialize(); | 1158 LazyInitialize(); |
| 1172 | 1159 |
| 1173 if (origin.is_empty() || clients_.empty()) { | 1160 if (origin.is_empty() || clients_.empty()) { |
| 1174 callback->Run(kQuotaStatusOk); | 1161 callback.Run(kQuotaStatusOk); |
| 1175 delete callback; | |
| 1176 return; | 1162 return; |
| 1177 } | 1163 } |
| 1178 | 1164 |
| 1179 OriginDataDeleter* deleter = | 1165 OriginDataDeleter* deleter = |
| 1180 new OriginDataDeleter(this, origin, type, callback); | 1166 new OriginDataDeleter(this, origin, type, callback); |
| 1181 deleter->Start(); | 1167 deleter->Start(); |
| 1182 } | 1168 } |
| 1183 | 1169 |
| 1184 bool QuotaManager::ResetUsageTracker(StorageType type) { | 1170 bool QuotaManager::ResetUsageTracker(StorageType type) { |
| 1185 switch (type) { | 1171 switch (type) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 default: | 1217 default: |
| 1232 NOTREACHED(); | 1218 NOTREACHED(); |
| 1233 } | 1219 } |
| 1234 } | 1220 } |
| 1235 | 1221 |
| 1236 void QuotaManager::NotifyStorageAccessedInternal( | 1222 void QuotaManager::NotifyStorageAccessedInternal( |
| 1237 QuotaClient::ID client_id, | 1223 QuotaClient::ID client_id, |
| 1238 const GURL& origin, StorageType type, | 1224 const GURL& origin, StorageType type, |
| 1239 base::Time accessed_time) { | 1225 base::Time accessed_time) { |
| 1240 LazyInitialize(); | 1226 LazyInitialize(); |
| 1241 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { | 1227 if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { |
| 1242 // Record the accessed origins while GetLRUOrigin task is runing | 1228 // Record the accessed origins while GetLRUOrigin task is runing |
| 1243 // to filter out them from eviction. | 1229 // to filter out them from eviction. |
| 1244 access_notified_origins_.insert(origin); | 1230 access_notified_origins_.insert(origin); |
| 1245 } | 1231 } |
| 1246 | 1232 |
| 1247 if (db_disabled_) | 1233 if (db_disabled_) |
| 1248 return; | 1234 return; |
| 1249 make_scoped_refptr(new UpdateAccessTimeTask( | 1235 make_scoped_refptr(new UpdateAccessTimeTask( |
| 1250 this, origin, type, accessed_time))->Start(); | 1236 this, origin, type, accessed_time))->Start(); |
| 1251 } | 1237 } |
| 1252 | 1238 |
| 1253 void QuotaManager::NotifyStorageModifiedInternal( | 1239 void QuotaManager::NotifyStorageModifiedInternal( |
| 1254 QuotaClient::ID client_id, | 1240 QuotaClient::ID client_id, |
| 1255 const GURL& origin, | 1241 const GURL& origin, |
| 1256 StorageType type, | 1242 StorageType type, |
| 1257 int64 delta, | 1243 int64 delta, |
| 1258 base::Time modified_time) { | 1244 base::Time modified_time) { |
| 1259 LazyInitialize(); | 1245 LazyInitialize(); |
| 1260 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); | 1246 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); |
| 1261 make_scoped_refptr(new UpdateModifiedTimeTask( | 1247 make_scoped_refptr(new UpdateModifiedTimeTask( |
| 1262 this, origin, type, modified_time))->Start(); | 1248 this, origin, type, modified_time))->Start(); |
| 1263 } | 1249 } |
| 1264 | 1250 |
| 1265 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { | 1251 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback callback) { |
| 1266 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); | 1252 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); |
| 1267 } | 1253 } |
| 1268 | 1254 |
| 1269 void QuotaManager::DumpOriginInfoTable( | 1255 void QuotaManager::DumpOriginInfoTable( |
| 1270 DumpOriginInfoTableCallback* callback) { | 1256 DumpOriginInfoTableCallback callback) { |
| 1271 make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start(); | 1257 make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start(); |
| 1272 } | 1258 } |
| 1273 | 1259 |
| 1274 | 1260 |
| 1275 void QuotaManager::DeleteOriginFromDatabase( | 1261 void QuotaManager::DeleteOriginFromDatabase( |
| 1276 const GURL& origin, StorageType type) { | 1262 const GURL& origin, StorageType type) { |
| 1277 LazyInitialize(); | 1263 LazyInitialize(); |
| 1278 if (db_disabled_) | 1264 if (db_disabled_) |
| 1279 return; | 1265 return; |
| 1280 scoped_refptr<DeleteOriginInfo> task = | 1266 scoped_refptr<DeleteOriginInfo> task = |
| 1281 new DeleteOriginInfo(this, origin, type); | 1267 new DeleteOriginInfo(this, origin, type); |
| 1282 task->Start(); | 1268 task->Start(); |
| 1283 } | 1269 } |
| 1284 | 1270 |
| 1285 void QuotaManager::GetLRUOrigin( | 1271 void QuotaManager::GetLRUOrigin( |
| 1286 StorageType type, | 1272 StorageType type, |
| 1287 GetLRUOriginCallback* callback) { | 1273 GetLRUOriginCallback callback) { |
| 1288 LazyInitialize(); | 1274 LazyInitialize(); |
| 1289 // This must not be called while there's an in-flight task. | 1275 // This must not be called while there's an in-flight task. |
| 1290 DCHECK(!lru_origin_callback_.get()); | 1276 DCHECK(lru_origin_callback_.is_null()); |
| 1291 lru_origin_callback_.reset(callback); | 1277 lru_origin_callback_ = callback; |
| 1292 if (db_disabled_) { | 1278 if (db_disabled_) { |
| 1293 lru_origin_callback_->Run(GURL()); | 1279 lru_origin_callback_.Run(GURL()); |
| 1294 lru_origin_callback_.reset(); | 1280 lru_origin_callback_.Reset(); |
| 1295 return; | 1281 return; |
| 1296 } | 1282 } |
| 1297 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( | 1283 scoped_refptr<GetLRUOriginTask> task(new GetLRUOriginTask( |
| 1298 this, type, origins_in_use_, | 1284 this, type, origins_in_use_, |
| 1299 origins_in_error_, callback_factory_.NewCallback( | 1285 origins_in_error_, |
| 1300 &QuotaManager::DidGetDatabaseLRUOrigin))); | 1286 base::Bind(&QuotaManager::DidGetDatabaseLRUOrigin, |
| 1287 weak_factory_.GetWeakPtr()))); |
| 1301 task->Start(); | 1288 task->Start(); |
| 1302 } | 1289 } |
| 1303 | 1290 |
| 1304 void QuotaManager::DidOriginDataEvicted( | 1291 void QuotaManager::DidOriginDataEvicted( |
| 1305 QuotaStatusCode status) { | 1292 QuotaStatusCode status) { |
| 1306 DCHECK(io_thread_->BelongsToCurrentThread()); | 1293 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1307 | 1294 |
| 1308 // We only try evict origins that are not in use, so basically | 1295 // We only try evict origins that are not in use, so basically |
| 1309 // deletion attempt for eviction should not fail. Let's record | 1296 // deletion attempt for eviction should not fail. Let's record |
| 1310 // the origin if we get error and exclude it from future eviction | 1297 // the origin if we get error and exclude it from future eviction |
| 1311 // if the error happens consistently (> kThresholdOfErrorsToBeBlacklisted). | 1298 // if the error happens consistently (> kThresholdOfErrorsToBeBlacklisted). |
| 1312 if (status != kQuotaStatusOk) | 1299 if (status != kQuotaStatusOk) |
| 1313 origins_in_error_[eviction_context_.evicted_origin]++; | 1300 origins_in_error_[eviction_context_.evicted_origin]++; |
| 1314 | 1301 |
| 1315 eviction_context_.evict_origin_data_callback->Run(status); | 1302 eviction_context_.evict_origin_data_callback.Run(status); |
| 1316 eviction_context_.evict_origin_data_callback.reset(); | 1303 eviction_context_.evict_origin_data_callback.Reset(); |
| 1317 } | 1304 } |
| 1318 | 1305 |
| 1319 void QuotaManager::EvictOriginData( | 1306 void QuotaManager::EvictOriginData( |
| 1320 const GURL& origin, | 1307 const GURL& origin, |
| 1321 StorageType type, | 1308 StorageType type, |
| 1322 EvictOriginDataCallback* callback) { | 1309 EvictOriginDataCallback callback) { |
| 1323 DCHECK(io_thread_->BelongsToCurrentThread()); | 1310 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1324 DCHECK_EQ(type, kStorageTypeTemporary); | 1311 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1325 | 1312 |
| 1326 eviction_context_.evicted_origin = origin; | 1313 eviction_context_.evicted_origin = origin; |
| 1327 eviction_context_.evicted_type = type; | 1314 eviction_context_.evicted_type = type; |
| 1328 eviction_context_.evict_origin_data_callback.reset(callback); | 1315 eviction_context_.evict_origin_data_callback = callback; |
| 1329 | 1316 |
| 1330 DeleteOriginData(origin, type, callback_factory_.NewCallback( | 1317 DeleteOriginData(origin, type, |
| 1331 &QuotaManager::DidOriginDataEvicted)); | 1318 base::Bind(&QuotaManager::DidOriginDataEvicted, |
| 1319 weak_factory_.GetWeakPtr())); |
| 1332 } | 1320 } |
| 1333 | 1321 |
| 1334 void QuotaManager::DidGetAvailableSpaceForEviction( | 1322 void QuotaManager::DidGetAvailableSpaceForEviction( |
| 1335 QuotaStatusCode status, | 1323 QuotaStatusCode status, |
| 1336 int64 available_space) { | 1324 int64 available_space) { |
| 1337 eviction_context_.get_usage_and_quota_callback->Run(status, | 1325 eviction_context_.get_usage_and_quota_callback.Run(status, |
| 1338 eviction_context_.usage, | 1326 eviction_context_.usage, |
| 1339 eviction_context_.unlimited_usage, | 1327 eviction_context_.unlimited_usage, |
| 1340 eviction_context_.quota, available_space); | 1328 eviction_context_.quota, available_space); |
| 1341 eviction_context_.get_usage_and_quota_callback.reset(); | 1329 eviction_context_.get_usage_and_quota_callback.Reset(); |
| 1342 } | 1330 } |
| 1343 | 1331 |
| 1344 void QuotaManager::DidGetGlobalQuotaForEviction( | 1332 void QuotaManager::DidGetGlobalQuotaForEviction( |
| 1345 QuotaStatusCode status, | 1333 QuotaStatusCode status, |
| 1346 StorageType type, | 1334 StorageType type, |
| 1347 int64 quota) { | 1335 int64 quota) { |
| 1348 DCHECK_EQ(type, kStorageTypeTemporary); | 1336 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1349 if (status != kQuotaStatusOk) { | 1337 if (status != kQuotaStatusOk) { |
| 1350 eviction_context_.get_usage_and_quota_callback->Run( | 1338 eviction_context_.get_usage_and_quota_callback.Run( |
| 1351 status, 0, 0, 0, 0); | 1339 status, 0, 0, 0, 0); |
| 1352 eviction_context_.get_usage_and_quota_callback.reset(); | 1340 eviction_context_.get_usage_and_quota_callback.Reset(); |
| 1353 return; | 1341 return; |
| 1354 } | 1342 } |
| 1355 | 1343 |
| 1356 eviction_context_.quota = quota; | 1344 eviction_context_.quota = quota; |
| 1357 GetAvailableSpace(callback_factory_. | 1345 GetAvailableSpace( |
| 1358 NewCallback(&QuotaManager::DidGetAvailableSpaceForEviction)); | 1346 base::Bind(&QuotaManager::DidGetAvailableSpaceForEviction, |
| 1347 weak_factory_.GetWeakPtr())); |
| 1359 } | 1348 } |
| 1360 | 1349 |
| 1361 void QuotaManager::DidGetGlobalUsageForEviction( | 1350 void QuotaManager::DidGetGlobalUsageForEviction( |
| 1362 StorageType type, int64 usage, int64 unlimited_usage) { | 1351 StorageType type, int64 usage, int64 unlimited_usage) { |
| 1363 DCHECK_EQ(type, kStorageTypeTemporary); | 1352 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1364 DCHECK_GE(usage, unlimited_usage); | 1353 DCHECK_GE(usage, unlimited_usage); |
| 1365 eviction_context_.usage = usage; | 1354 eviction_context_.usage = usage; |
| 1366 eviction_context_.unlimited_usage = unlimited_usage; | 1355 eviction_context_.unlimited_usage = unlimited_usage; |
| 1367 GetTemporaryGlobalQuota(callback_factory_. | 1356 GetTemporaryGlobalQuota( |
| 1368 NewCallback(&QuotaManager::DidGetGlobalQuotaForEviction)); | 1357 base::Bind(&QuotaManager::DidGetGlobalQuotaForEviction, |
| 1358 weak_factory_.GetWeakPtr())); |
| 1369 } | 1359 } |
| 1370 | 1360 |
| 1371 void QuotaManager::GetUsageAndQuotaForEviction( | 1361 void QuotaManager::GetUsageAndQuotaForEviction( |
| 1372 GetUsageAndQuotaForEvictionCallback* callback) { | 1362 GetUsageAndQuotaForEvictionCallback callback) { |
| 1373 DCHECK(io_thread_->BelongsToCurrentThread()); | 1363 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1374 DCHECK(!eviction_context_.get_usage_and_quota_callback.get()); | 1364 DCHECK(eviction_context_.get_usage_and_quota_callback.is_null()); |
| 1375 | 1365 |
| 1376 eviction_context_.get_usage_and_quota_callback.reset(callback); | 1366 eviction_context_.get_usage_and_quota_callback = callback; |
| 1377 // TODO(dmikurube): Make kStorageTypeTemporary an argument. | 1367 // TODO(dmikurube): Make kStorageTypeTemporary an argument. |
| 1378 GetGlobalUsage(kStorageTypeTemporary, callback_factory_. | 1368 GetGlobalUsage(kStorageTypeTemporary, |
| 1379 NewCallback(&QuotaManager::DidGetGlobalUsageForEviction)); | 1369 base::Bind(&QuotaManager::DidGetGlobalUsageForEviction, |
| 1370 weak_factory_.GetWeakPtr())); |
| 1380 } | 1371 } |
| 1381 | 1372 |
| 1382 void QuotaManager::StartEviction() { | 1373 void QuotaManager::StartEviction() { |
| 1383 DCHECK(!temporary_storage_evictor_.get()); | 1374 DCHECK(!temporary_storage_evictor_.get()); |
| 1384 temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor(this, | 1375 temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor(this, |
| 1385 kEvictionIntervalInMilliSeconds)); | 1376 kEvictionIntervalInMilliSeconds)); |
| 1386 temporary_storage_evictor_->Start(); | 1377 temporary_storage_evictor_->Start(); |
| 1387 } | 1378 } |
| 1388 | 1379 |
| 1389 void QuotaManager::ReportHistogram() { | 1380 void QuotaManager::ReportHistogram() { |
| 1390 GetGlobalUsage(kStorageTypeTemporary, | 1381 GetGlobalUsage(kStorageTypeTemporary, |
| 1391 callback_factory_.NewCallback( | 1382 base::Bind( |
| 1392 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram)); | 1383 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram, |
| 1384 weak_factory_.GetWeakPtr())); |
| 1393 GetGlobalUsage(kStorageTypePersistent, | 1385 GetGlobalUsage(kStorageTypePersistent, |
| 1394 callback_factory_.NewCallback( | 1386 base::Bind( |
| 1395 &QuotaManager::DidGetPersistentGlobalUsageForHistogram)); | 1387 &QuotaManager::DidGetPersistentGlobalUsageForHistogram, |
| 1388 weak_factory_.GetWeakPtr())); |
| 1396 } | 1389 } |
| 1397 | 1390 |
| 1398 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram( | 1391 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram( |
| 1399 StorageType type, | 1392 StorageType type, |
| 1400 int64 usage, | 1393 int64 usage, |
| 1401 int64 unlimited_usage) { | 1394 int64 unlimited_usage) { |
| 1402 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); | 1395 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); |
| 1403 | 1396 |
| 1404 std::set<GURL> origins; | 1397 std::set<GURL> origins; |
| 1405 GetCachedOrigins(type, &origins); | 1398 GetCachedOrigins(type, &origins); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 if (!need_initialize_origins_) { | 1446 if (!need_initialize_origins_) { |
| 1454 StartEviction(); | 1447 StartEviction(); |
| 1455 return; | 1448 return; |
| 1456 } | 1449 } |
| 1457 | 1450 |
| 1458 // We seem to need to initialize the origin table in the database. | 1451 // We seem to need to initialize the origin table in the database. |
| 1459 // Kick the first GetGlobalUsage for temporary storage to cache a list | 1452 // Kick the first GetGlobalUsage for temporary storage to cache a list |
| 1460 // of origins that have data in temporary storage to register them | 1453 // of origins that have data in temporary storage to register them |
| 1461 // in the database. (We'll need the global temporary usage anyway | 1454 // in the database. (We'll need the global temporary usage anyway |
| 1462 // for eviction later.) | 1455 // for eviction later.) |
| 1463 temporary_usage_tracker_->GetGlobalUsage(callback_factory_.NewCallback( | 1456 temporary_usage_tracker_->GetGlobalUsage( |
| 1464 &QuotaManager::DidRunInitialGetTemporaryGlobalUsage)); | 1457 base::Bind(&QuotaManager::DidRunInitialGetTemporaryGlobalUsage, |
| 1458 weak_factory_.GetWeakPtr())); |
| 1465 } | 1459 } |
| 1466 | 1460 |
| 1467 void QuotaManager::DidRunInitialGetTemporaryGlobalUsage( | 1461 void QuotaManager::DidRunInitialGetTemporaryGlobalUsage( |
| 1468 StorageType type, int64 usage_unused, int64 unlimited_usage_unused) { | 1462 StorageType type, int64 usage_unused, int64 unlimited_usage_unused) { |
| 1469 DCHECK_EQ(type, kStorageTypeTemporary); | 1463 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1470 // This will call the StartEviction() when initial origin registration | 1464 // This will call the StartEviction() when initial origin registration |
| 1471 // is completed. | 1465 // is completed. |
| 1472 scoped_refptr<InitializeTemporaryOriginsInfoTask> task( | 1466 scoped_refptr<InitializeTemporaryOriginsInfoTask> task( |
| 1473 new InitializeTemporaryOriginsInfoTask( | 1467 new InitializeTemporaryOriginsInfoTask( |
| 1474 this, temporary_usage_tracker_.get())); | 1468 this, temporary_usage_tracker_.get())); |
| 1475 task->Start(); | 1469 task->Start(); |
| 1476 } | 1470 } |
| 1477 | 1471 |
| 1478 void QuotaManager::DidGetDatabaseLRUOrigin(const GURL& origin) { | 1472 void QuotaManager::DidGetDatabaseLRUOrigin(const GURL& origin) { |
| 1479 // Make sure the returned origin is (still) not in the origin_in_use_ set | 1473 // Make sure the returned origin is (still) not in the origin_in_use_ set |
| 1480 // and has not been accessed since we posted the task. | 1474 // and has not been accessed since we posted the task. |
| 1481 if (origins_in_use_.find(origin) != origins_in_use_.end() || | 1475 if (origins_in_use_.find(origin) != origins_in_use_.end() || |
| 1482 access_notified_origins_.find(origin) != access_notified_origins_.end()) | 1476 access_notified_origins_.find(origin) != access_notified_origins_.end()) |
| 1483 lru_origin_callback_->Run(GURL()); | 1477 lru_origin_callback_.Run(GURL()); |
| 1484 else | 1478 else |
| 1485 lru_origin_callback_->Run(origin); | 1479 lru_origin_callback_.Run(origin); |
| 1486 access_notified_origins_.clear(); | 1480 access_notified_origins_.clear(); |
| 1487 lru_origin_callback_.reset(); | 1481 lru_origin_callback_.Reset(); |
| 1488 } | 1482 } |
| 1489 | 1483 |
| 1490 void QuotaManager::DeleteOnCorrectThread() const { | 1484 void QuotaManager::DeleteOnCorrectThread() const { |
| 1491 if (!io_thread_->BelongsToCurrentThread()) { | 1485 if (!io_thread_->BelongsToCurrentThread()) { |
| 1492 io_thread_->DeleteSoon(FROM_HERE, this); | 1486 io_thread_->DeleteSoon(FROM_HERE, this); |
| 1493 return; | 1487 return; |
| 1494 } | 1488 } |
| 1495 delete this; | 1489 delete this; |
| 1496 } | 1490 } |
| 1497 | 1491 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1561 |
| 1568 QuotaManagerProxy::QuotaManagerProxy( | 1562 QuotaManagerProxy::QuotaManagerProxy( |
| 1569 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1563 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
| 1570 : manager_(manager), io_thread_(io_thread) { | 1564 : manager_(manager), io_thread_(io_thread) { |
| 1571 } | 1565 } |
| 1572 | 1566 |
| 1573 QuotaManagerProxy::~QuotaManagerProxy() { | 1567 QuotaManagerProxy::~QuotaManagerProxy() { |
| 1574 } | 1568 } |
| 1575 | 1569 |
| 1576 } // namespace quota | 1570 } // namespace quota |
| OLD | NEW |