blob: 8c7bc3363cdc411b056e8b2e747ff3247717b14e [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"
[email protected]2f3617042014-03-21 22:44:3617#include "extensions/browser/browser_context_keyed_api_factory.h"
[email protected]96ac5962014-04-22 19:49:5818#include "extensions/browser/extension_registry_observer.h"
[email protected]240fc7e2014-03-20 06:52:2019
20class Profile;
[email protected]df84c532014-04-25 15:36:5421
[email protected]2f3617042014-03-21 22:44:3622namespace content {
23class BrowserContext;
24}
[email protected]df84c532014-04-25 15:36:5425
[email protected]240fc7e2014-03-20 06:52:2026namespace gcm {
[email protected]9d7e5c02014-05-21 03:09:0327class GCMDriver;
[email protected]240fc7e2014-03-20 06:52:2028class GCMProfileService;
29}
30
31namespace extensions {
32
[email protected]96ac5962014-04-22 19:49:5833class ExtensionRegistry;
[email protected]240fc7e2014-03-20 06:52:2034class GcmJsEventRouter;
35
36// Defines the interface to provide handling logic for a given app.
37class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
[email protected]2f3617042014-03-21 22:44:3638 public BrowserContextKeyedAPI,
[email protected]96ac5962014-04-22 19:49:5839 public ExtensionRegistryObserver {
[email protected]240fc7e2014-03-20 06:52:2040 public:
[email protected]2f3617042014-03-21 22:44:3641 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
[email protected]240fc7e2014-03-20 06:52:2042 virtual ~ExtensionGCMAppHandler();
43
[email protected]2f3617042014-03-21 22:44:3644 // BrowserContextKeyedAPI implementation.
45 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
46 GetFactoryInstance();
47
48 // gcm::GCMAppHandler implementation.
[email protected]240fc7e2014-03-20 06:52:2049 virtual void ShutdownHandler() OVERRIDE;
50 virtual void OnMessage(
51 const std::string& app_id,
52 const gcm::GCMClient::IncomingMessage& message) OVERRIDE;
53 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
54 virtual void OnSendError(
55 const std::string& app_id,
56 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
57
[email protected]2ac46732014-04-03 23:14:3158 protected:
59 virtual void OnUnregisterCompleted(const std::string& app_id,
60 gcm::GCMClient::Result result);
61
[email protected]240fc7e2014-03-20 06:52:2062 private:
[email protected]2f3617042014-03-21 22:44:3663 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
64
[email protected]96ac5962014-04-22 19:49:5865 // ExtensionRegistryObserver implementation.
66 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
67 const Extension* extension) OVERRIDE;
68 virtual void OnExtensionUnloaded(
69 content::BrowserContext* browser_context,
70 const Extension* extension,
71 UnloadedExtensionInfo::Reason reason) OVERRIDE;
[email protected]488949b2014-05-30 14:59:4172 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
73 const Extension* extension) OVERRIDE;
[email protected]96ac5962014-04-22 19:49:5874
[email protected]9d7e5c02014-05-21 03:09:0375 gcm::GCMDriver* GetGCMDriver() const;
[email protected]240fc7e2014-03-20 06:52:2076
[email protected]2f3617042014-03-21 22:44:3677 // BrowserContextKeyedAPI implementation.
78 static const char* service_name() { return "ExtensionGCMAppHandler"; }
79 static const bool kServiceIsNULLWhileTesting = true;
80
[email protected]240fc7e2014-03-20 06:52:2081 Profile* profile_;
[email protected]240fc7e2014-03-20 06:52:2082
[email protected]96ac5962014-04-22 19:49:5883 // Listen to extension load, unloaded notifications.
84 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
85 extension_registry_observer_;
86
[email protected]240fc7e2014-03-20 06:52:2087#if !defined(OS_ANDROID)
88 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
89#endif
90
91 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
92
93 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
94};
95
96} // namespace extensions
97
98#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_