| 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 "webkit/fileapi/file_system_quota_client.h" | 5 #include "webkit/fileapi/file_system_quota_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 FileSystemType type) | 34 FileSystemType type) |
| 35 : QuotaThreadTask(quota_client, file_message_loop), | 35 : QuotaThreadTask(quota_client, file_message_loop), |
| 36 quota_client_(quota_client), | 36 quota_client_(quota_client), |
| 37 origin_url_(origin_url), | 37 origin_url_(origin_url), |
| 38 type_(type), | 38 type_(type), |
| 39 fs_usage_(0) { | 39 fs_usage_(0) { |
| 40 DCHECK(quota_client_); | 40 DCHECK(quota_client_); |
| 41 file_system_context_ = quota_client_->file_system_context_; | 41 file_system_context_ = quota_client_->file_system_context_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 protected: |
| 44 virtual ~GetOriginUsageTask() {} | 45 virtual ~GetOriginUsageTask() {} |
| 45 | 46 |
| 46 protected: | 47 // QuotaThreadTask: |
| 47 virtual void RunOnTargetThread() OVERRIDE { | 48 virtual void RunOnTargetThread() OVERRIDE { |
| 48 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); | 49 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); |
| 49 if (quota_util) | 50 if (quota_util) |
| 50 fs_usage_ = quota_util->GetOriginUsageOnFileThread(origin_url_, type_); | 51 fs_usage_ = quota_util->GetOriginUsageOnFileThread(origin_url_, type_); |
| 51 } | 52 } |
| 52 | 53 |
| 53 virtual void Completed() OVERRIDE { | 54 virtual void Completed() OVERRIDE { |
| 54 quota_client_->DidGetOriginUsage(type_, origin_url_, fs_usage_); | 55 quota_client_->DidGetOriginUsage(type_, origin_url_, fs_usage_); |
| 55 } | 56 } |
| 56 | 57 |
| 57 FileSystemQuotaClient* quota_client_; | 58 FileSystemQuotaClient* quota_client_; |
| 58 scoped_refptr<FileSystemContext> file_system_context_; | 59 scoped_refptr<FileSystemContext> file_system_context_; |
| 59 GURL origin_url_; | 60 GURL origin_url_; |
| 60 FileSystemType type_; | 61 FileSystemType type_; |
| 61 int64 fs_usage_; | 62 int64 fs_usage_; |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { | 65 class FileSystemQuotaClient::GetOriginsForTypeTask : public QuotaThreadTask { |
| 65 public: | 66 public: |
| 66 GetOriginsForTypeTask( | 67 GetOriginsForTypeTask( |
| 67 FileSystemQuotaClient* quota_client, | 68 FileSystemQuotaClient* quota_client, |
| 68 scoped_refptr<MessageLoopProxy> file_message_loop, | 69 scoped_refptr<MessageLoopProxy> file_message_loop, |
| 69 FileSystemType type) | 70 FileSystemType type) |
| 70 : QuotaThreadTask(quota_client, file_message_loop), | 71 : QuotaThreadTask(quota_client, file_message_loop), |
| 71 quota_client_(quota_client), | 72 quota_client_(quota_client), |
| 72 type_(type) { | 73 type_(type) { |
| 73 DCHECK(quota_client_); | 74 DCHECK(quota_client_); |
| 74 file_system_context_ = quota_client_->file_system_context_; | 75 file_system_context_ = quota_client_->file_system_context_; |
| 75 } | 76 } |
| 77 |
| 78 protected: |
| 76 virtual ~GetOriginsForTypeTask() {} | 79 virtual ~GetOriginsForTypeTask() {} |
| 77 | 80 |
| 78 protected: | 81 // QuotaThreadTask: |
| 79 virtual void RunOnTargetThread() OVERRIDE { | 82 virtual void RunOnTargetThread() OVERRIDE { |
| 80 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); | 83 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); |
| 81 if (quota_util) | 84 if (quota_util) |
| 82 quota_util->GetOriginsForTypeOnFileThread(type_, &origins_); | 85 quota_util->GetOriginsForTypeOnFileThread(type_, &origins_); |
| 83 } | 86 } |
| 84 | 87 |
| 85 virtual void Completed() OVERRIDE { | 88 virtual void Completed() OVERRIDE { |
| 86 quota_client_->DidGetOriginsForType(type_, origins_); | 89 quota_client_->DidGetOriginsForType(type_, origins_); |
| 87 } | 90 } |
| 88 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 scoped_refptr<MessageLoopProxy> file_message_loop, | 103 scoped_refptr<MessageLoopProxy> file_message_loop, |
| 101 FileSystemType type, | 104 FileSystemType type, |
| 102 const std::string& host) | 105 const std::string& host) |
| 103 : QuotaThreadTask(quota_client, file_message_loop), | 106 : QuotaThreadTask(quota_client, file_message_loop), |
| 104 quota_client_(quota_client), | 107 quota_client_(quota_client), |
| 105 type_(type), | 108 type_(type), |
| 106 host_(host) { | 109 host_(host) { |
| 107 DCHECK(quota_client_); | 110 DCHECK(quota_client_); |
| 108 file_system_context_ = quota_client_->file_system_context_; | 111 file_system_context_ = quota_client_->file_system_context_; |
| 109 } | 112 } |
| 113 |
| 114 protected: |
| 110 virtual ~GetOriginsForHostTask() {} | 115 virtual ~GetOriginsForHostTask() {} |
| 111 | 116 |
| 112 protected: | 117 // QuotaThreadTask: |
| 113 virtual void RunOnTargetThread() OVERRIDE { | 118 virtual void RunOnTargetThread() OVERRIDE { |
| 114 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); | 119 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type_); |
| 115 if (quota_util) | 120 if (quota_util) |
| 116 quota_util->GetOriginsForHostOnFileThread(type_, host_, &origins_); | 121 quota_util->GetOriginsForHostOnFileThread(type_, host_, &origins_); |
| 117 } | 122 } |
| 118 | 123 |
| 119 virtual void Completed() OVERRIDE { | 124 virtual void Completed() OVERRIDE { |
| 120 quota_client_->DidGetOriginsForHost(std::make_pair(type_, host_), origins_); | 125 quota_client_->DidGetOriginsForHost(std::make_pair(type_, host_), origins_); |
| 121 } | 126 } |
| 122 | 127 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 138 FileSystemType type, | 143 FileSystemType type, |
| 139 const DeletionCallback& callback) | 144 const DeletionCallback& callback) |
| 140 : QuotaThreadTask(quota_client, file_message_loop), | 145 : QuotaThreadTask(quota_client, file_message_loop), |
| 141 file_system_context_(quota_client->file_system_context_), | 146 file_system_context_(quota_client->file_system_context_), |
| 142 origin_(origin), | 147 origin_(origin), |
| 143 type_(type), | 148 type_(type), |
| 144 status_(quota::kQuotaStatusUnknown), | 149 status_(quota::kQuotaStatusUnknown), |
| 145 callback_(callback) { | 150 callback_(callback) { |
| 146 } | 151 } |
| 147 | 152 |
| 153 protected: |
| 148 virtual ~DeleteOriginTask() {} | 154 virtual ~DeleteOriginTask() {} |
| 149 | 155 |
| 156 // QuotaThreadTask: |
| 150 virtual void RunOnTargetThread() OVERRIDE { | 157 virtual void RunOnTargetThread() OVERRIDE { |
| 151 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( | 158 if (file_system_context_->DeleteDataForOriginAndTypeOnFileThread( |
| 152 origin_, type_)) | 159 origin_, type_)) |
| 153 status_ = quota::kQuotaStatusOk; | 160 status_ = quota::kQuotaStatusOk; |
| 154 else | 161 else |
| 155 status_ = quota::kQuotaErrorInvalidModification; | 162 status_ = quota::kQuotaErrorInvalidModification; |
| 156 } | 163 } |
| 157 | 164 |
| 158 virtual void Completed() OVERRIDE { | 165 virtual void Completed() OVERRIDE { |
| 159 callback_.Run(status_); | 166 callback_.Run(status_); |
| 160 } | 167 } |
| 168 |
| 161 private: | 169 private: |
| 162 FileSystemContext* file_system_context_; | 170 FileSystemContext* file_system_context_; |
| 163 GURL origin_; | 171 GURL origin_; |
| 164 FileSystemType type_; | 172 FileSystemType type_; |
| 165 quota::QuotaStatusCode status_; | 173 quota::QuotaStatusCode status_; |
| 166 DeletionCallback callback_; | 174 DeletionCallback callback_; |
| 167 }; | 175 }; |
| 168 | 176 |
| 169 FileSystemQuotaClient::FileSystemQuotaClient( | 177 FileSystemQuotaClient::FileSystemQuotaClient( |
| 170 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 178 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
| 171 FileSystemContext* file_system_context, | 179 FileSystemContext* file_system_context, |
| 172 bool is_incognito) | 180 bool is_incognito) |
| 173 : file_message_loop_(file_message_loop), | 181 : file_message_loop_(file_message_loop), |
| 174 file_system_context_(file_system_context), | 182 file_system_context_(file_system_context), |
| 175 is_incognito_(is_incognito) { | 183 is_incognito_(is_incognito) { |
| 176 DCHECK(file_message_loop); | 184 DCHECK(file_message_loop); |
| 177 } | 185 } |
| 178 | 186 |
| 179 FileSystemQuotaClient::~FileSystemQuotaClient() { | 187 FileSystemQuotaClient::~FileSystemQuotaClient() {} |
| 180 } | |
| 181 | 188 |
| 182 quota::QuotaClient::ID FileSystemQuotaClient::id() const { | 189 quota::QuotaClient::ID FileSystemQuotaClient::id() const { |
| 183 return quota::QuotaClient::kFileSystem; | 190 return quota::QuotaClient::kFileSystem; |
| 184 } | 191 } |
| 185 | 192 |
| 186 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { | 193 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { |
| 187 delete this; | 194 delete this; |
| 188 } | 195 } |
| 189 | 196 |
| 190 void FileSystemQuotaClient::GetOriginUsage( | 197 void FileSystemQuotaClient::GetOriginUsage( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 291 } |
| 285 | 292 |
| 286 void FileSystemQuotaClient::DidGetOriginsForHost( | 293 void FileSystemQuotaClient::DidGetOriginsForHost( |
| 287 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { | 294 const TypeAndHostOrOrigin& type_and_host, const std::set<GURL>& origins) { |
| 288 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); | 295 DCHECK(pending_origins_for_host_callbacks_.HasCallbacks(type_and_host)); |
| 289 pending_origins_for_host_callbacks_.Run(type_and_host, origins, | 296 pending_origins_for_host_callbacks_.Run(type_and_host, origins, |
| 290 FileSystemTypeToQuotaStorageType(type_and_host.first)); | 297 FileSystemTypeToQuotaStorageType(type_and_host.first)); |
| 291 } | 298 } |
| 292 | 299 |
| 293 } // namespace fileapi | 300 } // namespace fileapi |
| OLD | NEW |