Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/local_discovery/privetv3_session.cc

Issue 468613003: API change to allow sticker authentication for devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/local_discovery/privet_http.h" 10 #include "chrome/browser/local_discovery/privet_http.h"
11 #include "chrome/common/cloud_print/cloud_print_constants.h" 11 #include "chrome/common/cloud_print/cloud_print_constants.h"
12 12
13 namespace local_discovery { 13 namespace local_discovery {
14 14
15 namespace { 15 namespace {
16 16
17 const char kUrlPlaceHolder[] = "http://host/"; 17 const char kUrlPlaceHolder[] = "http://host/";
18 18
19 const char kStubPrivetCode[] = "01234";
20
19 GURL CreatePrivetURL(const std::string& path) { 21 GURL CreatePrivetURL(const std::string& path) {
20 GURL url(kUrlPlaceHolder); 22 GURL url(kUrlPlaceHolder);
21 GURL::Replacements replacements; 23 GURL::Replacements replacements;
22 replacements.SetPathStr(path); 24 replacements.SetPathStr(path);
23 return url.ReplaceComponents(replacements); 25 return url.ReplaceComponents(replacements);
24 } 26 }
25 27
26 } // namespace 28 } // namespace
27 29
28 class PrivetV3Session::FetcherDelegate : public PrivetURLFetcher::Delegate { 30 class PrivetV3Session::FetcherDelegate : public PrivetURLFetcher::Delegate {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 100 }
99 101
100 void PrivetV3Session::Start() { 102 void PrivetV3Session::Start() {
101 base::MessageLoop::current()->PostDelayedTask( 103 base::MessageLoop::current()->PostDelayedTask(
102 FROM_HERE, 104 FROM_HERE,
103 base::Bind(&PrivetV3Session::ConfirmFakeCode, 105 base::Bind(&PrivetV3Session::ConfirmFakeCode,
104 weak_ptr_factory_.GetWeakPtr()), 106 weak_ptr_factory_.GetWeakPtr()),
105 base::TimeDelta::FromSeconds(1)); 107 base::TimeDelta::FromSeconds(1));
106 } 108 }
107 109
108 void PrivetV3Session::ConfirmCode() { 110 void PrivetV3Session::ConfirmCode(const std::string& code) {
109 code_confirmed_ = true; 111 if (code == kStubPrivetCode) {
110 delegate_->OnSessionEstablished(); 112 code_confirmed_ = true;
113 delegate_->OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS);
114 } else {
115 delegate_->OnSessionStatus(
116 extensions::api::gcd_private::STATUS_BADCONFIRMATIONCODEERROR);
117 }
111 } 118 }
112 119
113 void PrivetV3Session::StartRequest(Request* request) { 120 void PrivetV3Session::StartRequest(Request* request) {
114 CHECK(code_confirmed_); 121 CHECK(code_confirmed_);
115 122
116 request->fetcher_delegate_.reset( 123 request->fetcher_delegate_.reset(
117 new FetcherDelegate(weak_ptr_factory_.GetWeakPtr(), request)); 124 new FetcherDelegate(weak_ptr_factory_.GetWeakPtr(), request));
118 125
119 scoped_ptr<PrivetURLFetcher> url_fetcher = 126 scoped_ptr<PrivetURLFetcher> url_fetcher =
120 client_->CreateURLFetcher(CreatePrivetURL(request->GetName()), 127 client_->CreateURLFetcher(CreatePrivetURL(request->GetName()),
121 net::URLFetcher::POST, 128 net::URLFetcher::POST,
122 request->fetcher_delegate_.get()); 129 request->fetcher_delegate_.get());
123 std::string json; 130 std::string json;
124 base::JSONWriter::WriteWithOptions( 131 base::JSONWriter::WriteWithOptions(
125 &request->GetInput(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); 132 &request->GetInput(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
126 url_fetcher->SetUploadData(cloud_print::kContentTypeJSON, json); 133 url_fetcher->SetUploadData(cloud_print::kContentTypeJSON, json);
127 134
128 request->fetcher_delegate_->url_fetcher_ = url_fetcher.Pass(); 135 request->fetcher_delegate_->url_fetcher_ = url_fetcher.Pass();
129 request->fetcher_delegate_->url_fetcher_->Start(); 136 request->fetcher_delegate_->url_fetcher_->Start();
130 } 137 }
131 138
132 void PrivetV3Session::ConfirmFakeCode() { 139 void PrivetV3Session::ConfirmFakeCode() {
133 delegate_->OnSetupConfirmationNeeded("01234"); 140 delegate_->OnSetupConfirmationNeeded(
141 kStubPrivetCode,
142 extensions::api::gcd_private::CONFIRMATION_TYPE_DISPLAYCODE);
134 } 143 }
135 144
136 } // namespace local_discovery 145 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privetv3_session.h ('k') | chrome/browser/local_discovery/privetv3_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698