Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / gcm / gcm_api.h
blobf0b3460167c52a871256e21f460237dbd001c286
1 // Copyright 2013 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_API_GCM_GCM_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_
8 #include "chrome/common/extensions/api/gcm.h"
9 #include "components/gcm_driver/gcm_client.h"
10 #include "extensions/browser/extension_function.h"
12 namespace gcm {
13 class GCMDriver;
14 class GCMProfileService;
15 } // namespace gcm
17 class Profile;
19 namespace extensions {
21 class GcmApiFunction : public AsyncExtensionFunction {
22 public:
23 GcmApiFunction() {}
25 protected:
26 ~GcmApiFunction() override {}
28 // ExtensionFunction:
29 bool RunAsync() final;
31 // Actual implementation of specific functions.
32 virtual bool DoWork() = 0;
34 // Checks that the GCM API is enabled.
35 bool IsGcmApiEnabled() const;
37 gcm::GCMDriver* GetGCMDriver() const;
40 class GcmRegisterFunction : public GcmApiFunction {
41 public:
42 DECLARE_EXTENSION_FUNCTION("gcm.register", GCM_REGISTER);
44 GcmRegisterFunction();
46 protected:
47 ~GcmRegisterFunction() override;
49 // Register function implementation.
50 bool DoWork() final;
52 private:
53 void CompleteFunctionWithResult(const std::string& registration_id,
54 gcm::GCMClient::Result result);
57 class GcmUnregisterFunction : public GcmApiFunction {
58 public:
59 DECLARE_EXTENSION_FUNCTION("gcm.unregister", GCM_UNREGISTER);
61 GcmUnregisterFunction();
63 protected:
64 ~GcmUnregisterFunction() override;
66 // Register function implementation.
67 bool DoWork() final;
69 private:
70 void CompleteFunctionWithResult(gcm::GCMClient::Result result);
73 class GcmSendFunction : public GcmApiFunction {
74 public:
75 DECLARE_EXTENSION_FUNCTION("gcm.send", GCM_SEND);
77 GcmSendFunction();
79 protected:
80 ~GcmSendFunction() override;
82 // Send function implementation.
83 bool DoWork() final;
85 private:
86 void CompleteFunctionWithResult(const std::string& message_id,
87 gcm::GCMClient::Result result);
89 // Validates that message data do not carry invalid keys and fit into
90 // allowable size limits.
91 bool ValidateMessageData(const gcm::MessageData& data) const;
94 class GcmJsEventRouter {
95 public:
96 explicit GcmJsEventRouter(Profile* profile);
98 virtual ~GcmJsEventRouter();
100 void OnMessage(const std::string& app_id,
101 const gcm::IncomingMessage& message);
102 void OnMessagesDeleted(const std::string& app_id);
103 void OnSendError(const std::string& app_id,
104 const gcm::GCMClient::SendErrorDetails& send_error_details);
106 private:
107 // The application we route the event to is running in context of the
108 // |profile_| and the latter outlives the event router.
109 Profile* profile_;
112 } // namespace extensions
114 #endif // CHROME_BROWSER_EXTENSIONS_API_GCM_GCM_API_H_