[Payment Request] Change the lifetime management of PaymentRequestImpl

Was previously 1 PaymentRequestImpl per WebContents. Now there is a
PaymentRequestWebContentsManager (1 per WebContents) that owns all the
PaymentRequestImpl's, whose raw pointers are shared with the delegate
and the mojo bindings.

Also, moving PaymentRequestImpl from chrome/ to components/ which creates
the need for a PaymentRequestDelegate (initially managing the Chrome
dialog).

BUG=678302

Review-Url: https://codereview.chromium.org/2611253004
Cr-Commit-Position: refs/heads/master@{#442335}
diff --git a/components/payments/payment_request.h b/components/payments/payment_request.h
new file mode 100644
index 0000000..cbd0e24
--- /dev/null
+++ b/components/payments/payment_request.h
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
+#define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
+
+#include <memory>
+
+#include "components/payments/payment_request.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace content {
+class WebContents;
+}
+
+namespace payments {
+
+class PaymentRequestDelegate;
+class PaymentRequestWebContentsManager;
+
+class PaymentRequest : payments::mojom::PaymentRequest {
+ public:
+  PaymentRequest(
+      content::WebContents* web_contents,
+      std::unique_ptr<PaymentRequestDelegate> delegate,
+      PaymentRequestWebContentsManager* manager,
+      mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
+  ~PaymentRequest() override;
+
+  // payments::mojom::PaymentRequest "stub"
+  void Init(payments::mojom::PaymentRequestClientPtr client,
+            std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
+            payments::mojom::PaymentDetailsPtr details,
+            payments::mojom::PaymentOptionsPtr options) override;
+  void Show() override;
+  void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {}
+  void Abort() override {}
+  void Complete(payments::mojom::PaymentComplete result) override {}
+  void CanMakePayment() override {}
+
+  void Cancel();
+  void OnError();
+  payments::mojom::PaymentDetails* details() { return details_.get(); }
+
+  content::WebContents* web_contents() { return web_contents_; }
+
+ private:
+  content::WebContents* web_contents_;
+  std::unique_ptr<PaymentRequestDelegate> delegate_;
+  // |manager_| owns this PaymentRequest.
+  PaymentRequestWebContentsManager* manager_;
+  mojo::Binding<payments::mojom::PaymentRequest> binding_;
+  payments::mojom::PaymentRequestClientPtr client_;
+  payments::mojom::PaymentDetailsPtr details_;
+
+  DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
+};
+
+}  // namespace payments
+
+#endif  // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_