| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 20 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 20 #include "chrome/common/extensions/api/gcm.h" | 21 #include "chrome/common/extensions/api/gcm.h" |
| 21 #include "components/gcm_driver/common/gcm_messages.h" | 22 #include "components/gcm_driver/common/gcm_messages.h" |
| 22 #include "components/gcm_driver/gcm_driver.h" | 23 #include "components/gcm_driver/gcm_driver.h" |
| 23 #include "components/gcm_driver/gcm_profile_service.h" | 24 #include "components/gcm_driver/gcm_profile_service.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 extension()->id(), | 121 extension()->id(), |
| 121 params->sender_ids, | 122 params->sender_ids, |
| 122 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this)); | 123 base::Bind(&GcmRegisterFunction::CompleteFunctionWithResult, this)); |
| 123 | 124 |
| 124 return true; | 125 return true; |
| 125 } | 126 } |
| 126 | 127 |
| 127 void GcmRegisterFunction::CompleteFunctionWithResult( | 128 void GcmRegisterFunction::CompleteFunctionWithResult( |
| 128 const std::string& registration_id, | 129 const std::string& registration_id, |
| 129 gcm::GCMClient::Result result) { | 130 gcm::GCMClient::Result result) { |
| 130 SetResult(new base::StringValue(registration_id)); | 131 SetResult(base::MakeUnique<base::StringValue>(registration_id)); |
| 131 SetError(GcmResultToError(result)); | 132 SetError(GcmResultToError(result)); |
| 132 SendResponse(gcm::GCMClient::SUCCESS == result); | 133 SendResponse(gcm::GCMClient::SUCCESS == result); |
| 133 } | 134 } |
| 134 | 135 |
| 135 GcmUnregisterFunction::GcmUnregisterFunction() {} | 136 GcmUnregisterFunction::GcmUnregisterFunction() {} |
| 136 | 137 |
| 137 GcmUnregisterFunction::~GcmUnregisterFunction() {} | 138 GcmUnregisterFunction::~GcmUnregisterFunction() {} |
| 138 | 139 |
| 139 bool GcmUnregisterFunction::DoWork() { | 140 bool GcmUnregisterFunction::DoWork() { |
| 140 UMA_HISTOGRAM_BOOLEAN("GCM.APICallUnregister", true); | 141 UMA_HISTOGRAM_BOOLEAN("GCM.APICallUnregister", true); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 params->message.destination_id, | 175 params->message.destination_id, |
| 175 outgoing_message, | 176 outgoing_message, |
| 176 base::Bind(&GcmSendFunction::CompleteFunctionWithResult, this)); | 177 base::Bind(&GcmSendFunction::CompleteFunctionWithResult, this)); |
| 177 | 178 |
| 178 return true; | 179 return true; |
| 179 } | 180 } |
| 180 | 181 |
| 181 void GcmSendFunction::CompleteFunctionWithResult( | 182 void GcmSendFunction::CompleteFunctionWithResult( |
| 182 const std::string& message_id, | 183 const std::string& message_id, |
| 183 gcm::GCMClient::Result result) { | 184 gcm::GCMClient::Result result) { |
| 184 SetResult(new base::StringValue(message_id)); | 185 SetResult(base::MakeUnique<base::StringValue>(message_id)); |
| 185 SetError(GcmResultToError(result)); | 186 SetError(GcmResultToError(result)); |
| 186 SendResponse(gcm::GCMClient::SUCCESS == result); | 187 SendResponse(gcm::GCMClient::SUCCESS == result); |
| 187 } | 188 } |
| 188 | 189 |
| 189 bool GcmSendFunction::ValidateMessageData(const gcm::MessageData& data) const { | 190 bool GcmSendFunction::ValidateMessageData(const gcm::MessageData& data) const { |
| 190 size_t total_size = 0u; | 191 size_t total_size = 0u; |
| 191 for (std::map<std::string, std::string>::const_iterator iter = data.begin(); | 192 for (std::map<std::string, std::string>::const_iterator iter = data.begin(); |
| 192 iter != data.end(); ++iter) { | 193 iter != data.end(); ++iter) { |
| 193 total_size += iter->first.size() + iter->second.size(); | 194 total_size += iter->first.size() + iter->second.size(); |
| 194 | 195 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 error.details.additional_properties = send_error_details.additional_data; | 242 error.details.additional_properties = send_error_details.additional_data; |
| 242 | 243 |
| 243 std::unique_ptr<Event> event( | 244 std::unique_ptr<Event> event( |
| 244 new Event(events::GCM_ON_SEND_ERROR, api::gcm::OnSendError::kEventName, | 245 new Event(events::GCM_ON_SEND_ERROR, api::gcm::OnSendError::kEventName, |
| 245 api::gcm::OnSendError::Create(error), profile_)); | 246 api::gcm::OnSendError::Create(error), profile_)); |
| 246 EventRouter::Get(profile_) | 247 EventRouter::Get(profile_) |
| 247 ->DispatchEventToExtension(app_id, std::move(event)); | 248 ->DispatchEventToExtension(app_id, std::move(event)); |
| 248 } | 249 } |
| 249 | 250 |
| 250 } // namespace extensions | 251 } // namespace extensions |
| OLD | NEW |