1 // Copyright (c) 2012 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 <string>
6
7 #include "jingle/notifier/communicator/login_settings.h"
8
9 #include "base/logging.h"
10 #include "jingle/notifier/base/server_information.h"
11 #include "net/cert/cert_verifier.h"
12 #include "third_party/webrtc/rtc_base/socket_address.h"
13
14 namespace notifier {
15
LoginSettings(const jingle_xmpp::XmppClientSettings & user_settings,jingle_glue::GetProxyResolvingSocketFactoryCallback get_socket_factory_callback,const ServerList & default_servers,bool try_ssltcp_first,const std::string & auth_mechanism,const net::NetworkTrafficAnnotationTag & traffic_annotation)16 LoginSettings::LoginSettings(
17 const jingle_xmpp::XmppClientSettings& user_settings,
18 jingle_glue::GetProxyResolvingSocketFactoryCallback
19 get_socket_factory_callback,
20 const ServerList& default_servers,
21 bool try_ssltcp_first,
22 const std::string& auth_mechanism,
23 const net::NetworkTrafficAnnotationTag& traffic_annotation)
24 : user_settings_(user_settings),
25 get_socket_factory_callback_(get_socket_factory_callback),
26 default_servers_(default_servers),
27 try_ssltcp_first_(try_ssltcp_first),
28 auth_mechanism_(auth_mechanism),
29 traffic_annotation_(traffic_annotation) {
30 DCHECK_GT(default_servers_.size(), 0u);
31 }
32
33 LoginSettings::LoginSettings(const LoginSettings& other) = default;
34
~LoginSettings()35 LoginSettings::~LoginSettings() {}
36
set_user_settings(const jingle_xmpp::XmppClientSettings & user_settings)37 void LoginSettings::set_user_settings(
38 const jingle_xmpp::XmppClientSettings& user_settings) {
39 user_settings_ = user_settings;
40 }
41
GetServers() const42 ServerList LoginSettings::GetServers() const {
43 return GetServersForTime(base::Time::Now());
44 }
45
46 namespace {
47
48 // How long a redirect is valid for.
49 const int kRedirectExpirationTimeMinutes = 5;
50
51 } // namespace
52
SetRedirectServer(const ServerInformation & redirect_server)53 void LoginSettings::SetRedirectServer(
54 const ServerInformation& redirect_server) {
55 redirect_server_ = redirect_server;
56 redirect_expiration_ =
57 base::Time::Now() +
58 base::TimeDelta::FromMinutes(kRedirectExpirationTimeMinutes);
59 }
60
GetServersForTimeForTest(base::Time now) const61 ServerList LoginSettings::GetServersForTimeForTest(base::Time now) const {
62 return GetServersForTime(now);
63 }
64
GetRedirectExpirationForTest() const65 base::Time LoginSettings::GetRedirectExpirationForTest() const {
66 return redirect_expiration_;
67 }
68
GetServersForTime(base::Time now) const69 ServerList LoginSettings::GetServersForTime(base::Time now) const {
70 return
71 (now < redirect_expiration_) ?
72 ServerList(1, redirect_server_) :
73 default_servers_;
74 }
75
76 } // namespace notifier
77