OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/appcache/appcache_service_impl.h" | 5 #include "content/browser/appcache/appcache_service_impl.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/stl_util.h" | |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "content/browser/appcache/appcache.h" | 18 #include "content/browser/appcache/appcache.h" |
19 #include "content/browser/appcache/appcache_backend_impl.h" | 19 #include "content/browser/appcache/appcache_backend_impl.h" |
20 #include "content/browser/appcache/appcache_entry.h" | 20 #include "content/browser/appcache/appcache_entry.h" |
21 #include "content/browser/appcache/appcache_executable_handler.h" | 21 #include "content/browser/appcache/appcache_executable_handler.h" |
22 #include "content/browser/appcache/appcache_histograms.h" | 22 #include "content/browser/appcache/appcache_histograms.h" |
23 #include "content/browser/appcache/appcache_policy.h" | 23 #include "content/browser/appcache/appcache_policy.h" |
24 #include "content/browser/appcache/appcache_quota_client.h" | 24 #include "content/browser/appcache/appcache_quota_client.h" |
25 #include "content/browser/appcache/appcache_response.h" | 25 #include "content/browser/appcache/appcache_response.h" |
26 #include "content/browser/appcache/appcache_service_impl.h" | 26 #include "content/browser/appcache/appcache_service_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
44 AppCacheInfoCollection::~AppCacheInfoCollection() {} | 44 AppCacheInfoCollection::~AppCacheInfoCollection() {} |
45 | 45 |
46 // AsyncHelper ------- | 46 // AsyncHelper ------- |
47 | 47 |
48 class AppCacheServiceImpl::AsyncHelper | 48 class AppCacheServiceImpl::AsyncHelper |
49 : public AppCacheStorage::Delegate { | 49 : public AppCacheStorage::Delegate { |
50 public: | 50 public: |
51 AsyncHelper(AppCacheServiceImpl* service, | 51 AsyncHelper(AppCacheServiceImpl* service, |
52 const net::CompletionCallback& callback) | 52 const net::CompletionCallback& callback) |
53 : service_(service), callback_(callback) { | 53 : service_(service), callback_(callback) { |
54 service_->pending_helpers_.insert(this); | 54 service_->pending_helpers_[this] = base::WrapUnique(this); |
55 } | 55 } |
56 | 56 |
57 ~AsyncHelper() override { | 57 ~AsyncHelper() override { |
58 if (service_) | 58 if (service_) { |
| 59 service_->pending_helpers_[this].release(); |
59 service_->pending_helpers_.erase(this); | 60 service_->pending_helpers_.erase(this); |
| 61 } |
60 } | 62 } |
61 | 63 |
62 virtual void Start() = 0; | 64 virtual void Start() = 0; |
63 virtual void Cancel(); | 65 virtual void Cancel(); |
64 | 66 |
65 protected: | 67 protected: |
66 void CallCallback(int rv) { | 68 void CallCallback(int rv) { |
67 if (!callback_.is_null()) { | 69 if (!callback_.is_null()) { |
68 // Defer to guarantee async completion. | 70 // Defer to guarantee async completion. |
69 base::ThreadTaskRunnerHandle::Get()->PostTask( | 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
70 FROM_HERE, base::Bind(&DeferredCallback, callback_, rv)); | 72 FROM_HERE, base::Bind(&DeferredCallback, callback_, rv)); |
71 } | 73 } |
72 callback_.Reset(); | 74 callback_.Reset(); |
73 } | 75 } |
74 | 76 |
75 AppCacheServiceImpl* service_; | 77 AppCacheServiceImpl* service_; |
76 net::CompletionCallback callback_; | 78 net::CompletionCallback callback_; |
77 }; | 79 }; |
78 | 80 |
79 void AppCacheServiceImpl::AsyncHelper::Cancel() { | 81 void AppCacheServiceImpl::AsyncHelper::Cancel() { |
80 if (!callback_.is_null()) { | 82 if (!callback_.is_null()) { |
81 callback_.Run(net::ERR_ABORTED); | 83 callback_.Run(net::ERR_ABORTED); |
82 callback_.Reset(); | 84 callback_.Reset(); |
83 } | 85 } |
84 service_->storage()->CancelDelegateCallbacks(this); | 86 service_->storage()->CancelDelegateCallbacks(this); |
85 service_ = NULL; | 87 service_ = nullptr; |
86 } | 88 } |
87 | 89 |
88 // DeleteHelper ------- | 90 // DeleteHelper ------- |
89 | 91 |
90 class AppCacheServiceImpl::DeleteHelper : public AsyncHelper { | 92 class AppCacheServiceImpl::DeleteHelper : public AsyncHelper { |
91 public: | 93 public: |
92 DeleteHelper( | 94 DeleteHelper( |
93 AppCacheServiceImpl* service, const GURL& manifest_url, | 95 AppCacheServiceImpl* service, const GURL& manifest_url, |
94 const net::CompletionCallback& callback) | 96 const net::CompletionCallback& callback) |
95 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 97 : AsyncHelper(service, callback), manifest_url_(manifest_url) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 392 |
391 AppCacheStorageReference::AppCacheStorageReference( | 393 AppCacheStorageReference::AppCacheStorageReference( |
392 std::unique_ptr<AppCacheStorage> storage) | 394 std::unique_ptr<AppCacheStorage> storage) |
393 : storage_(std::move(storage)) {} | 395 : storage_(std::move(storage)) {} |
394 AppCacheStorageReference::~AppCacheStorageReference() {} | 396 AppCacheStorageReference::~AppCacheStorageReference() {} |
395 | 397 |
396 // AppCacheServiceImpl ------- | 398 // AppCacheServiceImpl ------- |
397 | 399 |
398 AppCacheServiceImpl::AppCacheServiceImpl( | 400 AppCacheServiceImpl::AppCacheServiceImpl( |
399 storage::QuotaManagerProxy* quota_manager_proxy) | 401 storage::QuotaManagerProxy* quota_manager_proxy) |
400 : appcache_policy_(NULL), | 402 : appcache_policy_(nullptr), |
401 quota_client_(NULL), | 403 quota_client_(nullptr), |
402 handler_factory_(NULL), | 404 handler_factory_(nullptr), |
403 quota_manager_proxy_(quota_manager_proxy), | 405 quota_manager_proxy_(quota_manager_proxy), |
404 request_context_(NULL), | 406 request_context_(nullptr), |
405 force_keep_session_state_(false), | 407 force_keep_session_state_(false), |
406 weak_factory_(this) { | 408 weak_factory_(this) { |
407 if (quota_manager_proxy_.get()) { | 409 if (quota_manager_proxy_.get()) { |
408 quota_client_ = new AppCacheQuotaClient(this); | 410 quota_client_ = new AppCacheQuotaClient(this); |
409 quota_manager_proxy_->RegisterClient(quota_client_); | 411 quota_manager_proxy_->RegisterClient(quota_client_); |
410 } | 412 } |
411 } | 413 } |
412 | 414 |
413 AppCacheServiceImpl::~AppCacheServiceImpl() { | 415 AppCacheServiceImpl::~AppCacheServiceImpl() { |
414 DCHECK(backends_.empty()); | 416 DCHECK(backends_.empty()); |
415 for (auto& observer : observers_) | 417 for (auto& observer : observers_) |
416 observer.OnServiceDestructionImminent(this); | 418 observer.OnServiceDestructionImminent(this); |
417 for (auto* helper : pending_helpers_) | 419 for (auto& helper : pending_helpers_) |
418 helper->Cancel(); | 420 helper.first->Cancel(); |
419 base::STLDeleteElements(&pending_helpers_); | 421 pending_helpers_.clear(); |
420 if (quota_client_) | 422 if (quota_client_) |
421 quota_client_->NotifyAppCacheDestroyed(); | 423 quota_client_->NotifyAppCacheDestroyed(); |
422 | 424 |
423 // Destroy storage_ first; ~AppCacheStorageImpl accesses other data members | 425 // Destroy storage_ first; ~AppCacheStorageImpl accesses other data members |
424 // (special_storage_policy_). | 426 // (special_storage_policy_). |
425 storage_.reset(); | 427 storage_.reset(); |
426 } | 428 } |
427 | 429 |
428 void AppCacheServiceImpl::Initialize( | 430 void AppCacheServiceImpl::Initialize( |
429 const base::FilePath& cache_directory, | 431 const base::FilePath& cache_directory, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 backends_.insert( | 521 backends_.insert( |
520 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 522 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
521 } | 523 } |
522 | 524 |
523 void AppCacheServiceImpl::UnregisterBackend( | 525 void AppCacheServiceImpl::UnregisterBackend( |
524 AppCacheBackendImpl* backend_impl) { | 526 AppCacheBackendImpl* backend_impl) { |
525 backends_.erase(backend_impl->process_id()); | 527 backends_.erase(backend_impl->process_id()); |
526 } | 528 } |
527 | 529 |
528 } // namespace content | 530 } // namespace content |
OLD | NEW |