OLD | NEW |
---|---|
(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 class PrefRegistrySimple; | |
21 | |
22 namespace copresence { | |
23 class CopresenceClient; | |
24 class WhispernetClient; | |
25 } | |
26 | |
27 namespace extensions { | |
28 | |
29 class CopresenceService : public BrowserContextKeyedAPI, | |
30 public copresence::CopresenceClientDelegate { | |
31 public: | |
32 explicit CopresenceService(content::BrowserContext* context); | |
33 virtual ~CopresenceService(); | |
34 | |
35 // These accessors will always return an object. If the object doesn't exist, | |
36 // they will create one first. | |
37 copresence::CopresenceClient* client(); | |
38 copresence::WhispernetClient* whispernet_client(); | |
xiyuan
2014/08/05 21:02:35
nit: move accessors to the last.
rkc
2014/08/05 22:25:22
Done.
| |
39 | |
40 virtual void Shutdown() OVERRIDE; | |
xiyuan
2014/08/05 21:02:35
nit: // BrowserContextKeyedAPI implementation.
rkc
2014/08/05 22:25:22
Done.
| |
41 | |
42 // A registry containing the app id's associated with every subscription. | |
43 SubscriptionToAppMap& SubscriptionToAppsRegistry() { | |
not at google - send to devlin
2014/08/05 21:05:38
should be subscription_to_apps_registry(), or real
rkc
2014/08/05 22:25:22
Done.
| |
44 return apps_by_subscription_id_; | |
45 } | |
46 | |
47 // Registers the preference for saving our device id. | |
48 static void RegisterPrefs(PrefRegistrySimple* registry); | |
49 | |
50 // BrowserContextKeyedAPI implementation. | |
51 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); | |
52 | |
53 private: | |
54 friend class BrowserContextKeyedAPIFactory<CopresenceService>; | |
55 | |
56 // CopresenceClientDelegate overrides: | |
57 virtual void HandleMessages( | |
58 const std::string& app_id, | |
59 const std::string& subscription_id, | |
60 const std::vector<copresence::Message>& message) OVERRIDE; | |
61 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE; | |
62 virtual const std::string GetPlatformVersionString() const OVERRIDE; | |
63 virtual const std::string GetDeviceId() const OVERRIDE; | |
64 virtual void SaveDeviceId(const std::string& device_id) OVERRIDE; | |
65 virtual copresence::WhispernetClient* GetWhispernetClient() OVERRIDE; | |
66 | |
67 // BrowserContextKeyedAPI implementation. | |
68 static const char* service_name() { return "CopresenceService"; } | |
69 | |
70 std::map<std::string, std::string> apps_by_subscription_id_; | |
71 | |
72 content::BrowserContext* const browser_context_; | |
73 scoped_ptr<copresence::CopresenceClient> client_; | |
74 scoped_ptr<copresence::WhispernetClient> whispernet_client_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(CopresenceService); | |
77 }; | |
78 | |
79 template <> | |
80 void BrowserContextKeyedAPIFactory< | |
81 CopresenceService>::DeclareFactoryDependencies(); | |
82 | |
83 class CopresenceBatchExecuteFunction : public ChromeUIThreadExtensionFunction { | |
84 public: | |
85 DECLARE_EXTENSION_FUNCTION("copresence.batchExecute", | |
86 COPRESENCE_BATCHEXECUTE); | |
87 | |
88 void SendResult(copresence::CopresenceStatus status); | |
not at google - send to devlin
2014/08/05 21:05:38
this can be private
rkc
2014/08/05 22:25:22
Done.
| |
89 | |
90 protected: | |
91 virtual ~CopresenceBatchExecuteFunction() {} | |
92 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; | |
93 }; | |
94 | |
95 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { | |
96 public: | |
97 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); | |
98 | |
99 void SendResult(copresence::CopresenceStatus status); | |
not at google - send to devlin
2014/08/05 21:05:38
this is never implemented
rkc
2014/08/05 22:25:22
Done.
| |
100 | |
101 protected: | |
102 virtual ~CopresenceSetApiKeyFunction() {} | |
103 virtual ExtensionFunction::ResponseAction Run() OVERRIDE; | |
104 }; | |
105 | |
106 } // namespace extensions | |
107 | |
108 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ | |
OLD | NEW |