Chromium Code Reviews| 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 "base/bind.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/stl_util.h" | |
| 10 #include "content/browser/payments/payment_app_manager.h" | |
| 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 PaymentAppContext::PaymentAppContext() { | |
| 17 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 18 } | |
| 19 | |
| 20 PaymentAppContext::~PaymentAppContext() { | |
| 21 DCHECK(services_.empty()); | |
| 22 } | |
| 23 | |
| 24 void PaymentAppContext::Init( | |
| 25 const scoped_refptr<ServiceWorkerContextWrapper>& context) { | |
| 26 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 27 } | |
| 28 | |
| 29 void PaymentAppContext::Shutdown() { | |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 31 | |
| 32 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 33 base::Bind(&PaymentAppContext::ShutdownOnIO, this)); | |
| 34 } | |
| 35 | |
| 36 void PaymentAppContext::CreateService( | |
| 37 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 39 | |
| 40 BrowserThread::PostTask( | |
| 41 BrowserThread::IO, FROM_HERE, | |
| 42 base::Bind(&PaymentAppContext::CreateServiceOnIOThread, this, | |
| 43 base::Passed(&request))); | |
| 44 } | |
| 45 | |
| 46 void PaymentAppContext::ServiceHadConnectionError(PaymentAppManager* service) { | |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 48 DCHECK(base::ContainsKey(services_, service)); | |
| 49 | |
| 50 services_.erase(service); | |
| 51 } | |
| 52 | |
| 53 void PaymentAppContext::CreateServiceOnIOThread( | |
| 54 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) { | |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 56 PaymentAppManager* service = new PaymentAppManager(this, std::move(request)); | |
| 57 services_[service] = base::WrapUnique(service); | |
|
jkarlin
2016/11/08 13:48:53
Prefer to use base::MakeUnique. Suggest:
services
zino
2016/11/08 14:34:21
Sorry, I don't understand your comment exactly.
D
jkarlin
2016/11/08 14:45:03
Ah, sorry, didn't notice that service was the key
| |
| 58 } | |
| 59 | |
| 60 void PaymentAppContext::ShutdownOnIO() { | |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 62 | |
| 63 services_.clear(); | |
| 64 } | |
| 65 | |
| 66 } // namespace content | |
| OLD | NEW |