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

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

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing memory error Created 6 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/copresence/copresence_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 27 matching lines...) Expand all
38 // These accessors will always return an object (except during shutdown). 38 // These accessors will always return an object (except during shutdown).
39 // If the object doesn't exist, they will create one first. 39 // If the object doesn't exist, they will create one first.
40 copresence::CopresenceManager* manager(); 40 copresence::CopresenceManager* manager();
41 copresence::WhispernetClient* whispernet_client(); 41 copresence::WhispernetClient* whispernet_client();
42 42
43 // A registry containing the app id's associated with every subscription. 43 // A registry containing the app id's associated with every subscription.
44 SubscriptionToAppMap& apps_by_subscription_id() { 44 SubscriptionToAppMap& apps_by_subscription_id() {
45 return apps_by_subscription_id_; 45 return apps_by_subscription_id_;
46 } 46 }
47 47
48 void set_api_key(const std::string& api_key) { api_key_ = api_key; } 48 void set_api_key(const std::string& app_id,
49 const std::string& api_key);
50 void set_auth_token(const std::string& token);
49 51
50 // Manager override for testing. 52 // Manager override for testing.
51 void set_manager_for_testing( 53 void set_manager_for_testing(
52 scoped_ptr<copresence::CopresenceManager> manager); 54 scoped_ptr<copresence::CopresenceManager> manager);
53 55
54 // BrowserContextKeyedAPI implementation. 56 // BrowserContextKeyedAPI implementation.
55 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance(); 57 static BrowserContextKeyedAPIFactory<CopresenceService>* GetFactoryInstance();
56 58
57 private: 59 private:
58 friend class BrowserContextKeyedAPIFactory<CopresenceService>; 60 friend class BrowserContextKeyedAPIFactory<CopresenceService>;
59 61
60 // CopresenceDelegate implementation 62 // CopresenceDelegate implementation
61 void HandleMessages(const std::string& app_id, 63 void HandleMessages(const std::string& app_id,
62 const std::string& subscription_id, 64 const std::string& subscription_id,
63 const std::vector<copresence::Message>& message) override; 65 const std::vector<copresence::Message>& message) override;
64 net::URLRequestContextGetter* GetRequestContext() const override; 66 net::URLRequestContextGetter* GetRequestContext() const override;
65 const std::string GetPlatformVersionString() const override; 67 const std::string GetPlatformVersionString() const override;
66 const std::string GetAPIKey() const override; 68 const std::string GetAPIKey(const std::string& app_id) const override;
69 const std::string GetAuthToken() const override;
67 copresence::WhispernetClient* GetWhispernetClient() override; 70 copresence::WhispernetClient* GetWhispernetClient() override;
68 71
69 // BrowserContextKeyedAPI implementation. 72 // BrowserContextKeyedAPI implementation.
70 static const char* service_name() { return "CopresenceService"; } 73 static const char* service_name() { return "CopresenceService"; }
71 74
72 bool is_shutting_down_; 75 bool is_shutting_down_;
73 std::map<std::string, std::string> apps_by_subscription_id_; 76 std::map<std::string, std::string> apps_by_subscription_id_;
74 77
75 content::BrowserContext* const browser_context_; 78 content::BrowserContext* const browser_context_;
76 std::string api_key_; 79 std::map<std::string, std::string> api_keys_by_app_;
80
81 // TODO(ckehoe): This is a temporary hack.
82 // Auth tokens from different apps needs to be separated properly.
83 std::string auth_token_;
77 84
78 scoped_ptr<copresence::CopresenceManager> manager_; 85 scoped_ptr<copresence::CopresenceManager> manager_;
79 scoped_ptr<ChromeWhispernetClient> whispernet_client_; 86 scoped_ptr<ChromeWhispernetClient> whispernet_client_;
80 87
81 DISALLOW_COPY_AND_ASSIGN(CopresenceService); 88 DISALLOW_COPY_AND_ASSIGN(CopresenceService);
82 }; 89 };
83 90
84 template <> 91 template <>
85 void BrowserContextKeyedAPIFactory< 92 void BrowserContextKeyedAPIFactory<
86 CopresenceService>::DeclareFactoryDependencies(); 93 CopresenceService>::DeclareFactoryDependencies();
(...skipping 12 matching lines...) Expand all
99 106
100 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction { 107 class CopresenceSetApiKeyFunction : public ChromeUIThreadExtensionFunction {
101 public: 108 public:
102 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY); 109 DECLARE_EXTENSION_FUNCTION("copresence.setApiKey", COPRESENCE_SETAPIKEY);
103 110
104 protected: 111 protected:
105 ~CopresenceSetApiKeyFunction() override {} 112 ~CopresenceSetApiKeyFunction() override {}
106 ExtensionFunction::ResponseAction Run() override; 113 ExtensionFunction::ResponseAction Run() override;
107 }; 114 };
108 115
116 class CopresenceSetAuthTokenFunction : public ChromeUIThreadExtensionFunction {
117 public:
118 DECLARE_EXTENSION_FUNCTION("copresence.setAuthToken",
119 COPRESENCE_SETAUTHTOKEN);
120
121 protected:
122 virtual ~CopresenceSetAuthTokenFunction() {}
123 virtual ExtensionFunction::ResponseAction Run() override;
124 };
125
109 } // namespace extensions 126 } // namespace extensions
110 127
111 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_ 128 #endif // CHROME_BROWSER_EXTENSIONS_API_COPRESENCE_COPRESENCE_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/copresence/copresence_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698