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

Unified Diff: chrome/browser/extensions/api/copresence/copresence_api.cc

Issue 671573003: Adding support for authenticated copresence calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Registering separately for authenticated calls Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/copresence/copresence_api.cc
diff --git a/chrome/browser/extensions/api/copresence/copresence_api.cc b/chrome/browser/extensions/api/copresence/copresence_api.cc
index 61749b8ff9938fdfaca0b5e7e19c75e523be2482..659b84bb15e6d4cd136141ee8bf807ddc3b8ea62 100644
--- a/chrome/browser/extensions/api/copresence/copresence_api.cc
+++ b/chrome/browser/extensions/api/copresence/copresence_api.cc
@@ -30,13 +30,20 @@ const char kShuttingDownMessage[] = "Shutting down.";
} // namespace
-// CopresenceService implementation:
+
+// CopresenceService implementation
rkc 2014/10/28 04:12:45 .
Charlie 2014/10/28 22:51:51 Done.
CopresenceService::CopresenceService(content::BrowserContext* context)
: is_shutting_down_(false), browser_context_(context) {}
CopresenceService::~CopresenceService() {}
+void CopresenceService::Shutdown() {
+ is_shutting_down_ = true;
+ manager_.reset();
+ whispernet_client_.reset();
+}
+
copresence::CopresenceManager* CopresenceService::manager() {
if (!manager_ && !is_shutting_down_)
manager_ = copresence::CopresenceManager::Create(this);
@@ -49,10 +56,14 @@ copresence::WhispernetClient* CopresenceService::whispernet_client() {
return whispernet_client_.get();
}
-void CopresenceService::Shutdown() {
- is_shutting_down_ = true;
- manager_.reset();
- whispernet_client_.reset();
+void CopresenceService::set_api_key(const std::string& app_id,
+ const std::string& api_key) {
+ DCHECK(!app_id.empty());
+ api_keys_by_app_[app_id] = api_key;
+}
+
+void CopresenceService::set_auth_token(const std::string& token) {
+ auth_token_ = token;
}
void CopresenceService::set_manager_for_testing(
@@ -112,8 +123,15 @@ const std::string CopresenceService::GetPlatformVersionString() const {
return chrome::VersionInfo().CreateVersionString();
}
-const std::string CopresenceService::GetAPIKey() const {
- return api_key_;
+const std::string CopresenceService::GetAPIKey(const std::string& app_id)
+ const {
+ // This won't be const if we use map[]
+ const auto& key = api_keys_by_app_.find(app_id);
+ return key == api_keys_by_app_.end() ? std::string() : key->second;
+}
+
+const std::string CopresenceService::GetAuthToken() const {
+ return auth_token_;
}
copresence::WhispernetClient* CopresenceService::GetWhispernetClient() {
@@ -126,7 +144,7 @@ BrowserContextKeyedAPIFactory<CopresenceService>::DeclareFactoryDependencies() {
DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
}
-// CopresenceExecuteFunction implementation:
+// CopresenceExecuteFunction implementation
ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() {
scoped_ptr<api::copresence::Execute::Params> params(
api::copresence::Execute::Params::Create(*args_));
@@ -164,7 +182,7 @@ void CopresenceExecuteFunction::SendResult(
Respond(ArgumentList(api::copresence::Execute::Results::Create(api_status)));
}
-// CopresenceSetApiKeyFunction implementation:
+// CopresenceSetApiKeyFunction implementation
rkc 2014/10/28 04:12:45 .
Charlie 2014/10/28 22:51:51 Done.
ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() {
scoped_ptr<api::copresence::SetApiKey::Params> params(
api::copresence::SetApiKey::Params::Create(*args_));
@@ -172,7 +190,19 @@ ExtensionFunction::ResponseAction CopresenceSetApiKeyFunction::Run() {
// The api key may be set to empty, to clear it.
CopresenceService::GetFactoryInstance()->Get(browser_context())
- ->set_api_key(params->api_key);
+ ->set_api_key(extension_id(), params->api_key);
+ return RespondNow(NoArguments());
+}
+
+// CopresenceSetAuthTokenFunction implementation
+ExtensionFunction::ResponseAction CopresenceSetAuthTokenFunction::Run() {
+ scoped_ptr<api::copresence::SetAuthToken::Params> params(
+ api::copresence::SetAuthToken::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ // The token may be set to empty, to clear it.
+ CopresenceService::GetFactoryInstance()->Get(browser_context())
+ ->set_auth_token(params->token);
rkc 2014/10/28 04:12:45 Add a TODO here with a link to a bug tracking that
Charlie 2014/10/28 22:51:51 Done.
return RespondNow(NoArguments());
}

Powered by Google App Engine
This is Rietveld 408576698