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 "webrtc/base/common.h"
13 #include "webrtc/base/socketaddress.h"
14
15 namespace notifier {
16
LoginSettings(const buzz::XmppClientSettings & user_settings,const scoped_refptr<net::URLRequestContextGetter> & request_context_getter,const ServerList & default_servers,bool try_ssltcp_first,const std::string & auth_mechanism)17 LoginSettings::LoginSettings(const buzz::XmppClientSettings& user_settings,
18 const scoped_refptr<net::URLRequestContextGetter>&
19 request_context_getter,
20 const ServerList& default_servers,
21 bool try_ssltcp_first,
22 const std::string& auth_mechanism)
23 : user_settings_(user_settings),
24 request_context_getter_(request_context_getter),
25 default_servers_(default_servers),
26 try_ssltcp_first_(try_ssltcp_first),
27 auth_mechanism_(auth_mechanism) {
28 DCHECK_GT(default_servers_.size(), 0u);
29 }
30
~LoginSettings()31 LoginSettings::~LoginSettings() {}
32
set_user_settings(const buzz::XmppClientSettings & user_settings)33 void LoginSettings::set_user_settings(
34 const buzz::XmppClientSettings& user_settings) {
35 user_settings_ = user_settings;
36 }
37
GetServers() const38 ServerList LoginSettings::GetServers() const {
39 return GetServersForTime(base::Time::Now());
40 }
41
42 namespace {
43
44 // How long a redirect is valid for.
45 const int kRedirectExpirationTimeMinutes = 5;
46
47 } // namespace
48
SetRedirectServer(const ServerInformation & redirect_server)49 void LoginSettings::SetRedirectServer(
50 const ServerInformation& redirect_server) {
51 redirect_server_ = redirect_server;
52 redirect_expiration_ =
53 base::Time::Now() +
54 base::TimeDelta::FromMinutes(kRedirectExpirationTimeMinutes);
55 }
56
GetServersForTimeForTest(base::Time now) const57 ServerList LoginSettings::GetServersForTimeForTest(base::Time now) const {
58 return GetServersForTime(now);
59 }
60
GetRedirectExpirationForTest() const61 base::Time LoginSettings::GetRedirectExpirationForTest() const {
62 return redirect_expiration_;
63 }
64
GetServersForTime(base::Time now) const65 ServerList LoginSettings::GetServersForTime(base::Time now) const {
66 return
67 (now < redirect_expiration_) ?
68 ServerList(1, redirect_server_) :
69 default_servers_;
70 }
71
72 } // namespace notifier
73