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.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 PaymentAppContext::PaymentAppContext( |
| 19 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
| 20 : service_worker_context_(std::move(service_worker_context)) { |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 22 } |
| 23 |
| 24 PaymentAppContext::~PaymentAppContext() { |
| 25 DCHECK(services_.empty()); |
| 26 } |
| 27 |
| 28 void PaymentAppContext::Shutdown() { |
| 29 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 30 |
| 31 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 32 base::Bind(&PaymentAppContext::ShutdownOnIO, this)); |
| 33 } |
| 34 |
| 35 void PaymentAppContext::CreateService( |
| 36 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 38 |
| 39 BrowserThread::PostTask( |
| 40 BrowserThread::IO, FROM_HERE, |
| 41 base::Bind(&PaymentAppContext::CreateServiceOnIOThread, this, |
| 42 base::Passed(&request))); |
| 43 } |
| 44 |
| 45 void PaymentAppContext::ServiceHadConnectionError(PaymentAppManager* service) { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 47 DCHECK(base::ContainsKey(services_, service)); |
| 48 |
| 49 services_.erase(service); |
| 50 } |
| 51 |
| 52 ServiceWorkerContextWrapper* PaymentAppContext::service_worker_context() const { |
| 53 return service_worker_context_.get(); |
| 54 } |
| 55 |
| 56 void PaymentAppContext::CreateServiceOnIOThread( |
| 57 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 59 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); |
| 60 services_[service] = base::WrapUnique(service); |
| 61 } |
| 62 |
| 63 void PaymentAppContext::ShutdownOnIO() { |
| 64 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 65 |
| 66 services_.clear(); |
| 67 } |
| 68 |
| 69 } // namespace content |
OLD | NEW |