OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/local_discovery/privetv3_session.h" | 5 #include "chrome/browser/local_discovery/privetv3_session.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "chrome/browser/local_discovery/privet_http.h" | 9 #include "chrome/browser/local_discovery/privet_http.h" |
10 #include "chrome/common/cloud_print/cloud_print_constants.h" | |
9 | 11 |
10 namespace local_discovery { | 12 namespace local_discovery { |
11 | 13 |
14 namespace { | |
15 | |
16 const char kUrlPlaceHolder[] = "http://host/"; | |
17 | |
18 GURL CreatePrivetURL(const std::string& path) { | |
19 GURL url(kUrlPlaceHolder); | |
20 GURL::Replacements replacements; | |
21 replacements.SetPathStr(path); | |
22 return url.ReplaceComponents(replacements); | |
23 } | |
24 | |
25 } // namespace | |
26 | |
12 PrivetV3Session::Delegate::~Delegate() { | 27 PrivetV3Session::Delegate::~Delegate() { |
13 } | 28 } |
14 | 29 |
30 PrivetV3Session::Request::Request() { | |
31 } | |
32 | |
15 PrivetV3Session::Request::~Request() { | 33 PrivetV3Session::Request::~Request() { |
16 } | 34 } |
17 | 35 |
36 std::vector<std::string> PrivetV3Session::Request::GetExtraRequestHeaders() { | |
37 return std::vector<std::string>(); | |
38 } | |
39 | |
18 PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, | 40 PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, |
19 Delegate* delegate) { | 41 Delegate* delegate) |
42 : delegate_(delegate), client_(client.Pass()), code_confirmed_(false) { | |
20 } | 43 } |
21 | 44 |
22 PrivetV3Session::~PrivetV3Session() { | 45 PrivetV3Session::~PrivetV3Session() { |
23 } | 46 } |
24 | 47 |
25 void PrivetV3Session::Start() { | 48 void PrivetV3Session::Start() { |
49 delegate_->OnSetupConfirmationNeeded("01234"); | |
50 } | |
51 | |
52 void PrivetV3Session::ConfirmCode() { | |
53 code_confirmed_ = true; | |
54 delegate_->OnSessionEstablished(); | |
55 } | |
56 | |
57 void PrivetV3Session::StartRequest(Request* request) { | |
58 CHECK(code_confirmed_); | |
59 request->url_fetcher_ = client_->CreateURLFetcher( | |
60 CreatePrivetURL(request->GetCallName()), net::URLFetcher::POST, request); | |
61 request->url_fetcher_->SendEmptyPrivetToken(); | |
Noam Samuel
2014/07/16 20:48:23
Please remove this line.
Vitaly Buka (NO REVIEWS)
2014/07/16 20:53:23
Done.
| |
62 | |
63 std::string json; | |
64 base::JSONWriter::WriteWithOptions( | |
65 &request->GetInput(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | |
66 request->url_fetcher_->SetUploadData(cloud_print::kContentTypeJSON, json); | |
67 request->url_fetcher_->Start(); | |
26 } | 68 } |
27 | 69 |
28 } // namespace local_discovery | 70 } // namespace local_discovery |
OLD | NEW |