blob: af22e2100c7f3256237103cee28ad2e2dceafcfd [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
8#include "base/memory/scoped_ptr.h"
9#include "base/memory/weak_ptr.h"
10#include "chrome/browser/services/gcm/gcm_app_handler.h"
11#include "content/public/browser/notification_observer.h"
12#include "content/public/browser/notification_registrar.h"
[email protected]2f3617042014-03-21 22:44:3613#include "extensions/browser/browser_context_keyed_api_factory.h"
[email protected]240fc7e2014-03-20 06:52:2014#include "google_apis/gcm/gcm_client.h"
15
16class Profile;
[email protected]2f3617042014-03-21 22:44:3617namespace content {
18class BrowserContext;
19}
[email protected]240fc7e2014-03-20 06:52:2020namespace gcm {
21class GCMProfileService;
22}
23
24namespace extensions {
25
26class GcmJsEventRouter;
27
28// Defines the interface to provide handling logic for a given app.
29class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
[email protected]2f3617042014-03-21 22:44:3630 public BrowserContextKeyedAPI,
[email protected]240fc7e2014-03-20 06:52:2031 public content::NotificationObserver {
32 public:
[email protected]2f3617042014-03-21 22:44:3633 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
[email protected]240fc7e2014-03-20 06:52:2034 virtual ~ExtensionGCMAppHandler();
35
[email protected]2f3617042014-03-21 22:44:3636 // BrowserContextKeyedAPI implementation.
37 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
38 GetFactoryInstance();
39
40 // gcm::GCMAppHandler implementation.
[email protected]240fc7e2014-03-20 06:52:2041 virtual void ShutdownHandler() OVERRIDE;
42 virtual void OnMessage(
43 const std::string& app_id,
44 const gcm::GCMClient::IncomingMessage& message) OVERRIDE;
45 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
46 virtual void OnSendError(
47 const std::string& app_id,
48 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
49
50 private:
[email protected]2f3617042014-03-21 22:44:3651 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
52
53 // content::NotificationObserver implementation.
[email protected]240fc7e2014-03-20 06:52:2054 virtual void Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) OVERRIDE;
57
58 gcm::GCMProfileService* GetGCMProfileService() const;
[email protected]240fc7e2014-03-20 06:52:2059 void OnUnregisterCompleted(const std::string& app_id,
60 gcm::GCMClient::Result result);
61
[email protected]2f3617042014-03-21 22:44:3662 // BrowserContextKeyedAPI implementation.
63 static const char* service_name() { return "ExtensionGCMAppHandler"; }
64 static const bool kServiceIsNULLWhileTesting = true;
65
[email protected]240fc7e2014-03-20 06:52:2066 Profile* profile_;
67 content::NotificationRegistrar registrar_;
68
69#if !defined(OS_ANDROID)
70 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
71#endif
72
73 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
74
75 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
76};
77
78} // namespace extensions
79
80#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_