Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / extensions / extension_gcm_app_handler.h
blob81d6efcd6addf7954b0135e6cb0ebb781492c558
1 // 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_observer.h"
15 #include "components/gcm_driver/common/gcm_messages.h"
16 #include "components/gcm_driver/gcm_app_handler.h"
17 #include "components/gcm_driver/gcm_client.h"
18 #include "components/gcm_driver/instance_id/instance_id.h"
19 #include "extensions/browser/browser_context_keyed_api_factory.h"
20 #include "extensions/browser/extension_registry_observer.h"
22 class Profile;
24 namespace content {
25 class BrowserContext;
28 namespace gcm {
29 class GCMDriver;
30 class GCMProfileService;
32 namespace instance_id {
33 class InstanceIDDriver;
36 namespace extensions {
38 class ExtensionRegistry;
39 class GcmJsEventRouter;
41 // Defines the interface to provide handling logic for a given app.
42 class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
43 public BrowserContextKeyedAPI,
44 public ExtensionRegistryObserver {
45 public:
46 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
47 ~ExtensionGCMAppHandler() override;
49 // BrowserContextKeyedAPI implementation.
50 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
51 GetFactoryInstance();
53 // gcm::GCMAppHandler implementation.
54 void ShutdownHandler() override;
55 void OnMessage(const std::string& app_id,
56 const gcm::IncomingMessage& message) override;
57 void OnMessagesDeleted(const std::string& app_id) override;
58 void OnSendError(
59 const std::string& app_id,
60 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
61 void OnSendAcknowledged(const std::string& app_id,
62 const std::string& message_id) override;
64 protected:
65 // Could be overridden by testing purpose.
66 virtual void OnUnregisterCompleted(const std::string& app_id,
67 gcm::GCMClient::Result result);
68 virtual void OnDeleteIDCompleted(const std::string& app_id,
69 instance_id::InstanceID::Result result);
70 virtual void AddAppHandler(const std::string& app_id);
71 virtual void RemoveAppHandler(const std::string& app_id);
73 gcm::GCMDriver* GetGCMDriver() const;
74 instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
76 private:
77 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
79 // ExtensionRegistryObserver implementation.
80 void OnExtensionLoaded(content::BrowserContext* browser_context,
81 const Extension* extension) override;
82 void OnExtensionUnloaded(content::BrowserContext* browser_context,
83 const Extension* extension,
84 UnloadedExtensionInfo::Reason reason) override;
85 void OnExtensionUninstalled(content::BrowserContext* browser_context,
86 const Extension* extension,
87 extensions::UninstallReason reason) override;
89 void RemoveInstanceID(const std::string& app_id);
90 void AddDummyAppHandler();
91 void RemoveDummyAppHandler();
93 // BrowserContextKeyedAPI implementation.
94 static const char* service_name() { return "ExtensionGCMAppHandler"; }
95 static const bool kServiceIsNULLWhileTesting = true;
97 Profile* profile_;
99 // Listen to extension load, unloaded notifications.
100 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
101 extension_registry_observer_;
103 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
105 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
107 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
110 } // namespace extensions
112 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_