blob: 5da91b71d05697e282bc1532e4c60a9fcdca5527 [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]240fc7e2014-03-20 06:52:2016#include "content/public/browser/notification_observer.h"
17#include "content/public/browser/notification_registrar.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#include "google_apis/gcm/gcm_client.h"
21
22class Profile;
[email protected]df84c532014-04-25 15:36:5423
[email protected]2f3617042014-03-21 22:44:3624namespace content {
25class BrowserContext;
26}
[email protected]df84c532014-04-25 15:36:5427
[email protected]240fc7e2014-03-20 06:52:2028namespace gcm {
[email protected]9d7e5c02014-05-21 03:09:0329class GCMDriver;
[email protected]240fc7e2014-03-20 06:52:2030class GCMProfileService;
31}
32
33namespace extensions {
34
[email protected]96ac5962014-04-22 19:49:5835class ExtensionRegistry;
[email protected]240fc7e2014-03-20 06:52:2036class GcmJsEventRouter;
37
38// Defines the interface to provide handling logic for a given app.
39class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
[email protected]2f3617042014-03-21 22:44:3640 public BrowserContextKeyedAPI,
[email protected]96ac5962014-04-22 19:49:5841 public content::NotificationObserver,
42 public ExtensionRegistryObserver {
[email protected]240fc7e2014-03-20 06:52:2043 public:
[email protected]2f3617042014-03-21 22:44:3644 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
[email protected]240fc7e2014-03-20 06:52:2045 virtual ~ExtensionGCMAppHandler();
46
[email protected]2f3617042014-03-21 22:44:3647 // BrowserContextKeyedAPI implementation.
48 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
49 GetFactoryInstance();
50
51 // gcm::GCMAppHandler implementation.
[email protected]240fc7e2014-03-20 06:52:2052 virtual void ShutdownHandler() OVERRIDE;
53 virtual void OnMessage(
54 const std::string& app_id,
55 const gcm::GCMClient::IncomingMessage& message) OVERRIDE;
56 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
57 virtual void OnSendError(
58 const std::string& app_id,
59 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
60
[email protected]2ac46732014-04-03 23:14:3161 protected:
62 virtual void OnUnregisterCompleted(const std::string& app_id,
63 gcm::GCMClient::Result result);
64
[email protected]240fc7e2014-03-20 06:52:2065 private:
[email protected]2f3617042014-03-21 22:44:3666 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
67
68 // content::NotificationObserver implementation.
[email protected]240fc7e2014-03-20 06:52:2069 virtual void Observe(int type,
70 const content::NotificationSource& source,
71 const content::NotificationDetails& details) OVERRIDE;
72
[email protected]96ac5962014-04-22 19:49:5873 // ExtensionRegistryObserver implementation.
74 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
75 const Extension* extension) OVERRIDE;
76 virtual void OnExtensionUnloaded(
77 content::BrowserContext* browser_context,
78 const Extension* extension,
79 UnloadedExtensionInfo::Reason reason) OVERRIDE;
80
[email protected]9d7e5c02014-05-21 03:09:0381 gcm::GCMDriver* GetGCMDriver() const;
[email protected]240fc7e2014-03-20 06:52:2082
[email protected]2f3617042014-03-21 22:44:3683 // BrowserContextKeyedAPI implementation.
84 static const char* service_name() { return "ExtensionGCMAppHandler"; }
85 static const bool kServiceIsNULLWhileTesting = true;
86
[email protected]240fc7e2014-03-20 06:52:2087 Profile* profile_;
88 content::NotificationRegistrar registrar_;
89
[email protected]96ac5962014-04-22 19:49:5890 // Listen to extension load, unloaded notifications.
91 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
92 extension_registry_observer_;
93
[email protected]240fc7e2014-03-20 06:52:2094#if !defined(OS_ANDROID)
95 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
96#endif
97
98 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
99
100 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
101};
102
103} // namespace extensions
104
105#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_