| 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 "base/trace_event/trace_event.h" | 
| 10 #include "content/common/quota_messages.h" | 11 #include "content/common/quota_messages.h" | 
| 11 #include "content/public/browser/quota_permission_context.h" | 12 #include "content/public/browser/quota_permission_context.h" | 
| 12 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" | 
| 13 #include "storage/browser/quota/quota_manager.h" | 14 #include "storage/browser/quota/quota_manager.h" | 
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" | 
| 15 | 16 | 
| 16 using storage::QuotaClient; | 17 using storage::QuotaClient; | 
| 17 using storage::QuotaManager; | 18 using storage::QuotaManager; | 
| 18 using storage::QuotaStatusCode; | 19 using storage::QuotaStatusCode; | 
| 19 using storage::StorageType; | 20 using storage::StorageType; | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 64     : public RequestDispatcher { | 65     : public RequestDispatcher { | 
| 65  public: | 66  public: | 
| 66   QueryUsageAndQuotaDispatcher( | 67   QueryUsageAndQuotaDispatcher( | 
| 67       base::WeakPtr<QuotaDispatcherHost> dispatcher_host, | 68       base::WeakPtr<QuotaDispatcherHost> dispatcher_host, | 
| 68       int request_id) | 69       int request_id) | 
| 69       : RequestDispatcher(dispatcher_host, request_id), | 70       : RequestDispatcher(dispatcher_host, request_id), | 
| 70         weak_factory_(this) {} | 71         weak_factory_(this) {} | 
| 71   ~QueryUsageAndQuotaDispatcher() override {} | 72   ~QueryUsageAndQuotaDispatcher() override {} | 
| 72 | 73 | 
| 73   void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) { | 74   void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) { | 
|  | 75     // crbug.com/349708 | 
|  | 76     TRACE_EVENT0("io", | 
|  | 77                  "QuotaDispatcherHost::QueryUsageAndQuotaDispatcher" | 
|  | 78                  "::QueryStorageUsageAndQuota"); | 
|  | 79 | 
| 74     quota_manager()->GetUsageAndQuotaForWebApps( | 80     quota_manager()->GetUsageAndQuotaForWebApps( | 
| 75         origin, type, | 81         origin, type, | 
| 76         base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, | 82         base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, | 
| 77                    weak_factory_.GetWeakPtr())); | 83                    weak_factory_.GetWeakPtr())); | 
| 78   } | 84   } | 
| 79 | 85 | 
| 80  private: | 86  private: | 
| 81   void DidQueryStorageUsageAndQuota( | 87   void DidQueryStorageUsageAndQuota( | 
| 82       QuotaStatusCode status, int64 usage, int64 quota) { | 88       QuotaStatusCode status, int64 usage, int64 quota) { | 
| 83     if (!dispatcher_host()) | 89     if (!dispatcher_host()) | 
| 84       return; | 90       return; | 
|  | 91     // crbug.com/349708 | 
|  | 92     TRACE_EVENT0("io", "QuotaDispatcherHost::RequestQuotaDispatcher" | 
|  | 93                  "::DidQueryStorageUsageAndQuota"); | 
|  | 94 | 
| 85     if (status != storage::kQuotaStatusOk) { | 95     if (status != storage::kQuotaStatusOk) { | 
| 86       dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 96       dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 
| 87     } else { | 97     } else { | 
| 88       dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( | 98       dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( | 
| 89           request_id(), usage, quota)); | 99           request_id(), usage, quota)); | 
| 90     } | 100     } | 
| 91     Completed(); | 101     Completed(); | 
| 92   } | 102   } | 
| 93 | 103 | 
| 94   base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; | 104   base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 109         weak_factory_(this) { | 119         weak_factory_(this) { | 
| 110     // Convert the requested size from uint64 to int64 since the quota backend | 120     // Convert the requested size from uint64 to int64 since the quota backend | 
| 111     // requires int64 values. | 121     // requires int64 values. | 
| 112     // TODO(nhiroki): The backend should accept uint64 values. | 122     // TODO(nhiroki): The backend should accept uint64 values. | 
| 113     requested_quota_ = base::saturated_cast<int64>(params_.requested_size); | 123     requested_quota_ = base::saturated_cast<int64>(params_.requested_size); | 
| 114   } | 124   } | 
| 115   ~RequestQuotaDispatcher() override {} | 125   ~RequestQuotaDispatcher() override {} | 
| 116 | 126 | 
| 117   void Start() { | 127   void Start() { | 
| 118     DCHECK(dispatcher_host()); | 128     DCHECK(dispatcher_host()); | 
|  | 129     // crbug.com/349708 | 
|  | 130     TRACE_EVENT0("io", "QuotaDispatcherHost::RequestQuotaDispatcher::Start"); | 
| 119 | 131 | 
| 120     DCHECK(params_.storage_type == storage::kStorageTypeTemporary || | 132     DCHECK(params_.storage_type == storage::kStorageTypeTemporary || | 
| 121            params_.storage_type == storage::kStorageTypePersistent); | 133            params_.storage_type == storage::kStorageTypePersistent); | 
| 122     if (params_.storage_type == storage::kStorageTypePersistent) { | 134     if (params_.storage_type == storage::kStorageTypePersistent) { | 
| 123       quota_manager()->GetUsageAndQuotaForWebApps( | 135       quota_manager()->GetUsageAndQuotaForWebApps( | 
| 124           params_.origin_url, params_.storage_type, | 136           params_.origin_url, params_.storage_type, | 
| 125           base::Bind(&self_type::DidGetPersistentUsageAndQuota, | 137           base::Bind(&self_type::DidGetPersistentUsageAndQuota, | 
| 126                      weak_factory_.GetWeakPtr())); | 138                      weak_factory_.GetWeakPtr())); | 
| 127     } else { | 139     } else { | 
| 128       quota_manager()->GetUsageAndQuotaForWebApps( | 140       quota_manager()->GetUsageAndQuotaForWebApps( | 
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252     return; | 264     return; | 
| 253   } | 265   } | 
| 254 | 266 | 
| 255   RequestQuotaDispatcher* dispatcher = | 267   RequestQuotaDispatcher* dispatcher = | 
| 256       new RequestQuotaDispatcher(weak_factory_.GetWeakPtr(), | 268       new RequestQuotaDispatcher(weak_factory_.GetWeakPtr(), | 
| 257                                  params); | 269                                  params); | 
| 258   dispatcher->Start(); | 270   dispatcher->Start(); | 
| 259 } | 271 } | 
| 260 | 272 | 
| 261 }  // namespace content | 273 }  // namespace content | 
| OLD | NEW | 
|---|