blob: ef2b94c158ef77a3d47531cf58892837d20df135 [file] [log] [blame]
// Copyright 2019 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.
#include "base/macros.h"
#include "base/optional.h"
#include "components/gcm_driver/web_push_common.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace network {
class SimpleURLLoader;
} // namespace network
namespace crypto {
class ECPrivateKey;
namespace gcm {
struct WebPushMessage;
// Class for sending a message via Firebase Cloud Messaging (FCM) Web Push.
class WebPushSender {
explicit WebPushSender(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
// Sends a WebPushMessage via FCM Web Push. Authenticates with FCM server
// using Voluntary Application Server Identification for Web Push (VAPID)
// protocol.
// |fcm_token|: FCM registration token for receiving end.
// |vapid_key|: Private key to sign VAPID header.
// |message|: WebPushMessage to be sent.
// |callback|: To be invoked with message_id if asynchronous operation
// succeeded, or base::nullopt if operation failed.
void SendMessage(const std::string& fcm_token,
crypto::ECPrivateKey* vapid_key,
WebPushMessage message,
WebPushCallback callback);
void OnMessageSent(std::unique_ptr<network::SimpleURLLoader> url_loader,
WebPushCallback callback,
std::unique_ptr<std::string> response_body);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
base::WeakPtrFactory<WebPushSender> weak_ptr_factory_{this};
} // namespace gcm