Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "components/payments/android/payment_manifest_web_data_service.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 | |
| 10 namespace payments { | |
| 11 | |
| 12 PaymentManifestWebDataService::PaymentManifestWebDataService( | |
| 13 scoped_refptr<WebDatabaseService> wdbs, | |
| 14 const ProfileErrorCallback& callback, | |
| 15 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread) | |
| 16 : WebDataServiceBase(wdbs, callback, ui_thread) {} | |
| 17 | |
| 18 PaymentManifestWebDataService::~PaymentManifestWebDataService() {} | |
| 19 | |
| 20 void PaymentManifestWebDataService::AddPaymentWebAppManifest( | |
| 21 const std::vector<mojom::WebAppManifestSectionPtr>& manifest) { | |
|
please use gerrit instead
2017/04/24 18:22:32
I recommend that you change the type of this param
gogerald1
2017/04/26 13:46:33
I can not move it since the input manifest is also
| |
| 22 // Make a copy of |manifest| to be used in DB thread. | |
| 23 // Note that mojom::WebAppManifestSectionPtr is DISALLOW_COPY_AND_ASSIGN. | |
|
please use gerrit instead
2017/04/24 18:22:32
Actually, mojom::WebAppManifestSectionPtr is a mov
gogerald1
2017/04/26 13:46:33
Acknowledged.
| |
| 24 std::vector<mojom::WebAppManifestSectionPtr> manifest_copy; | |
| 25 for (size_t i = 0; i < manifest.size(); i++) { | |
| 26 manifest_copy.emplace_back(manifest[i].Clone()); | |
| 27 } | |
| 28 | |
| 29 wdbs_->ScheduleDBTask( | |
| 30 FROM_HERE, | |
| 31 base::Bind(&PaymentManifestWebDataService::AddPaymentWebAppManifestImpl, | |
| 32 this, std::move(manifest_copy))); | |
| 33 } | |
| 34 | |
| 35 WebDatabase::State PaymentManifestWebDataService::AddPaymentWebAppManifestImpl( | |
| 36 const std::vector<mojom::WebAppManifestSectionPtr>& manifest, | |
| 37 WebDatabase* db) { | |
| 38 if (WebAppManifestSectionTable::FromWebDatabase(db)->AddWebAppManifest( | |
| 39 manifest)) { | |
| 40 return WebDatabase::COMMIT_NEEDED; | |
| 41 } | |
| 42 | |
| 43 return WebDatabase::COMMIT_NOT_NEEDED; | |
| 44 } | |
| 45 | |
| 46 WebDataServiceBase::Handle | |
| 47 PaymentManifestWebDataService::GetPaymentWebAppManifest( | |
| 48 const std::string& web_app, | |
| 49 WebDataServiceConsumer* consumer) { | |
| 50 return wdbs_->ScheduleDBTaskWithResult( | |
| 51 FROM_HERE, | |
| 52 base::Bind(&PaymentManifestWebDataService::GetPaymentWebAppManifestImpl, | |
| 53 this, web_app), | |
| 54 consumer); | |
| 55 } | |
| 56 | |
| 57 std::unique_ptr<WDTypedResult> | |
| 58 PaymentManifestWebDataService::GetPaymentWebAppManifestImpl( | |
| 59 const std::string& web_app, | |
| 60 WebDatabase* db) { | |
| 61 std::unique_ptr<WDTypedResult> result_ptr; | |
| 62 | |
| 63 result_ptr.reset(new WDResult<std::vector<mojom::WebAppManifestSectionPtr>>( | |
|
please use gerrit instead
2017/04/24 18:22:32
Use base::MakeUnique.
return base::MakeUnique<WDR
gogerald1
2017/04/26 13:46:33
Done.
| |
| 64 PAYMENT_WEB_APP_MANIFEST, | |
| 65 WebAppManifestSectionTable::FromWebDatabase(db)->GetWebAppManifest( | |
| 66 web_app))); | |
| 67 | |
| 68 return result_ptr; | |
| 69 } | |
| 70 | |
| 71 void PaymentManifestWebDataService::AddPaymentMethodManifest( | |
| 72 const std::string& payment_method, | |
| 73 const std::vector<std::string>& web_app_ids) { | |
| 74 wdbs_->ScheduleDBTask( | |
| 75 FROM_HERE, | |
| 76 base::Bind(&PaymentManifestWebDataService::AddPaymentMethodManifestImpl, | |
| 77 this, payment_method, web_app_ids)); | |
| 78 } | |
| 79 | |
| 80 WebDatabase::State PaymentManifestWebDataService::AddPaymentMethodManifestImpl( | |
| 81 const std::string& payment_method, | |
| 82 const std::vector<std::string>& web_app_ids, | |
| 83 WebDatabase* db) { | |
| 84 if (PaymentMethodManifestTable::FromWebDatabase(db)->AddManifest( | |
| 85 payment_method, web_app_ids)) { | |
| 86 return WebDatabase::COMMIT_NEEDED; | |
| 87 } | |
| 88 | |
| 89 return WebDatabase::COMMIT_NOT_NEEDED; | |
| 90 } | |
| 91 | |
| 92 WebDataServiceBase::Handle | |
| 93 PaymentManifestWebDataService::GetPaymentMethodManifest( | |
| 94 const std::string& payment_method, | |
| 95 WebDataServiceConsumer* consumer) { | |
| 96 return wdbs_->ScheduleDBTaskWithResult( | |
| 97 FROM_HERE, | |
| 98 base::Bind(&PaymentManifestWebDataService::GetPaymentMethodManifestImpl, | |
| 99 this, payment_method), | |
| 100 consumer); | |
| 101 } | |
| 102 | |
| 103 std::unique_ptr<WDTypedResult> | |
| 104 PaymentManifestWebDataService::GetPaymentMethodManifestImpl( | |
| 105 const std::string& payment_method, | |
| 106 WebDatabase* db) { | |
| 107 std::unique_ptr<WDTypedResult> result_ptr; | |
| 108 | |
| 109 result_ptr.reset(new WDResult<std::vector<std::string>>( | |
|
please use gerrit instead
2017/04/24 18:22:32
Ditto.
gogerald1
2017/04/26 13:46:33
Done.
| |
| 110 PAYMENT_METHOD_MANIFEST, | |
| 111 PaymentMethodManifestTable::FromWebDatabase(db)->GetManifest( | |
| 112 payment_method))); | |
| 113 | |
| 114 return result_ptr; | |
| 115 } | |
| 116 | |
| 117 } // namespace payments | |
| OLD | NEW |