blob: f2a5a6caee40d05ec1a8aa65144f12ae5a55fd38 [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
[email protected]df84c532014-04-25 15:36:548#include <string>
9
10#include "base/compiler_specific.h"
11#include "base/macros.h"
[email protected]240fc7e2014-03-20 06:52:2012#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
[email protected]96ac5962014-04-22 19:49:5814#include "base/scoped_observer.h"
[email protected]446f73c22014-05-14 20:47:1815#include "components/gcm_driver/gcm_app_handler.h"
[email protected]cd57f372014-06-09 17:13:0616#include "components/gcm_driver/gcm_client.h"
jianli7898ae712015-06-04 19:47:0617#include "components/gcm_driver/instance_id/instance_id.h"
[email protected]2f3617042014-03-21 22:44:3618#include "extensions/browser/browser_context_keyed_api_factory.h"
[email protected]96ac5962014-04-22 19:49:5819#include "extensions/browser/extension_registry_observer.h"
[email protected]240fc7e2014-03-20 06:52:2020
21class Profile;
[email protected]df84c532014-04-25 15:36:5422
[email protected]2f3617042014-03-21 22:44:3623namespace content {
24class BrowserContext;
25}
[email protected]df84c532014-04-25 15:36:5426
[email protected]240fc7e2014-03-20 06:52:2027namespace gcm {
[email protected]9d7e5c02014-05-21 03:09:0328class GCMDriver;
[email protected]240fc7e2014-03-20 06:52:2029class GCMProfileService;
30}
jianli7898ae712015-06-04 19:47:0631namespace instance_id {
32class InstanceIDDriver;
33}
[email protected]240fc7e2014-03-20 06:52:2034
35namespace extensions {
36
[email protected]96ac5962014-04-22 19:49:5837class ExtensionRegistry;
[email protected]240fc7e2014-03-20 06:52:2038class 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();
51
52 // gcm::GCMAppHandler implementation.
dchengae36a4a2014-10-21 12:36:3653 void ShutdownHandler() override;
54 void OnMessage(const std::string& app_id,
55 const gcm::GCMClient::IncomingMessage& message) override;
56 void OnMessagesDeleted(const std::string& app_id) override;
57 void OnSendError(
[email protected]240fc7e2014-03-20 06:52:2058 const std::string& app_id,
mostynba15bee12014-10-04 00:40:3259 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
dchengae36a4a2014-10-21 12:36:3660 void OnSendAcknowledged(const std::string& app_id,
61 const std::string& message_id) override;
[email protected]240fc7e2014-03-20 06:52:2062
[email protected]2ac46732014-04-03 23:14:3163 protected:
[email protected]1182aa1b2014-06-17 21:19:5164 // Could be overridden by testing purpose.
[email protected]2ac46732014-04-03 23:14:3165 virtual void OnUnregisterCompleted(const std::string& app_id,
66 gcm::GCMClient::Result result);
jianli7898ae712015-06-04 19:47:0667 virtual void OnDeleteIDCompleted(const std::string& app_id,
68 instance_id::InstanceID::Result result);
[email protected]1182aa1b2014-06-17 21:19:5169 virtual void AddAppHandler(const std::string& app_id);
70 virtual void RemoveAppHandler(const std::string& app_id);
[email protected]2ac46732014-04-03 23:14:3171
[email protected]1182aa1b2014-06-17 21:19:5172 gcm::GCMDriver* GetGCMDriver() const;
jianli7898ae712015-06-04 19:47:0673 instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
[email protected]1182aa1b2014-06-17 21:19:5174
jianlic5f6bd92015-05-28 02:23:4575 private:
[email protected]2f3617042014-03-21 22:44:3676 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
77
[email protected]96ac5962014-04-22 19:49:5878 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3679 void OnExtensionLoaded(content::BrowserContext* browser_context,
80 const Extension* extension) override;
81 void OnExtensionUnloaded(content::BrowserContext* browser_context,
82 const Extension* extension,
83 UnloadedExtensionInfo::Reason reason) override;
84 void OnExtensionUninstalled(content::BrowserContext* browser_context,
85 const Extension* extension,
86 extensions::UninstallReason reason) override;
[email protected]96ac5962014-04-22 19:49:5887
jianli7898ae712015-06-04 19:47:0688 void RemoveInstanceID(const std::string& app_id);
[email protected]1182aa1b2014-06-17 21:19:5189 void AddDummyAppHandler();
90 void RemoveDummyAppHandler();
[email protected]240fc7e2014-03-20 06:52:2091
[email protected]2f3617042014-03-21 22:44:3692 // BrowserContextKeyedAPI implementation.
93 static const char* service_name() { return "ExtensionGCMAppHandler"; }
94 static const bool kServiceIsNULLWhileTesting = true;
95
[email protected]240fc7e2014-03-20 06:52:2096 Profile* profile_;
[email protected]240fc7e2014-03-20 06:52:2097
[email protected]96ac5962014-04-22 19:49:5898 // Listen to extension load, unloaded notifications.
99 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
100 extension_registry_observer_;
101
[email protected]240fc7e2014-03-20 06:52:20102 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
[email protected]240fc7e2014-03-20 06:52:20103
104 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
105
106 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
107};
108
109} // namespace extensions
110
111#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_