blob: ff7d0550d757030333ed71217d2e5b4b04591849 [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"
[email protected]96ac5962014-04-22 19:49:5814#include "base/scoped_observer.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);
dchengae36a4a2014-10-21 12:36:3646 ~ExtensionGCMAppHandler() override;
[email protected]240fc7e2014-03-20 06:52:2047
[email protected]2f3617042014-03-21 22:44:3648 // BrowserContextKeyedAPI implementation.
49 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
50 GetFactoryInstance();
sense383ce0f2017-03-24 04:06:4351 void Shutdown() override;
[email protected]2f3617042014-03-21 22:44:3652
53 // gcm::GCMAppHandler implementation.
dchengae36a4a2014-10-21 12:36:3654 void ShutdownHandler() override;
johnme93ec7932016-11-17 14:26:5855 void OnStoreReset() override;
dchengae36a4a2014-10-21 12:36:3656 void OnMessage(const std::string& app_id,
mvanouwerkerkf8633deb2015-07-13 11:04:0657 const gcm::IncomingMessage& message) override;
dchengae36a4a2014-10-21 12:36:3658 void OnMessagesDeleted(const std::string& app_id) override;
59 void OnSendError(
[email protected]240fc7e2014-03-20 06:52:2060 const std::string& app_id,
mostynba15bee12014-10-04 00:40:3261 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
dchengae36a4a2014-10-21 12:36:3662 void OnSendAcknowledged(const std::string& app_id,
63 const std::string& message_id) override;
[email protected]240fc7e2014-03-20 06:52:2064
[email protected]2ac46732014-04-03 23:14:3165 protected:
[email protected]1182aa1b2014-06-17 21:19:5166 // Could be overridden by testing purpose.
[email protected]2ac46732014-04-03 23:14:3167 virtual void OnUnregisterCompleted(const std::string& app_id,
68 gcm::GCMClient::Result result);
jianli7898ae712015-06-04 19:47:0669 virtual void OnDeleteIDCompleted(const std::string& app_id,
70 instance_id::InstanceID::Result result);
[email protected]1182aa1b2014-06-17 21:19:5171 virtual void AddAppHandler(const std::string& app_id);
72 virtual void RemoveAppHandler(const std::string& app_id);
[email protected]2ac46732014-04-03 23:14:3173
[email protected]1182aa1b2014-06-17 21:19:5174 gcm::GCMDriver* GetGCMDriver() const;
jianli7898ae712015-06-04 19:47:0675 instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
[email protected]1182aa1b2014-06-17 21:19:5176
jianlic5f6bd92015-05-28 02:23:4577 private:
[email protected]2f3617042014-03-21 22:44:3678 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
79
[email protected]96ac5962014-04-22 19:49:5880 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3681 void OnExtensionLoaded(content::BrowserContext* browser_context,
82 const Extension* extension) override;
83 void OnExtensionUnloaded(content::BrowserContext* browser_context,
84 const Extension* extension,
limasdf0deef2042017-05-03 19:17:1785 UnloadedExtensionReason reason) override;
dchengae36a4a2014-10-21 12:36:3686 void OnExtensionUninstalled(content::BrowserContext* browser_context,
87 const Extension* extension,
88 extensions::UninstallReason reason) override;
[email protected]96ac5962014-04-22 19:49:5889
jianli7898ae712015-06-04 19:47:0690 void RemoveInstanceID(const std::string& app_id);
[email protected]1182aa1b2014-06-17 21:19:5191 void AddDummyAppHandler();
92 void RemoveDummyAppHandler();
[email protected]240fc7e2014-03-20 06:52:2093
[email protected]2f3617042014-03-21 22:44:3694 // BrowserContextKeyedAPI implementation.
95 static const char* service_name() { return "ExtensionGCMAppHandler"; }
96 static const bool kServiceIsNULLWhileTesting = true;
97
[email protected]240fc7e2014-03-20 06:52:2098 Profile* profile_;
[email protected]240fc7e2014-03-20 06:52:2099
[email protected]96ac5962014-04-22 19:49:58100 // Listen to extension load, unloaded notifications.
101 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
Evan Stade75872a62019-09-06 21:17:38102 extension_registry_observer_{this};
[email protected]96ac5962014-04-22 19:49:58103
dchengc963c7142016-04-08 03:55:22104 std::unique_ptr<extensions::GcmJsEventRouter> js_event_router_;
[email protected]240fc7e2014-03-20 06:52:20105
Jeremy Roman495db682019-07-12 16:03:24106 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_{this};
[email protected]240fc7e2014-03-20 06:52:20107
108 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
109};
110
111} // namespace extensions
112
113#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_