Chromium Code Reviews| Index: chrome/browser/local_discovery/gcd_registration_ticket_creator.cc |
| diff --git a/chrome/browser/local_discovery/gcd_registration_ticket_creator.cc b/chrome/browser/local_discovery/gcd_registration_ticket_creator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..198958870b443c75ec3dfe81e065cdb0769cf5a2 |
| --- /dev/null |
| +++ b/chrome/browser/local_discovery/gcd_registration_ticket_creator.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "chrome/browser/local_discovery/gcd_registration_ticket_creator.h" |
| + |
| +#include "chrome/browser/local_discovery/gcd_constants.h" |
| +#include "chrome/common/cloud_print/cloud_print_constants.h" |
| +#include "components/cloud_devices/common/cloud_devices_urls.h" |
| + |
| +namespace local_discovery { |
| + |
| +namespace { |
| + |
|
Vitaly Buka (NO REVIEWS)
2014/06/03 21:30:49
empty lines inconsistent
Noam Samuel
2014/06/03 21:48:13
Done.
|
| +const char kUploadData[] = "{ \"userEmail\": \"me\" }"; |
| +const char kKindRegistrationTicket[] = "clouddevices#registrationTicket"; |
| +const char kGCDKeyId[] = "id"; |
| +} |
| + |
| +GCDRegistrationTicketCreator::GCDRegistrationTicketCreator( |
| + const ResponseCallback& callback) |
| + : callback_(callback) { |
| +} |
| + |
| +GCDRegistrationTicketCreator::~GCDRegistrationTicketCreator() { |
| +} |
| + |
| +void GCDRegistrationTicketCreator::GetUploadData(std::string* upload_type, |
| + std::string* upload_data) { |
| + *upload_data = kUploadData; |
| + |
| + // TODO(noamsml): Move this constant to cloud_devices component. |
| + *upload_type = cloud_print::kContentTypeJSON; |
| +} |
| + |
| +net::URLFetcher::RequestType GCDRegistrationTicketCreator::GetRequestType() { |
| + return net::URLFetcher::POST; |
| +} |
| + |
| +void GCDRegistrationTicketCreator::OnGCDAPIFlowError( |
| + GCDApiFlow::Status status) { |
| + callback_.Run(std::string()); |
| +} |
| + |
| +void GCDRegistrationTicketCreator::OnGCDAPIFlowComplete( |
| + const base::DictionaryValue& value) { |
| + std::string kind; |
| + std::string id; |
| + if (!value.GetString(kGCDKeyKind, &kind) || kind != kKindRegistrationTicket || |
| + !value.GetString(kGCDKeyId, &id)) { |
| + callback_.Run(std::string()); |
| + return; |
| + } |
| + |
| + callback_.Run(id); |
| +} |
| + |
| +GURL GCDRegistrationTicketCreator::GetURL() { |
| + return cloud_devices::GetCloudDevicesRelativeURL("registrationTickets"); |
| +} |
| + |
| +} // namespace local_discovery |