// Copyright (c) 2019 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // GENERATED FROM THE API DEFINITION IN // chrome/common/extensions/api/gcm.json // DO NOT EDIT. #include "tools/json_schema_compiler/util.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/extensions/api/gcm.h" #include #include using base::UTF8ToUTF16; namespace extensions { namespace api { namespace gcm { // // Properties // const int MAX_MESSAGE_SIZE = 4096; // // Functions // namespace Register { Params::Params() {} Params::~Params() {} // static std::unique_ptr Params::Create(const base::ListValue& args) { if (args.GetSize() != 1) { return nullptr; } std::unique_ptr params(new Params()); const base::Value* sender_ids_value = NULL; if (args.Get(0, &sender_ids_value) && !sender_ids_value->is_none()) { { const base::ListValue* list = NULL; if (!sender_ids_value->GetAsList(&list)) { return std::unique_ptr(); } else { if (!json_schema_compiler::util::PopulateArrayFromList(*list, ¶ms->sender_ids)) { return std::unique_ptr(); } } } } else { return std::unique_ptr(); } return params; } std::unique_ptr Results::Create(const std::string& registration_id) { std::unique_ptr create_results(new base::ListValue()); create_results->Append(std::make_unique(registration_id)); return create_results; } } // namespace Register namespace Unregister { std::unique_ptr Results::Create() { std::unique_ptr create_results(new base::ListValue()); return create_results; } } // namespace Unregister namespace Send { Params::Message::Data::Data() {} Params::Message::Data::~Data() {} Params::Message::Data::Data(Data&& rhs) : additional_properties(std::move(rhs.additional_properties)){ } Params::Message::Data& Params::Message::Data::operator=(Data&& rhs) { additional_properties = std::move(rhs.additional_properties); return *this; } // static bool Params::Message::Data::Populate( const base::Value& value, Data* out) { if (!value.is_dict()) { return false; } const base::DictionaryValue* dict = static_cast(&value); for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { std::string tmp; { if (!(&it.value())->GetAsString(&tmp)) { return false; } } out->additional_properties[it.key()] = tmp; } return true; } Params::Message::Message() {} Params::Message::~Message() {} Params::Message::Message(Message&& rhs) : destination_id(std::move(rhs.destination_id)), message_id(std::move(rhs.message_id)), time_to_live(std::move(rhs.time_to_live)), data(std::move(rhs.data)){ } Params::Message& Params::Message::operator=(Message&& rhs) { destination_id = std::move(rhs.destination_id); message_id = std::move(rhs.message_id); time_to_live = std::move(rhs.time_to_live); data = std::move(rhs.data); return *this; } // static bool Params::Message::Populate( const base::Value& value, Message* out) { if (!value.is_dict()) { return false; } const base::DictionaryValue* dict = static_cast(&value); const base::Value* destination_id_value = NULL; if (!dict->GetWithoutPathExpansion("destinationId", &destination_id_value)) { return false; } { if (!destination_id_value->GetAsString(&out->destination_id)) { return false; } } const base::Value* message_id_value = NULL; if (!dict->GetWithoutPathExpansion("messageId", &message_id_value)) { return false; } { if (!message_id_value->GetAsString(&out->message_id)) { return false; } } const base::Value* time_to_live_value = NULL; if (dict->GetWithoutPathExpansion("timeToLive", &time_to_live_value)) { { int temp; if (!time_to_live_value->GetAsInteger(&temp)) { out->time_to_live.reset(); return false; } else out->time_to_live.reset(new int(temp)); } } const base::Value* data_value = NULL; if (!dict->GetWithoutPathExpansion("data", &data_value)) { return false; } { const base::DictionaryValue* dictionary = NULL; if (!data_value->GetAsDictionary(&dictionary)) { return false; } if (!Data::Populate(*dictionary, &out->data)) { return false; } } return true; } Params::Params() {} Params::~Params() {} // static std::unique_ptr Params::Create(const base::ListValue& args) { if (args.GetSize() != 1) { return nullptr; } std::unique_ptr params(new Params()); const base::Value* message_value = NULL; if (args.Get(0, &message_value) && !message_value->is_none()) { { const base::DictionaryValue* dictionary = NULL; if (!message_value->GetAsDictionary(&dictionary)) { return std::unique_ptr(); } if (!Message::Populate(*dictionary, ¶ms->message)) { return std::unique_ptr(); } } } else { return std::unique_ptr(); } return params; } std::unique_ptr Results::Create(const std::string& message_id) { std::unique_ptr create_results(new base::ListValue()); create_results->Append(std::make_unique(message_id)); return create_results; } } // namespace Send // // Events // namespace OnMessage { const char kEventName[] = "gcm.onMessage"; Message::Data::Data() {} Message::Data::~Data() {} Message::Data::Data(Data&& rhs) : additional_properties(std::move(rhs.additional_properties)){ } Message::Data& Message::Data::operator=(Data&& rhs) { additional_properties = std::move(rhs.additional_properties); return *this; } std::unique_ptr Message::Data::ToValue() const { std::unique_ptr value(new base::DictionaryValue()); for (const auto& it : additional_properties) { value->SetWithoutPathExpansion(it.first, std::make_unique(it.second)); } return value; } Message::Message() {} Message::~Message() {} Message::Message(Message&& rhs) : data(std::move(rhs.data)), from(std::move(rhs.from)), collapse_key(std::move(rhs.collapse_key)){ } Message& Message::operator=(Message&& rhs) { data = std::move(rhs.data); from = std::move(rhs.from); collapse_key = std::move(rhs.collapse_key); return *this; } std::unique_ptr Message::ToValue() const { std::unique_ptr value(new base::DictionaryValue()); value->SetWithoutPathExpansion("data", (this->data).ToValue()); if (this->from.get()) { value->SetWithoutPathExpansion("from", std::make_unique(*this->from)); } if (this->collapse_key.get()) { value->SetWithoutPathExpansion("collapseKey", std::make_unique(*this->collapse_key)); } return value; } std::unique_ptr Create(const Message& message) { std::unique_ptr create_results(new base::ListValue()); create_results->Append((message).ToValue()); return create_results; } } // namespace OnMessage namespace OnMessagesDeleted { const char kEventName[] = "gcm.onMessagesDeleted"; std::unique_ptr Create() { std::unique_ptr create_results(new base::ListValue()); return create_results; } } // namespace OnMessagesDeleted namespace OnSendError { const char kEventName[] = "gcm.onSendError"; Error::Details::Details() {} Error::Details::~Details() {} Error::Details::Details(Details&& rhs) : additional_properties(std::move(rhs.additional_properties)){ } Error::Details& Error::Details::operator=(Details&& rhs) { additional_properties = std::move(rhs.additional_properties); return *this; } std::unique_ptr Error::Details::ToValue() const { std::unique_ptr value(new base::DictionaryValue()); for (const auto& it : additional_properties) { value->SetWithoutPathExpansion(it.first, std::make_unique(it.second)); } return value; } Error::Error() {} Error::~Error() {} Error::Error(Error&& rhs) : error_message(std::move(rhs.error_message)), message_id(std::move(rhs.message_id)), details(std::move(rhs.details)){ } Error& Error::operator=(Error&& rhs) { error_message = std::move(rhs.error_message); message_id = std::move(rhs.message_id); details = std::move(rhs.details); return *this; } std::unique_ptr Error::ToValue() const { std::unique_ptr value(new base::DictionaryValue()); value->SetWithoutPathExpansion("errorMessage", std::make_unique(this->error_message)); if (this->message_id.get()) { value->SetWithoutPathExpansion("messageId", std::make_unique(*this->message_id)); } value->SetWithoutPathExpansion("details", (this->details).ToValue()); return value; } std::unique_ptr Create(const Error& error) { std::unique_ptr create_results(new base::ListValue()); create_results->Append((error).ToValue()); return create_results; } } // namespace OnSendError } // namespace gcm } // namespace api } // namespace extensions