1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "components/gcm_driver/gcm_app_handler.h"
11 #include "components/gcm_driver/gcm_client.h"
12 #include "content/public/browser/push_messaging_service.h"
13 #include "content/public/common/push_messaging_status.h"
14 #include "third_party/WebKit/public/platform/WebPushPermissionStatus.h"
18 namespace user_prefs {
19 class PrefRegistrySyncable;
24 class GCMProfileService;
25 struct PushMessagingApplicationId;
27 class PushMessagingServiceImpl : public content::PushMessagingService,
28 public GCMAppHandler {
30 // Register profile-specific prefs for GCM.
31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
33 // If any Service Workers are using push, starts GCM and adds an app handler.
34 static void InitializeForProfile(Profile* profile);
36 PushMessagingServiceImpl(GCMProfileService* gcm_profile_service,
38 ~PushMessagingServiceImpl() override;
40 // GCMAppHandler implementation.
41 void ShutdownHandler() override;
42 void OnMessage(const std::string& app_id,
43 const GCMClient::IncomingMessage& message) override;
44 void OnMessagesDeleted(const std::string& app_id) override;
46 const std::string& app_id,
47 const GCMClient::SendErrorDetails& send_error_details) override;
48 void OnSendAcknowledged(const std::string& app_id,
49 const std::string& message_id) override;
50 bool CanHandle(const std::string& app_id) const override;
52 // content::PushMessagingService implementation:
55 int64 service_worker_registration_id,
56 const std::string& sender_id,
60 const content::PushMessagingService::RegisterCallback& callback) override;
61 blink::WebPushPermissionStatus GetPermissionStatus(
62 const GURL& requesting_origin,
64 int render_frame_id) override;
66 void SetProfileForTesting(Profile* profile);
69 void DeliverMessageCallback(const PushMessagingApplicationId& application_id,
70 const GCMClient::IncomingMessage& message,
71 content::PushDeliveryStatus status);
74 const content::PushMessagingService::RegisterCallback& callback,
75 const std::string& registration_id,
76 content::PushRegistrationStatus status);
79 const content::PushMessagingService::RegisterCallback& callback,
80 const std::string& registration_id,
81 GCMClient::Result result);
83 void DidRequestPermission(
84 const PushMessagingApplicationId& application_id,
85 const std::string& sender_id,
86 const content::PushMessagingService::RegisterCallback& callback,
89 GCMProfileService* gcm_profile_service_; // It owns us.
91 Profile* profile_; // It owns our owner.
93 base::WeakPtrFactory<PushMessagingServiceImpl> weak_factory_;
95 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl);
100 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_