Prevent chrome://net-internals/#export from flickering
[chromium-blink-merge.git] / chrome / browser / extensions / extension_gcm_app_handler.h
blob3e2c00f00f67e1443df1d18e44c617c19a22a193
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/gcm_app_handler.h"
16 #include "components/gcm_driver/gcm_client.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/browser/extension_registry_observer.h"
20 class Profile;
22 namespace content {
23 class BrowserContext;
26 namespace gcm {
27 class GCMDriver;
28 class GCMProfileService;
31 namespace extensions {
33 class ExtensionRegistry;
34 class GcmJsEventRouter;
36 // Defines the interface to provide handling logic for a given app.
37 class ExtensionGCMAppHandler : public gcm::GCMAppHandler,
38 public BrowserContextKeyedAPI,
39 public ExtensionRegistryObserver {
40 public:
41 explicit ExtensionGCMAppHandler(content::BrowserContext* context);
42 ~ExtensionGCMAppHandler() override;
44 // BrowserContextKeyedAPI implementation.
45 static BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>*
46 GetFactoryInstance();
48 // gcm::GCMAppHandler implementation.
49 void ShutdownHandler() override;
50 void OnMessage(const std::string& app_id,
51 const gcm::GCMClient::IncomingMessage& message) override;
52 void OnMessagesDeleted(const std::string& app_id) override;
53 void OnSendError(
54 const std::string& app_id,
55 const gcm::GCMClient::SendErrorDetails& send_error_details) override;
56 void OnSendAcknowledged(const std::string& app_id,
57 const std::string& message_id) override;
59 protected:
60 // Could be overridden by testing purpose.
61 virtual void OnUnregisterCompleted(const std::string& app_id,
62 gcm::GCMClient::Result result);
63 virtual void AddAppHandler(const std::string& app_id);
64 virtual void RemoveAppHandler(const std::string& app_id);
66 gcm::GCMDriver* GetGCMDriver() const;
68 private:
69 friend class BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>;
71 // ExtensionRegistryObserver implementation.
72 void OnExtensionLoaded(content::BrowserContext* browser_context,
73 const Extension* extension) override;
74 void OnExtensionUnloaded(content::BrowserContext* browser_context,
75 const Extension* extension,
76 UnloadedExtensionInfo::Reason reason) override;
77 void OnExtensionUninstalled(content::BrowserContext* browser_context,
78 const Extension* extension,
79 extensions::UninstallReason reason) override;
81 void AddDummyAppHandler();
82 void RemoveDummyAppHandler();
84 // BrowserContextKeyedAPI implementation.
85 static const char* service_name() { return "ExtensionGCMAppHandler"; }
86 static const bool kServiceIsNULLWhileTesting = true;
88 Profile* profile_;
90 // Listen to extension load, unloaded notifications.
91 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
92 extension_registry_observer_;
94 scoped_ptr<extensions::GcmJsEventRouter> js_event_router_;
96 base::WeakPtrFactory<ExtensionGCMAppHandler> weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandler);
101 } // namespace extensions
103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_GCM_APP_HANDLER_H_