| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/payments/payment_app_context_impl.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/stl_util.h" |
| 12 #include "content/browser/payments/payment_app_manager.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 PaymentAppContextImpl::PaymentAppContextImpl( |
| 19 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
| 20 : service_worker_context_(std::move(service_worker_context)), |
| 21 weak_ptr_factory_(this) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 23 } |
| 24 |
| 25 PaymentAppContextImpl::~PaymentAppContextImpl() { |
| 26 DCHECK(services_.empty()); |
| 27 } |
| 28 |
| 29 void PaymentAppContextImpl::Shutdown() { |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 |
| 32 BrowserThread::PostTask( |
| 33 BrowserThread::IO, FROM_HERE, |
| 34 base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this)); |
| 35 } |
| 36 |
| 37 void PaymentAppContextImpl::CreateService( |
| 38 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 |
| 41 BrowserThread::PostTask( |
| 42 BrowserThread::IO, FROM_HERE, |
| 43 base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this, |
| 44 base::Passed(&request))); |
| 45 } |
| 46 |
| 47 void PaymentAppContextImpl::ServiceHadConnectionError( |
| 48 PaymentAppManager* service) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 DCHECK(base::ContainsKey(services_, service)); |
| 51 |
| 52 services_.erase(service); |
| 53 } |
| 54 |
| 55 ServiceWorkerContextWrapper* PaymentAppContextImpl::service_worker_context() |
| 56 const { |
| 57 return service_worker_context_.get(); |
| 58 } |
| 59 |
| 60 void PaymentAppContextImpl::GetAllManifests( |
| 61 const GetAllManifestsCallback& callback) { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 63 LOG(INFO) << "GetAllManifests"; |
| 64 BrowserThread::PostTask( |
| 65 BrowserThread::IO, FROM_HERE, |
| 66 base::Bind(&PaymentAppContextImpl::GetAllManifestsOnIO, this, callback)); |
| 67 } |
| 68 |
| 69 void PaymentAppContextImpl::GetAllManifestsOnIO(const GetAllManifestsCallback& c
allback) { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 71 LOG(INFO) << "GetAllManifestsOnIO"; |
| 72 service_worker_context_->GetUserDataForAllRegistrations("PaymentAppManifestDat
a", base::Bind(&PaymentAppContextImpl::DidGetAllManifests, this, callback)); |
| 73 } |
| 74 |
| 75 void PaymentAppContextImpl::DidGetAllManifests( |
| 76 const GetAllManifestsCallback& callback, |
| 77 const std::vector<std::pair<int64_t, std::string>>& user_data, |
| 78 ServiceWorkerStatusCode status) { |
| 79 LOG(INFO) << "DidGetAllManifests"; |
| 80 LOG(INFO) << user_data.size(); |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 82 |
| 83 // Something |
| 84 |
| 85 //BrowserThread::PostTask( |
| 86 // BrowserThread::UI, FROM_HERE, |
| 87 // base::Bind(&PaymentAppContextImpl::GetAll, this, callback)); |
| 88 } |
| 89 |
| 90 void PaymentAppContextImpl::CreateServiceOnIOThread( |
| 91 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 93 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); |
| 94 services_[service] = base::WrapUnique(service); |
| 95 } |
| 96 |
| 97 void PaymentAppContextImpl::ShutdownOnIO() { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 |
| 100 services_.clear(); |
| 101 } |
| 102 |
| 103 } // namespace content |
| OLD | NEW |