Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cloud_print/gcp20/prototype/printer.h" | 5 #include "cloud_print/gcp20/prototype/printer.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 175 |
| 176 void Printer::Stop() { | 176 void Printer::Stop() { |
| 177 dns_server_.Shutdown(); | 177 dns_server_.Shutdown(); |
| 178 http_server_.Shutdown(); | 178 http_server_.Shutdown(); |
| 179 requester_.reset(); | 179 requester_.reset(); |
| 180 print_job_handler_.reset(); | 180 print_job_handler_.reset(); |
| 181 xmpp_listener_.reset(); | 181 xmpp_listener_.reset(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void Printer::OnAuthError() { | 184 void Printer::OnAuthError() { |
| 185 access_token_update_ = base::Time::Now(); | 185 access_token_update_ = base::Time::UnixEpoch(); |
| 186 ChangeState(OFFLINE); | 186 ReconnectIn(base::TimeDelta::FromSeconds(0)); |
| 187 // TODO(maksymb): Implement *instant* updating of access_token. | |
| 188 } | 187 } |
| 189 | 188 |
| 190 std::string Printer::GetAccessToken() { | 189 std::string Printer::GetAccessToken() { |
| 191 return access_token_; | 190 return access_token_; |
| 192 } | 191 } |
| 193 | 192 |
| 194 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart( | 193 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart( |
| 195 const std::string& user) { | 194 const std::string& user) { |
| 196 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); | 195 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); |
| 197 if (status != PrivetHttpServer::REG_ERROR_OK) | 196 if (status != PrivetHttpServer::REG_ERROR_OK) |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 return "connecting"; | 748 return "connecting"; |
| 750 case NOT_CONFIGURED: | 749 case NOT_CONFIGURED: |
| 751 return "not-configured"; | 750 return "not-configured"; |
| 752 | 751 |
| 753 default: | 752 default: |
| 754 NOTREACHED(); | 753 NOTREACHED(); |
| 755 return ""; | 754 return ""; |
| 756 } | 755 } |
| 757 } | 756 } |
| 758 | 757 |
| 758 void Printer::ReconnectIn(const base::TimeDelta& delay) { | |
| 759 requester_.reset(); | |
| 760 xmpp_listener_.reset(); | |
| 761 base::MessageLoop::current()->PostDelayedTask( | |
|
gene
2013/08/05 20:56:28
Since this is a post task, it is possible you can
maksymb
2013/08/06 21:45:54
Done.
gene
2013/08/08 02:01:55
Could you please explain how this has been fixed?
maksymb
2013/08/08 18:35:46
/privet/accesstoken can be processed only in OnIdl
| |
| 762 FROM_HERE, | |
| 763 base::Bind(&Printer::TryConnect, AsWeakPtr()), | |
| 764 delay); | |
| 765 } | |
| 766 | |
| 759 bool Printer::ChangeState(ConnectionState new_state) { | 767 bool Printer::ChangeState(ConnectionState new_state) { |
| 760 if (connection_state_ == new_state) | 768 if (connection_state_ == new_state) |
| 761 return false; | 769 return false; |
| 762 | 770 |
| 763 connection_state_ = new_state; | 771 connection_state_ = new_state; |
| 764 LOG(INFO) << base::StringPrintf( | 772 LOG(INFO) << base::StringPrintf( |
| 765 "Printer is now %s (%s)", | 773 "Printer is now %s (%s)", |
| 766 ConnectionStateToString(connection_state_).c_str(), | 774 ConnectionStateToString(connection_state_).c_str(), |
| 767 IsRegistered() ? "registered" : "unregistered"); | 775 IsRegistered() ? "registered" : "unregistered"); |
| 768 | 776 |
| 769 dns_server_.UpdateMetadata(CreateTxt()); | 777 dns_server_.UpdateMetadata(CreateTxt()); |
| 770 | 778 |
| 771 switch (connection_state_) { | 779 if (connection_state_ == OFFLINE) |
| 772 case CONNECTING: | 780 ReconnectIn(base::TimeDelta::FromSeconds(kReconnectTimeout)); |
| 773 break; | |
| 774 | |
| 775 case ONLINE: | |
| 776 break; | |
| 777 | |
| 778 case OFFLINE: | |
| 779 requester_.reset(); | |
| 780 xmpp_listener_.reset(); | |
| 781 base::MessageLoop::current()->PostDelayedTask( | |
| 782 FROM_HERE, | |
| 783 base::Bind(&Printer::TryConnect, AsWeakPtr()), | |
| 784 base::TimeDelta::FromSeconds(kReconnectTimeout)); | |
| 785 | |
| 786 case NOT_CONFIGURED: | |
| 787 break; | |
| 788 | |
| 789 default: | |
| 790 NOTREACHED(); | |
| 791 } | |
| 792 | 781 |
| 793 return true; | 782 return true; |
| 794 } | 783 } |
| 795 | 784 |
| OLD | NEW |