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 |
| 11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 17 #include "chrome/common/extensions/api/gcm.h" | 17 #include "chrome/common/extensions/api/gcm.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const size_t kMaximumMessageSize = 4096; // in bytes. | 24 const size_t kMaximumMessageSize = 4096; // in bytes. |
| 25 const char kCollapseKey[] = "collapse_key"; | |
| 26 const size_t kCollapseKeyLength = arraysize(kCollapseKey) - 1; | |
|
not at google - send to devlin
2014/02/12 01:42:23
I don't really understand why you can't inline the
fgorski
2014/02/12 21:52:22
Done.
| |
| 25 const char kGoogDotRestrictedPrefix[] = "goog."; | 27 const char kGoogDotRestrictedPrefix[] = "goog."; |
| 26 const size_t kGoogDotPrefixLength = arraysize(kGoogDotRestrictedPrefix) - 1; | 28 const size_t kGoogDotPrefixLength = arraysize(kGoogDotRestrictedPrefix) - 1; |
| 27 const char kGoogleRestrictedPrefix[] = "google"; | 29 const char kGoogleRestrictedPrefix[] = "google"; |
| 28 const size_t kGooglePrefixLength = arraysize(kGoogleRestrictedPrefix) - 1; | 30 const size_t kGooglePrefixLength = arraysize(kGoogleRestrictedPrefix) - 1; |
| 29 | 31 |
| 30 // Error messages. | 32 // Error messages. |
| 31 const char kInvalidParameter[] = | 33 const char kInvalidParameter[] = |
| 32 "Function was called with invalid parameters."; | 34 "Function was called with invalid parameters."; |
| 33 const char kNotSignedIn[] = "Profile was not signed in."; | 35 const char kNotSignedIn[] = "Profile was not signed in."; |
| 34 const char kAsyncOperationPending[] = | 36 const char kAsyncOperationPending[] = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 64 default: | 66 default: |
| 65 NOTREACHED() << "Unexpected value of result cannot be converted: " | 67 NOTREACHED() << "Unexpected value of result cannot be converted: " |
| 66 << result; | 68 << result; |
| 67 } | 69 } |
| 68 | 70 |
| 69 // Never reached, but prevents missing return statement warning. | 71 // Never reached, but prevents missing return statement warning. |
| 70 return ""; | 72 return ""; |
| 71 } | 73 } |
| 72 | 74 |
| 73 bool IsMessageKeyValid(const std::string& key) { | 75 bool IsMessageKeyValid(const std::string& key) { |
| 76 std::string lower; | |
| 77 std::transform(key.begin(), key.end(), lower.begin(), ::tolower); | |
|
jianli
2014/02/12 01:30:32
nit: use base::StringToLowerASCII. Or even better,
fgorski
2014/02/12 21:52:22
Done.
| |
| 74 return !key.empty() && | 78 return !key.empty() && |
| 75 key.compare(0, kGooglePrefixLength, kGoogleRestrictedPrefix) != 0 && | 79 key.compare(0, kCollapseKeyLength, kCollapseKey) != 0 && |
| 76 key.compare(0, kGoogDotPrefixLength, kGoogDotRestrictedPrefix) != 0; | 80 lower.compare(0, kGooglePrefixLength, kGoogleRestrictedPrefix) != 0 && |
| 81 lower.compare(0, kGoogDotPrefixLength, kGoogDotRestrictedPrefix) != 0; | |
| 77 } | 82 } |
| 78 | 83 |
| 79 } // namespace | 84 } // namespace |
| 80 | 85 |
| 81 namespace extensions { | 86 namespace extensions { |
| 82 | 87 |
| 83 bool GcmApiFunction::RunImpl() { | 88 bool GcmApiFunction::RunImpl() { |
| 84 if (!IsGcmApiEnabled()) | 89 if (!IsGcmApiEnabled()) |
| 85 return false; | 90 return false; |
| 86 | 91 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 216 |
| 212 scoped_ptr<Event> event(new Event( | 217 scoped_ptr<Event> event(new Event( |
| 213 api::gcm::OnSendError::kEventName, | 218 api::gcm::OnSendError::kEventName, |
| 214 api::gcm::OnSendError::Create(error).Pass(), | 219 api::gcm::OnSendError::Create(error).Pass(), |
| 215 profile_)); | 220 profile_)); |
| 216 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 221 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
| 217 app_id, event.Pass()); | 222 app_id, event.Pass()); |
| 218 } | 223 } |
| 219 | 224 |
| 220 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |