| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quota_dispatcher_host.h" | 5 #include "content/browser/quota_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "content/common/quota_messages.h" | 10 #include "content/common/quota_messages.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, | 76 base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, |
| 77 weak_factory_.GetWeakPtr())); | 77 weak_factory_.GetWeakPtr())); |
| 78 } | 78 } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 void DidQueryStorageUsageAndQuota( | 81 void DidQueryStorageUsageAndQuota( |
| 82 QuotaStatusCode status, int64 usage, int64 quota) { | 82 QuotaStatusCode status, int64 usage, int64 quota) { |
| 83 if (!dispatcher_host()) | 83 if (!dispatcher_host()) |
| 84 return; | 84 return; |
| 85 if (status != storage::kQuotaStatusOk) { | 85 if (status != storage::kQuotaStatusOk) { |
| 86 LOG(ERROR) << "Sending DidFail"; |
| 86 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 87 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); |
| 87 } else { | 88 } else { |
| 88 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( | 89 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( |
| 89 request_id(), usage, quota)); | 90 request_id(), usage, quota)); |
| 90 } | 91 } |
| 91 Completed(); | 92 Completed(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; | 95 base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; |
| 95 }; | 96 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 111 // requires int64 values. | 112 // requires int64 values. |
| 112 // TODO(nhiroki): The backend should accept uint64 values. | 113 // TODO(nhiroki): The backend should accept uint64 values. |
| 113 requested_quota_ = base::saturated_cast<int64>(params_.requested_size); | 114 requested_quota_ = base::saturated_cast<int64>(params_.requested_size); |
| 114 } | 115 } |
| 115 ~RequestQuotaDispatcher() override {} | 116 ~RequestQuotaDispatcher() override {} |
| 116 | 117 |
| 117 void Start() { | 118 void Start() { |
| 118 DCHECK(dispatcher_host()); | 119 DCHECK(dispatcher_host()); |
| 119 | 120 |
| 120 DCHECK(params_.storage_type == storage::kStorageTypeTemporary || | 121 DCHECK(params_.storage_type == storage::kStorageTypeTemporary || |
| 121 params_.storage_type == storage::kStorageTypePersistent); | 122 params_.storage_type == storage::kStorageTypePersistent || |
| 123 params_.storage_type == storage::kStorageTypeDurable); |
| 122 if (params_.storage_type == storage::kStorageTypePersistent) { | 124 if (params_.storage_type == storage::kStorageTypePersistent) { |
| 123 quota_manager()->GetUsageAndQuotaForWebApps( | 125 quota_manager()->GetUsageAndQuotaForWebApps( |
| 124 params_.origin_url, params_.storage_type, | 126 params_.origin_url, params_.storage_type, |
| 125 base::Bind(&self_type::DidGetPersistentUsageAndQuota, | 127 base::Bind(&self_type::DidGetPersistentUsageAndQuota, |
| 126 weak_factory_.GetWeakPtr())); | 128 weak_factory_.GetWeakPtr())); |
| 129 } else if (params_.storage_type == storage::kStorageTypeDurable) { |
| 130 quota_manager()->GetDurability( |
| 131 params_.origin_url, |
| 132 base::Bind(&self_type::DidGetDurable, |
| 133 weak_factory_.GetWeakPtr())); |
| 127 } else { | 134 } else { |
| 135 LOG(ERROR) << "Got here A"; |
| 128 quota_manager()->GetUsageAndQuotaForWebApps( | 136 quota_manager()->GetUsageAndQuotaForWebApps( |
| 129 params_.origin_url, params_.storage_type, | 137 params_.origin_url, params_.storage_type, |
| 130 base::Bind(&self_type::DidGetTemporaryUsageAndQuota, | 138 base::Bind(&self_type::DidGetTemporaryUsageAndQuota, |
| 131 weak_factory_.GetWeakPtr())); | 139 weak_factory_.GetWeakPtr())); |
| 132 } | 140 } |
| 133 } | 141 } |
| 134 | 142 |
| 135 private: | 143 private: |
| 144 |
| 145 void DidGetDurable(QuotaStatusCode status, bool durable) { |
| 146 LOG(ERROR) << "Inside DidGetDurable = " << status << ":" << durable; |
| 147 if (!dispatcher_host()) |
| 148 return; |
| 149 if (status != storage::kQuotaStatusOk) { |
| 150 DidFinish(status, 0, 0); |
| 151 return; |
| 152 } |
| 153 |
| 154 if (quota_manager()->IsStorageUnlimited(params_.origin_url, |
| 155 params_.storage_type)) { |
| 156 // Seems like we can just let it go. |
| 157 DidFinish(storage::kQuotaStatusOk, 0, 0); |
| 158 return; |
| 159 } |
| 160 if (durable) { |
| 161 DidFinish(status, 0, 0); |
| 162 return; |
| 163 } |
| 164 LOG(ERROR) << "Need to ask for permission."; |
| 165 } |
| 166 |
| 136 void DidGetPersistentUsageAndQuota(QuotaStatusCode status, | 167 void DidGetPersistentUsageAndQuota(QuotaStatusCode status, |
| 137 int64 usage, | 168 int64 usage, |
| 138 int64 quota) { | 169 int64 quota) { |
| 139 if (!dispatcher_host()) | 170 if (!dispatcher_host()) |
| 140 return; | 171 return; |
| 141 if (status != storage::kQuotaStatusOk) { | 172 if (status != storage::kQuotaStatusOk) { |
| 142 DidFinish(status, 0, 0); | 173 DidFinish(status, 0, 0); |
| 143 return; | 174 return; |
| 144 } | 175 } |
| 145 | 176 |
| 146 if (quota_manager()->IsStorageUnlimited(params_.origin_url, | 177 if (quota_manager()->IsStorageUnlimited(params_.origin_url, |
| 147 params_.storage_type) || | 178 params_.storage_type) || |
| 148 requested_quota_ <= quota) { | 179 requested_quota_ <= quota) { |
| 149 // Seems like we can just let it go. | 180 // Seems like we can just let it go. |
| 150 DidFinish(storage::kQuotaStatusOk, usage, params_.requested_size); | 181 DidFinish(storage::kQuotaStatusOk, usage, params_.requested_size); |
| 151 return; | 182 return; |
| 152 } | 183 } |
| 153 current_usage_ = usage; | 184 current_usage_ = usage; |
| 154 current_quota_ = quota; | 185 current_quota_ = quota; |
| 155 | 186 |
| 156 // Otherwise we need to consult with the permission context and | 187 // Otherwise we need to consult with the permission context and |
| 157 // possibly show a prompt. | 188 // possibly show a prompt. |
| 158 DCHECK(permission_context()); | 189 DCHECK(permission_context()); |
| 190 LOG(ERROR) << "About to RequestQuotaPermission"; |
| 159 permission_context()->RequestQuotaPermission(params_, render_process_id(), | 191 permission_context()->RequestQuotaPermission(params_, render_process_id(), |
| 160 base::Bind(&self_type::DidGetPermissionResponse, | 192 base::Bind(&self_type::DidGetPermissionResponse, |
| 161 weak_factory_.GetWeakPtr())); | 193 weak_factory_.GetWeakPtr())); |
| 162 } | 194 } |
| 163 | 195 |
| 164 void DidGetTemporaryUsageAndQuota(QuotaStatusCode status, | 196 void DidGetTemporaryUsageAndQuota(QuotaStatusCode status, |
| 165 int64 usage, | 197 int64 usage, |
| 166 int64 quota) { | 198 int64 quota) { |
| 167 DidFinish(status, usage, std::min(requested_quota_, quota)); | 199 DidFinish(status, usage, std::min(requested_quota_, quota)); |
| 168 } | 200 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 184 | 216 |
| 185 void DidSetHostQuota(QuotaStatusCode status, int64 new_quota) { | 217 void DidSetHostQuota(QuotaStatusCode status, int64 new_quota) { |
| 186 DidFinish(status, current_usage_, new_quota); | 218 DidFinish(status, current_usage_, new_quota); |
| 187 } | 219 } |
| 188 | 220 |
| 189 void DidFinish(QuotaStatusCode status, | 221 void DidFinish(QuotaStatusCode status, |
| 190 int64 usage, | 222 int64 usage, |
| 191 int64 granted_quota) { | 223 int64 granted_quota) { |
| 192 if (!dispatcher_host()) | 224 if (!dispatcher_host()) |
| 193 return; | 225 return; |
| 194 DCHECK(dispatcher_host()); | |
| 195 if (status != storage::kQuotaStatusOk) { | 226 if (status != storage::kQuotaStatusOk) { |
| 227 LOG(ERROR) << "Sending DidFail, status = " << status; |
| 196 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 228 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); |
| 197 } else { | 229 } else { |
| 198 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( | 230 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( |
| 199 request_id(), usage, granted_quota)); | 231 request_id(), usage, granted_quota)); |
| 200 } | 232 } |
| 201 Completed(); | 233 Completed(); |
| 202 } | 234 } |
| 203 | 235 |
| 204 StorageQuotaParams params_; | 236 StorageQuotaParams params_; |
| 205 int64 current_usage_; | 237 int64 current_usage_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 int request_id, | 269 int request_id, |
| 238 const GURL& origin, | 270 const GURL& origin, |
| 239 StorageType type) { | 271 StorageType type) { |
| 240 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( | 272 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( |
| 241 weak_factory_.GetWeakPtr(), request_id); | 273 weak_factory_.GetWeakPtr(), request_id); |
| 242 dispatcher->QueryStorageUsageAndQuota(origin, type); | 274 dispatcher->QueryStorageUsageAndQuota(origin, type); |
| 243 } | 275 } |
| 244 | 276 |
| 245 void QuotaDispatcherHost::OnRequestStorageQuota( | 277 void QuotaDispatcherHost::OnRequestStorageQuota( |
| 246 const StorageQuotaParams& params) { | 278 const StorageQuotaParams& params) { |
| 279 LOG(ERROR) |
| 280 << "Got into QuotaDispatcherHost::OnRequestStorageQuota storage_type = " |
| 281 << params.storage_type; |
| 247 if (params.storage_type != storage::kStorageTypeTemporary && | 282 if (params.storage_type != storage::kStorageTypeTemporary && |
| 283 params.storage_type != storage::kStorageTypeDurable && |
| 248 params.storage_type != storage::kStorageTypePersistent) { | 284 params.storage_type != storage::kStorageTypePersistent) { |
| 249 // Unsupported storage types. | 285 // Unsupported storage types. |
| 286 LOG(ERROR) << "Sending DidFail"; |
| 250 Send(new QuotaMsg_DidFail(params.request_id, | 287 Send(new QuotaMsg_DidFail(params.request_id, |
| 251 storage::kQuotaErrorNotSupported)); | 288 storage::kQuotaErrorNotSupported)); |
| 252 return; | 289 return; |
| 253 } | 290 } |
| 254 | 291 |
| 255 RequestQuotaDispatcher* dispatcher = | 292 RequestQuotaDispatcher* dispatcher = |
| 256 new RequestQuotaDispatcher(weak_factory_.GetWeakPtr(), | 293 new RequestQuotaDispatcher(weak_factory_.GetWeakPtr(), |
| 257 params); | 294 params); |
| 258 dispatcher->Start(); | 295 dispatcher->Start(); |
| 259 } | 296 } |
| 260 | 297 |
| 261 } // namespace content | 298 } // namespace content |
| OLD | NEW |