OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/local_discovery/gcd_registration_ticket_creator.h" | |
6 | |
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" | |
10 | |
11 namespace local_discovery { | |
12 | |
13 namespace { | |
14 | |
Vitaly Buka (NO REVIEWS)
2014/06/03 21:30:49
empty lines inconsistent
Noam Samuel
2014/06/03 21:48:13
Done.
| |
15 const char kUploadData[] = "{ \"userEmail\": \"me\" }"; | |
16 const char kKindRegistrationTicket[] = "clouddevices#registrationTicket"; | |
17 const char kGCDKeyId[] = "id"; | |
18 } | |
19 | |
20 GCDRegistrationTicketCreator::GCDRegistrationTicketCreator( | |
21 const ResponseCallback& callback) | |
22 : callback_(callback) { | |
23 } | |
24 | |
25 GCDRegistrationTicketCreator::~GCDRegistrationTicketCreator() { | |
26 } | |
27 | |
28 void GCDRegistrationTicketCreator::GetUploadData(std::string* upload_type, | |
29 std::string* upload_data) { | |
30 *upload_data = kUploadData; | |
31 | |
32 // TODO(noamsml): Move this constant to cloud_devices component. | |
33 *upload_type = cloud_print::kContentTypeJSON; | |
34 } | |
35 | |
36 net::URLFetcher::RequestType GCDRegistrationTicketCreator::GetRequestType() { | |
37 return net::URLFetcher::POST; | |
38 } | |
39 | |
40 void GCDRegistrationTicketCreator::OnGCDAPIFlowError( | |
41 GCDApiFlow::Status status) { | |
42 callback_.Run(std::string()); | |
43 } | |
44 | |
45 void GCDRegistrationTicketCreator::OnGCDAPIFlowComplete( | |
46 const base::DictionaryValue& value) { | |
47 std::string kind; | |
48 std::string id; | |
49 if (!value.GetString(kGCDKeyKind, &kind) || kind != kKindRegistrationTicket || | |
50 !value.GetString(kGCDKeyId, &id)) { | |
51 callback_.Run(std::string()); | |
52 return; | |
53 } | |
54 | |
55 callback_.Run(id); | |
56 } | |
57 | |
58 GURL GCDRegistrationTicketCreator::GetURL() { | |
59 return cloud_devices::GetCloudDevicesRelativeURL("registrationTickets"); | |
60 } | |
61 | |
62 } // namespace local_discovery | |
OLD | NEW |