Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 5 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 const size_t kMaximumMessageSize = 4096; // in bytes. | 25 const size_t kMaximumMessageSize = 4096; // in bytes. |
| 26 const char kCollapseKey[] = "collapse_key"; | 26 const char kCollapseKey[] = "collapse_key"; |
| 27 const char kGoogDotRestrictedPrefix[] = "goog."; | 27 const char kGoogDotRestrictedPrefix[] = "goog."; |
| 28 const char kGoogleRestrictedPrefix[] = "google"; | 28 const char kGoogleRestrictedPrefix[] = "google"; |
| 29 | 29 |
| 30 // Error messages. | 30 // Error messages. |
| 31 const char kInvalidParameter[] = | 31 const char kInvalidParameter[] = |
| 32 "Function was called with invalid parameters."; | 32 "Function was called with invalid parameters."; |
| 33 const char kNotSignedIn[] = "Profile was not signed in."; | 33 const char kNotSignedIn[] = "Profile was not signed in."; |
| 34 const char kCertificateMissing[] = "Manifest key was missing."; | |
| 35 const char kAsyncOperationPending[] = | 34 const char kAsyncOperationPending[] = |
| 36 "Asynchronous operation is pending."; | 35 "Asynchronous operation is pending."; |
| 37 const char kNetworkError[] = "Network error occurred."; | 36 const char kNetworkError[] = "Network error occurred."; |
| 38 const char kServerError[] = "Server error occurred."; | 37 const char kServerError[] = "Server error occurred."; |
| 39 const char kTtlExceeded[] = "Time-to-live exceeded."; | 38 const char kTtlExceeded[] = "Time-to-live exceeded."; |
| 40 const char kUnknownError[] = "Unknown error occurred."; | 39 const char kUnknownError[] = "Unknown error occurred."; |
| 41 | 40 |
| 42 std::string SHA1HashHexString(const std::string& str) { | 41 std::string SHA1HashHexString(const std::string& str) { |
| 43 std::string hash = base::SHA1HashString(str); | 42 std::string hash = base::SHA1HashString(str); |
| 44 return base::HexEncode(hash.data(), hash.size()); | 43 return base::HexEncode(hash.data(), hash.size()); |
| 45 } | 44 } |
| 46 | 45 |
| 47 const char* GcmResultToError(gcm::GCMClient::Result result) { | 46 const char* GcmResultToError(gcm::GCMClient::Result result) { |
| 48 switch (result) { | 47 switch (result) { |
| 49 case gcm::GCMClient::SUCCESS: | 48 case gcm::GCMClient::SUCCESS: |
| 50 return ""; | 49 return ""; |
| 51 case gcm::GCMClient::INVALID_PARAMETER: | 50 case gcm::GCMClient::INVALID_PARAMETER: |
| 52 return kInvalidParameter; | 51 return kInvalidParameter; |
| 53 case gcm::GCMClient::NOT_SIGNED_IN: | 52 case gcm::GCMClient::NOT_SIGNED_IN: |
| 54 return kNotSignedIn; | 53 return kNotSignedIn; |
| 55 case gcm::GCMClient::CERTIFICATE_MISSING: | |
| 56 return kCertificateMissing; | |
| 57 case gcm::GCMClient::ASYNC_OPERATION_PENDING: | 54 case gcm::GCMClient::ASYNC_OPERATION_PENDING: |
| 58 return kAsyncOperationPending; | 55 return kAsyncOperationPending; |
| 59 case gcm::GCMClient::NETWORK_ERROR: | 56 case gcm::GCMClient::NETWORK_ERROR: |
| 60 return kNetworkError; | 57 return kNetworkError; |
| 61 case gcm::GCMClient::SERVER_ERROR: | 58 case gcm::GCMClient::SERVER_ERROR: |
| 62 return kServerError; | 59 return kServerError; |
| 63 case gcm::GCMClient::TTL_EXCEEDED: | 60 case gcm::GCMClient::TTL_EXCEEDED: |
| 64 return kTtlExceeded; | 61 return kTtlExceeded; |
| 65 case gcm::GCMClient::UNKNOWN_ERROR: | 62 case gcm::GCMClient::UNKNOWN_ERROR: |
| 66 return kUnknownError; | 63 return kUnknownError; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 111 |
| 115 GcmRegisterFunction::GcmRegisterFunction() {} | 112 GcmRegisterFunction::GcmRegisterFunction() {} |
| 116 | 113 |
| 117 GcmRegisterFunction::~GcmRegisterFunction() {} | 114 GcmRegisterFunction::~GcmRegisterFunction() {} |
| 118 | 115 |
| 119 bool GcmRegisterFunction::DoWork() { | 116 bool GcmRegisterFunction::DoWork() { |
| 120 scoped_ptr<api::gcm::Register::Params> params( | 117 scoped_ptr<api::gcm::Register::Params> params( |
| 121 api::gcm::Register::Params::Create(*args_)); | 118 api::gcm::Register::Params::Create(*args_)); |
| 122 EXTENSION_FUNCTION_VALIDATE(params.get()); | 119 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 123 | 120 |
| 124 if (GetExtension()->public_key().empty()) { | |
| 125 CompleteFunctionWithResult(std::string(), | |
| 126 gcm::GCMClient::CERTIFICATE_MISSING); | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 GCMProfileService()->Register( | 121 GCMProfileService()->Register( |
| 131 GetExtension()->id(), | 122 GetExtension()->id(), |
| 132 params->sender_ids, | 123 params->sender_ids, |
| 133 SHA1HashHexString(GetExtension()->public_key()), | 124 SHA1HashHexString(GetExtension()->id()), |
|
fgorski
2014/02/27 23:39:30
please investigate if we need to pass a certificat
jianli
2014/02/28 19:53:40
Per discussion, the cert is not needed any more.
| |
| 134 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this)); | 125 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this)); |
| 135 | 126 |
| 136 return true; | 127 return true; |
| 137 } | 128 } |
| 138 | 129 |
| 139 void GcmRegisterFunction::CompleteFunctionWithResult( | 130 void GcmRegisterFunction::CompleteFunctionWithResult( |
| 140 const std::string& registration_id, | 131 const std::string& registration_id, |
| 141 gcm::GCMClient::Result result) { | 132 gcm::GCMClient::Result result) { |
| 142 SetResult(base::Value::CreateStringValue(registration_id)); | 133 SetResult(base::Value::CreateStringValue(registration_id)); |
| 143 SetError(GcmResultToError(result)); | 134 SetError(GcmResultToError(result)); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 222 |
| 232 scoped_ptr<Event> event(new Event( | 223 scoped_ptr<Event> event(new Event( |
| 233 api::gcm::OnSendError::kEventName, | 224 api::gcm::OnSendError::kEventName, |
| 234 api::gcm::OnSendError::Create(error).Pass(), | 225 api::gcm::OnSendError::Create(error).Pass(), |
| 235 profile_)); | 226 profile_)); |
| 236 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 227 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
| 237 app_id, event.Pass()); | 228 app_id, event.Pass()); |
| 238 } | 229 } |
| 239 | 230 |
| 240 } // namespace extensions | 231 } // namespace extensions |
| OLD | NEW |