blob: 91fca891c9fe12a4f37b65c7c94fb46ea4fda434 [file] [log] [blame]
[email protected]240fc7e2014-03-20 06:52:201// 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.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
7
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]df84c532014-04-25 15:36:549#include <string>
10
11#include "base/compiler_specific.h"
12#include "base/macros.h"
[email protected]240fc7e2014-03-20 06:52:2013#include "base/memory/weak_ptr.h"
Sigurdur Asgeirsson2c442dc2021-03-25 13:41:2014#include "base/scoped_observation.h"
Rayan Kanso7b3b5ea2019-05-08 18:15:0015#include "components/gcm_driver/common/gcm_message.h"
[email protected]446f73c22014-05-14 20:47:1816#include "components/gcm_driver/gcm_app_handler.h"
[email protected]cd57f372014-06-09 17:13:0617#include "components/gcm_driver/gcm_client.h"
jianli7898ae712015-06-04 19:47:0618#include "components/gcm_driver/instance_id/instance_id.h"
[email protected]2f3617042014-03-21 22:44:3619#include "extensions/browser/browser_context_keyed_api_factory.h"
Evan Stade75872a62019-09-06 21:17:3820#include "extensions/browser/extension_registry.h"
[email protected]96ac5962014-04-22 19:49:5821#include "extensions/browser/extension_registry_observer.h"
[email protected]240fc7e2014-03-20 06:52:2022
23class Profile;
[email protected]df84c532014-04-25 15:36:5424
[email protected]2f3617042014-03-21 22:44:3625namespace content {
26class BrowserContext;
27}
[email protected]df84c532014-04-25 15:36:5428
[email protected]240fc7e2014-03-20 06:52:2029namespace gcm {
[email protected]9d7e5c02014-05-21 03:09:0330class GCMDriver;
[email protected]240fc7e2014-03-20 06:52:2031}
jianli7898ae712015-06-04 19:47:0632namespace instance_id {
33class InstanceIDDriver;
34}
[email protected]240fc7e2014-03-20 06:52:2035
36namespace extensions {
37
38class GcmJsEventRouter;
39
40// Defines the interface to provide handling logic for a given app.
41class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
[email protected]2f3617042014-03-21 22:44:3642 public BrowserContextKeyedAPI,
[email protected]96ac5962014-04-22 19:49:5843 public ExtensionRegistryObserver {
[email protected]240fc7e2014-03-20 06:52:2044 public:
[email protected]2f3617042014-03-21 22:44:3645 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
Peter Boström53c6c5952021-09-17 09:41:2646
47 ExtensionGCMAppHandler(const ExtensionGCMAppHandler&) = delete;
48 ExtensionGCMAppHandler& operator=(const ExtensionGCMAppHandler&) = delete;
49
dchengae36a4a2014-10-21 12:36:3650 ~ExtensionGCMAppHandler() override;
[email protected]240fc7e2014-03-20 06:52:2051
[email protected]2f3617042014-03-21 22:44:3652 // BrowserContextKeyedAPI implementation.
53 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
54 GetFactoryInstance();
sense383ce0f2017-03-24 04:06:4355 void Shutdown() override;
[email protected]2f3617042014-03-21 22:44:3656
57 // gcm::GCMAppHandler implementation.
dchengae36a4a2014-10-21 12:36:3658 void ShutdownHandler() override;
johnme93ec7932016-11-17 14:26:5859 void OnStoreReset() override;
dchengae36a4a2014-10-21 12:36:3660 void OnMessage(const std::string& app_id,
mvanouwerkerkf8633deb2015-07-13 11:04:0661 const gcm::IncomingMessage& message) override;
dchengae36a4a2014-10-21 12:36:3662 void OnMessagesDeleted(const std::string& app_id) override;
63 void OnSendError(
[email protected]240fc7e2014-03-20 06:52:2064 const std::string& app_id,
mostynba15bee12014-10-04 00:40:3265 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
dchengae36a4a2014-10-21 12:36:3666 void OnSendAcknowledged(const std::string& app_id,
67 const std::string& message_id) override;
[email protected]240fc7e2014-03-20 06:52:2068
[email protected]2ac46732014-04-03 23:14:3169 protected:
[email protected]1182aa1b2014-06-17 21:19:5170 // Could be overridden by testing purpose.
[email protected]2ac46732014-04-03 23:14:3171 virtual void OnUnregisterCompleted(const std::string& app_id,
72 gcm::GCMClient::Result result);
jianli7898ae712015-06-04 19:47:0673 virtual void OnDeleteIDCompleted(const std::string& app_id,
74 instance_id::InstanceID::Result result);
[email protected]1182aa1b2014-06-17 21:19:5175 virtual void AddAppHandler(const std::string& app_id);
76 virtual void RemoveAppHandler(const std::string& app_id);
[email protected]2ac46732014-04-03 23:14:3177
[email protected]1182aa1b2014-06-17 21:19:5178 gcm::GCMDriver* GetGCMDriver() const;
jianli7898ae712015-06-04 19:47:0679 instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
[email protected]1182aa1b2014-06-17 21:19:5180
jianlic5f6bd92015-05-28 02:23:4581 private:
[email protected]2f3617042014-03-21 22:44:3682 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
83
[email protected]96ac5962014-04-22 19:49:5884 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3685 void OnExtensionLoaded(content::BrowserContext* browser_context,
86 const Extension* extension) override;
87 void OnExtensionUnloaded(content::BrowserContext* browser_context,
88 const Extension* extension,
limasdf0deef2042017-05-03 19:17:1789 UnloadedExtensionReason reason) override;
dchengae36a4a2014-10-21 12:36:3690 void OnExtensionUninstalled(content::BrowserContext* browser_context,
91 const Extension* extension,
92 extensions::UninstallReason reason) override;
[email protected]96ac5962014-04-22 19:49:5893
jianli7898ae712015-06-04 19:47:0694 void RemoveInstanceID(const std::string& app_id);
[email protected]1182aa1b2014-06-17 21:19:5195 void AddDummyAppHandler();
96 void RemoveDummyAppHandler();
[email protected]240fc7e2014-03-20 06:52:2097
[email protected]2f3617042014-03-21 22:44:3698 // BrowserContextKeyedAPI implementation.
99 static const char* service_name() { return "ExtensionGCMAppHandler"; }
100 static const bool kServiceIsNULLWhileTesting = true;
101
[email protected]240fc7e2014-03-20 06:52:20102 Profile* profile_;
[email protected]240fc7e2014-03-20 06:52:20103
[email protected]96ac5962014-04-22 19:49:58104 // Listen to extension load, unloaded notifications.
Sigurdur Asgeirsson2c442dc2021-03-25 13:41:20105 base::ScopedObservation<ExtensionRegistry, ExtensionRegistryObserver>
106 extension_registry_observation_{this};
[email protected]96ac5962014-04-22 19:49:58107
dchengc963c7142016-04-08 03:55:22108 std::unique_ptr<extensions::GcmJsEventRouter> js_event_router_;
[email protected]240fc7e2014-03-20 06:52:20109
Jeremy Roman495db682019-07-12 16:03:24110 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_{this};
[email protected]240fc7e2014-03-20 06:52:20111};
112
113} // namespace extensions
114
115#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_