| 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 "content/browser/in_process_webkit/indexed_db_quota_client.h" | 5 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 protected: | 25 protected: |
| 26 HelperTask( | 26 HelperTask( |
| 27 IndexedDBQuotaClient* client, | 27 IndexedDBQuotaClient* client, |
| 28 base::MessageLoopProxy* webkit_thread_message_loop) | 28 base::MessageLoopProxy* webkit_thread_message_loop) |
| 29 : QuotaThreadTask(client, webkit_thread_message_loop), | 29 : QuotaThreadTask(client, webkit_thread_message_loop), |
| 30 client_(client), indexed_db_context_(client->indexed_db_context_) { | 30 client_(client), indexed_db_context_(client->indexed_db_context_) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 IndexedDBQuotaClient* client_; | 33 IndexedDBQuotaClient* client_; |
| 34 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 34 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 35 |
| 36 protected: |
| 37 virtual ~HelperTask() {} |
| 35 }; | 38 }; |
| 36 | 39 |
| 37 class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { | 40 class IndexedDBQuotaClient::DeleteOriginTask : public HelperTask { |
| 38 public: | 41 public: |
| 39 DeleteOriginTask(IndexedDBQuotaClient* client, | 42 DeleteOriginTask(IndexedDBQuotaClient* client, |
| 40 base::MessageLoopProxy* webkit_thread_message_loop, | 43 base::MessageLoopProxy* webkit_thread_message_loop, |
| 41 const GURL& origin_url, | 44 const GURL& origin_url, |
| 42 const DeletionCallback& callback) | 45 const DeletionCallback& callback) |
| 43 : HelperTask(client, webkit_thread_message_loop), | 46 : HelperTask(client, webkit_thread_message_loop), |
| 44 origin_url_(origin_url), callback_(callback) { | 47 origin_url_(origin_url), callback_(callback) { |
| 45 } | 48 } |
| 49 |
| 46 private: | 50 private: |
| 51 virtual ~DeleteOriginTask() {} |
| 52 |
| 47 virtual void RunOnTargetThread() OVERRIDE { | 53 virtual void RunOnTargetThread() OVERRIDE { |
| 48 indexed_db_context_->DeleteForOrigin(origin_url_); | 54 indexed_db_context_->DeleteForOrigin(origin_url_); |
| 49 } | 55 } |
| 56 |
| 50 virtual void Aborted() OVERRIDE { | 57 virtual void Aborted() OVERRIDE { |
| 51 callback_.Reset(); | 58 callback_.Reset(); |
| 52 } | 59 } |
| 60 |
| 53 virtual void Completed() OVERRIDE { | 61 virtual void Completed() OVERRIDE { |
| 54 callback_.Run(quota::kQuotaStatusOk); | 62 callback_.Run(quota::kQuotaStatusOk); |
| 55 callback_.Reset(); | 63 callback_.Reset(); |
| 56 } | 64 } |
| 65 |
| 57 GURL origin_url_; | 66 GURL origin_url_; |
| 58 DeletionCallback callback_; | 67 DeletionCallback callback_; |
| 59 }; | 68 }; |
| 60 | 69 |
| 61 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { | 70 class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask { |
| 62 public: | 71 public: |
| 63 GetOriginUsageTask( | 72 GetOriginUsageTask( |
| 64 IndexedDBQuotaClient* client, | 73 IndexedDBQuotaClient* client, |
| 65 base::MessageLoopProxy* webkit_thread_message_loop, | 74 base::MessageLoopProxy* webkit_thread_message_loop, |
| 66 const GURL& origin_url) | 75 const GURL& origin_url) |
| 67 : HelperTask(client, webkit_thread_message_loop), | 76 : HelperTask(client, webkit_thread_message_loop), |
| 68 origin_url_(origin_url), usage_(0) { | 77 origin_url_(origin_url), usage_(0) { |
| 69 } | 78 } |
| 70 | 79 |
| 71 private: | 80 private: |
| 81 virtual ~GetOriginUsageTask() {} |
| 82 |
| 72 virtual void RunOnTargetThread() OVERRIDE { | 83 virtual void RunOnTargetThread() OVERRIDE { |
| 73 usage_ = indexed_db_context_->GetOriginDiskUsage(origin_url_); | 84 usage_ = indexed_db_context_->GetOriginDiskUsage(origin_url_); |
| 74 } | 85 } |
| 86 |
| 75 virtual void Completed() OVERRIDE { | 87 virtual void Completed() OVERRIDE { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 77 client_->DidGetOriginUsage(origin_url_, usage_); | 89 client_->DidGetOriginUsage(origin_url_, usage_); |
| 78 } | 90 } |
| 91 |
| 79 GURL origin_url_; | 92 GURL origin_url_; |
| 80 int64 usage_; | 93 int64 usage_; |
| 81 }; | 94 }; |
| 82 | 95 |
| 83 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { | 96 class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask { |
| 84 protected: | 97 protected: |
| 85 GetOriginsTaskBase( | 98 GetOriginsTaskBase( |
| 86 IndexedDBQuotaClient* client, | 99 IndexedDBQuotaClient* client, |
| 87 base::MessageLoopProxy* webkit_thread_message_loop) | 100 base::MessageLoopProxy* webkit_thread_message_loop) |
| 88 : HelperTask(client, webkit_thread_message_loop) { | 101 : HelperTask(client, webkit_thread_message_loop) { |
| 89 } | 102 } |
| 90 | 103 |
| 91 virtual bool ShouldAddOrigin(const GURL& origin) = 0; | 104 virtual bool ShouldAddOrigin(const GURL& origin) = 0; |
| 92 | 105 |
| 93 virtual void RunOnTargetThread() OVERRIDE { | 106 virtual void RunOnTargetThread() OVERRIDE { |
| 94 std::vector<GURL> origins = indexed_db_context_->GetAllOrigins(); | 107 std::vector<GURL> origins = indexed_db_context_->GetAllOrigins(); |
| 95 for (std::vector<GURL>::const_iterator iter = origins.begin(); | 108 for (std::vector<GURL>::const_iterator iter = origins.begin(); |
| 96 iter != origins.end(); ++iter) { | 109 iter != origins.end(); ++iter) { |
| 97 if (ShouldAddOrigin(*iter)) | 110 if (ShouldAddOrigin(*iter)) |
| 98 origins_.insert(*iter); | 111 origins_.insert(*iter); |
| 99 } | 112 } |
| 100 } | 113 } |
| 101 | 114 |
| 102 std::set<GURL> origins_; | 115 std::set<GURL> origins_; |
| 116 |
| 117 protected: |
| 118 virtual ~GetOriginsTaskBase() {} |
| 103 }; | 119 }; |
| 104 | 120 |
| 105 class IndexedDBQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase { | 121 class IndexedDBQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase { |
| 106 public: | 122 public: |
| 107 GetAllOriginsTask( | 123 GetAllOriginsTask( |
| 108 IndexedDBQuotaClient* client, | 124 IndexedDBQuotaClient* client, |
| 109 base::MessageLoopProxy* webkit_thread_message_loop, | 125 base::MessageLoopProxy* webkit_thread_message_loop, |
| 110 quota::StorageType type) | 126 quota::StorageType type) |
| 111 : GetOriginsTaskBase(client, webkit_thread_message_loop), | 127 : GetOriginsTaskBase(client, webkit_thread_message_loop), |
| 112 type_(type) { | 128 type_(type) { |
| 113 } | 129 } |
| 114 | 130 |
| 115 protected: | 131 protected: |
| 132 virtual ~GetAllOriginsTask() {} |
| 133 |
| 116 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { | 134 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { |
| 117 return true; | 135 return true; |
| 118 } | 136 } |
| 137 |
| 119 virtual void Completed() OVERRIDE { | 138 virtual void Completed() OVERRIDE { |
| 120 client_->DidGetAllOrigins(origins_, type_); | 139 client_->DidGetAllOrigins(origins_, type_); |
| 121 } | 140 } |
| 122 | 141 |
| 123 private: | 142 private: |
| 124 quota::StorageType type_; | 143 quota::StorageType type_; |
| 125 }; | 144 }; |
| 126 | 145 |
| 127 class IndexedDBQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase { | 146 class IndexedDBQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase { |
| 128 public: | 147 public: |
| 129 GetOriginsForHostTask( | 148 GetOriginsForHostTask( |
| 130 IndexedDBQuotaClient* client, | 149 IndexedDBQuotaClient* client, |
| 131 base::MessageLoopProxy* webkit_thread_message_loop, | 150 base::MessageLoopProxy* webkit_thread_message_loop, |
| 132 const std::string& host, | 151 const std::string& host, |
| 133 quota::StorageType type) | 152 quota::StorageType type) |
| 134 : GetOriginsTaskBase(client, webkit_thread_message_loop), | 153 : GetOriginsTaskBase(client, webkit_thread_message_loop), |
| 135 host_(host), | 154 host_(host), |
| 136 type_(type) { | 155 type_(type) { |
| 137 } | 156 } |
| 138 | 157 |
| 139 private: | 158 private: |
| 159 virtual ~GetOriginsForHostTask() {} |
| 160 |
| 140 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { | 161 virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE { |
| 141 return host_ == net::GetHostOrSpecFromURL(origin); | 162 return host_ == net::GetHostOrSpecFromURL(origin); |
| 142 } | 163 } |
| 164 |
| 143 virtual void Completed() OVERRIDE { | 165 virtual void Completed() OVERRIDE { |
| 144 client_->DidGetOriginsForHost(host_, origins_, type_); | 166 client_->DidGetOriginsForHost(host_, origins_, type_); |
| 145 } | 167 } |
| 168 |
| 146 std::string host_; | 169 std::string host_; |
| 147 quota::StorageType type_; | 170 quota::StorageType type_; |
| 148 }; | 171 }; |
| 149 | 172 |
| 150 // IndexedDBQuotaClient -------------------------------------------------------- | 173 // IndexedDBQuotaClient -------------------------------------------------------- |
| 151 | 174 |
| 152 IndexedDBQuotaClient::IndexedDBQuotaClient( | 175 IndexedDBQuotaClient::IndexedDBQuotaClient( |
| 153 base::MessageLoopProxy* webkit_thread_message_loop, | 176 base::MessageLoopProxy* webkit_thread_message_loop, |
| 154 IndexedDBContextImpl* indexed_db_context) | 177 IndexedDBContextImpl* indexed_db_context) |
| 155 : webkit_thread_message_loop_(webkit_thread_message_loop), | 178 : webkit_thread_message_loop_(webkit_thread_message_loop), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 DCHECK(origins_for_type_callbacks_.HasCallbacks()); | 277 DCHECK(origins_for_type_callbacks_.HasCallbacks()); |
| 255 origins_for_type_callbacks_.Run(origins, type); | 278 origins_for_type_callbacks_.Run(origins, type); |
| 256 } | 279 } |
| 257 | 280 |
| 258 void IndexedDBQuotaClient::DidGetOriginsForHost( | 281 void IndexedDBQuotaClient::DidGetOriginsForHost( |
| 259 const std::string& host, const std::set<GURL>& origins, | 282 const std::string& host, const std::set<GURL>& origins, |
| 260 quota::StorageType type) { | 283 quota::StorageType type) { |
| 261 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); | 284 DCHECK(origins_for_host_callbacks_.HasCallbacks(host)); |
| 262 origins_for_host_callbacks_.Run(host, origins, type); | 285 origins_for_host_callbacks_.Run(host, origins, type); |
| 263 } | 286 } |
| OLD | NEW |