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"
17 namespace user_prefs
{
18 class PrefRegistrySyncable
;
23 class GCMProfileService
;
24 struct PushMessagingApplicationId
;
26 class PushMessagingServiceImpl
: public content::PushMessagingService
,
27 public GCMAppHandler
{
29 // Register profile-specific prefs for GCM.
30 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
32 // If any Service Workers are using push, starts GCM and adds an app handler.
33 static void InitializeForProfile(Profile
* profile
);
35 PushMessagingServiceImpl(GCMProfileService
* gcm_profile_service
,
37 virtual ~PushMessagingServiceImpl();
39 // GCMAppHandler implementation.
40 virtual void ShutdownHandler() override
;
41 virtual void OnMessage(const std::string
& app_id
,
42 const GCMClient::IncomingMessage
& message
) override
;
43 virtual void OnMessagesDeleted(const std::string
& app_id
) override
;
44 virtual void OnSendError(
45 const std::string
& app_id
,
46 const GCMClient::SendErrorDetails
& send_error_details
) override
;
47 virtual void OnSendAcknowledged(const std::string
& app_id
,
48 const std::string
& message_id
) override
;
49 virtual bool CanHandle(const std::string
& app_id
) const override
;
51 // content::PushMessagingService implementation:
52 virtual void Register(
54 int64 service_worker_registration_id
,
55 const std::string
& sender_id
,
59 const content::PushMessagingService::RegisterCallback
& callback
) override
;
62 void DeliverMessageCallback(const PushMessagingApplicationId
& application_id
,
63 const GCMClient::IncomingMessage
& message
,
64 content::PushDeliveryStatus status
);
67 const content::PushMessagingService::RegisterCallback
& callback
,
68 const std::string
& registration_id
,
69 content::PushRegistrationStatus status
);
72 const content::PushMessagingService::RegisterCallback
& callback
,
73 const std::string
& registration_id
,
74 GCMClient::Result result
);
76 void DidRequestPermission(
77 const PushMessagingApplicationId
& application_id
,
78 const std::string
& sender_id
,
79 const content::PushMessagingService::RegisterCallback
& callback
,
82 GCMProfileService
* gcm_profile_service_
; // It owns us.
84 Profile
* profile_
; // It owns our owner.
86 base::WeakPtrFactory
<PushMessagingServiceImpl
> weak_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(PushMessagingServiceImpl
);
93 #endif // CHROME_BROWSER_SERVICES_GCM_PUSH_MESSAGING_SERVICE_IMPL_H_