Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/extensions/api/copresence/copresence_api.h

Issue 444513005: Add the Copresence API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/extensions/api/copresence/copresence_translations.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
16 #include "chrome/common/extensions/api/copresence.h"
17 #include "components/copresence/public/copresence_client_delegate.h"
18 #include "extensions/browser/browser_context_keyed_api_factory.h"
19
20 namespace copresence {
21 class CopresenceClient;
22 class WhispernetClient;
23 }
24
25 namespace extensions {
26
27 class CopresenceService : public BrowserContextKeyedAPI,
28 public copresence::CopresenceClientDelegate {
29 public:
30 explicit CopresenceService(content::BrowserContext* context);
31 virtual ~CopresenceService();
32
33 // BrowserContextKeyedAPI implementation.
34 virtual void Shutdown() OVERRIDE;
35
36 // These accessors will always return an object. If the object doesn't exist,
37 // they will create one first.
38 copresence::CopresenceClient* client();
39 copresence::WhispernetClient* whispernet_client();
40
41 // A registry containing the app id's associated with every subscription.
42 SubscriptionToAppMap& apps_by_subscription_id() {
43 return apps_by_subscription_id_;
44 }
45
46 // BrowserContextKeyedAPI implementation.
47 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance();
48
49 private:
50 friend class BrowserContextKeyedAPIFactory<CopresenceService>;
51
52 // CopresenceClientDelegate overrides:
53 virtual void HandleMessages(
54 const std::string& app_id,
55 const std::string& subscription_id,
56 const std::vector<copresence::Message>& message) OVERRIDE;
57 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE;
58 virtual const std::string GetPlatformVersionString() const OVERRIDE;
59 virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE;
60
61 // BrowserContextKeyedAPI implementation.
62 static const char* service_name() { return "CopresenceService"; }
63
64 bool is_shutting_down_;
65 std::map<std::string, std::string> apps_by_subscription_id_;
66
67 content::BrowserContext* const browser_context_;
68 scoped_ptr<copresence::CopresenceClient> client_;
69 scoped_ptr<copresence::WhispernetClient> whispernet_client_;
70
71 DISALLOW_COPY_AND_ASSIGN(CopresenceService);
72 };
73
74 template <>
75 void BrowserContextKeyedAPIFactory<
76 CopresenceService>::DeclareFactoryDependencies();
77
78 class CopresenceExecuteFunction : public ChromeUIThreadExtensionFunction {
79 public:
80 DECLARE_EXTENSION_FUNCTION("copresence.execute", COPRESENCE_EXECUTE);
81
82 protected:
83 virtual ~CopresenceExecuteFunction() {}
84 virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
85
86 private:
87 void SendResult(copresence::CopresenceStatus status);
88 };
89
90 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction {
91 public:
92 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY);
93
94 protected:
95 virtual ~CopresenceSetApiKeyFunction() {}
96 virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
97 };
98
99 } // namespace extensions
100
101 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698