Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / local_discovery / gcd_registration_ticket_request.cc
blob26f1f5eeb64b721a0d77fdb602a3cb500cec7f2e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/local_discovery/gcd_registration_ticket_request.h"
7 #include "chrome/browser/local_discovery/gcd_constants.h"
8 #include "chrome/common/cloud_print/cloud_print_constants.h"
9 #include "components/cloud_devices/common/cloud_devices_urls.h"
11 namespace local_discovery {
13 namespace {
15 const char kUploadData[] = "{ \"userEmail\": \"me\" }";
16 const char kKindRegistrationTicket[] = "clouddevices#registrationTicket";
17 const char kGCDKeyId[] = "id";
20 GCDRegistrationTicketRequest::GCDRegistrationTicketRequest(
21 const ResponseCallback& callback)
22 : callback_(callback) {
25 GCDRegistrationTicketRequest::~GCDRegistrationTicketRequest() {
28 void GCDRegistrationTicketRequest::GetUploadData(std::string* upload_type,
29 std::string* upload_data) {
30 *upload_data = kUploadData;
32 // TODO(noamsml): Move this constant to cloud_devices component.
33 *upload_type = cloud_print::kContentTypeJSON;
36 net::URLFetcher::RequestType GCDRegistrationTicketRequest::GetRequestType() {
37 return net::URLFetcher::POST;
40 void GCDRegistrationTicketRequest::OnGCDAPIFlowError(
41 GCDApiFlow::Status status) {
42 callback_.Run(std::string(), std::string());
45 void GCDRegistrationTicketRequest::OnGCDAPIFlowComplete(
46 const base::DictionaryValue& value) {
47 std::string kind;
48 std::string id;
49 std::string device_id;
50 value.GetString(kGCDKeyKind, &kind);
51 if (kind == kKindRegistrationTicket) {
52 value.GetString(kGCDKeyId, &id);
53 value.GetString(kGCDKeyDeviceId, &device_id);
55 callback_.Run(id, device_id);
58 GURL GCDRegistrationTicketRequest::GetURL() {
59 return cloud_devices::GetCloudDevicesRelativeURL("registrationTickets");
62 } // namespace local_discovery