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

Side by Side Diff: net/dns/dns_client.cc

Issue 1898033006: DNS: Add stubs for persisting data across restarts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and fix bad merge. Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "net/dns/dns_client.h" 5 #include "net/dns/dns_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "net/dns/address_sorter.h" 12 #include "net/dns/address_sorter.h"
13 #include "net/dns/dns_config_service.h" 13 #include "net/dns/dns_config_service.h"
14 #include "net/dns/dns_session.h" 14 #include "net/dns/dns_session.h"
15 #include "net/dns/dns_socket_pool.h" 15 #include "net/dns/dns_socket_pool.h"
16 #include "net/dns/dns_transaction.h" 16 #include "net/dns/dns_transaction.h"
17 #include "net/log/net_log.h" 17 #include "net/log/net_log.h"
18 #include "net/socket/client_socket_factory.h" 18 #include "net/socket/client_socket_factory.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 namespace { 22 namespace {
23 23
24 #if !defined(OS_IOS)
Charlie Harrison 2016/07/26 13:49:42 Why is this necessary?
Julia Tuttle 2016/07/26 21:10:13 It's not! Fixed.
24 class DnsClientImpl : public DnsClient { 25 class DnsClientImpl : public DnsClient {
25 public: 26 public:
26 DnsClientImpl(NetLog* net_log, 27 DnsClientImpl(NetLog* net_log,
27 ClientSocketFactory* socket_factory, 28 ClientSocketFactory* socket_factory,
28 const RandIntCallback& rand_int_callback) 29 const RandIntCallback& rand_int_callback)
29 : address_sorter_(AddressSorter::CreateAddressSorter()), 30 : address_sorter_(AddressSorter::CreateAddressSorter()),
30 net_log_(net_log), 31 net_log_(net_log),
31 socket_factory_(socket_factory), 32 socket_factory_(socket_factory),
32 rand_int_callback_(rand_int_callback) {} 33 rand_int_callback_(rand_int_callback) {}
33 34
(...skipping 15 matching lines...) Expand all
49 const DnsConfig* GetConfig() const override { 50 const DnsConfig* GetConfig() const override {
50 return session_.get() ? &session_->config() : NULL; 51 return session_.get() ? &session_->config() : NULL;
51 } 52 }
52 53
53 DnsTransactionFactory* GetTransactionFactory() override { 54 DnsTransactionFactory* GetTransactionFactory() override {
54 return session_.get() ? factory_.get() : NULL; 55 return session_.get() ? factory_.get() : NULL;
55 } 56 }
56 57
57 AddressSorter* GetAddressSorter() override { return address_sorter_.get(); } 58 AddressSorter* GetAddressSorter() override { return address_sorter_.get(); }
58 59
60 std::unique_ptr<const base::Value> GetPersistentData() const override {
61 if (!session_)
62 return std::unique_ptr<const base::Value>();
63 return session_->GetPersistentData();
64 }
65
66 void ApplyPersistentData(const base::Value& data) override {
67 if (!session_)
68 return;
69 session_->ApplyPersistentData(data);
70 }
71
59 private: 72 private:
60 scoped_refptr<DnsSession> session_; 73 scoped_refptr<DnsSession> session_;
61 std::unique_ptr<DnsTransactionFactory> factory_; 74 std::unique_ptr<DnsTransactionFactory> factory_;
62 std::unique_ptr<AddressSorter> address_sorter_; 75 std::unique_ptr<AddressSorter> address_sorter_;
63 76
64 NetLog* net_log_; 77 NetLog* net_log_;
65 78
66 ClientSocketFactory* socket_factory_; 79 ClientSocketFactory* socket_factory_;
67 const RandIntCallback rand_int_callback_; 80 const RandIntCallback rand_int_callback_;
68 81
69 DISALLOW_COPY_AND_ASSIGN(DnsClientImpl); 82 DISALLOW_COPY_AND_ASSIGN(DnsClientImpl);
70 }; 83 };
84 #endif // !defined(OS_IOS)
71 85
72 } // namespace 86 } // namespace
73 87
88 void DnsClient::ApplyPersistentData(const base::Value& data) {}
89
90 std::unique_ptr<const base::Value> DnsClient::GetPersistentData() const {
91 return std::unique_ptr<const base::Value>();
92 }
93
74 // static 94 // static
75 std::unique_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) { 95 std::unique_ptr<DnsClient> DnsClient::CreateClient(NetLog* net_log) {
96 #if !defined(OS_IOS)
76 return base::WrapUnique( 97 return base::WrapUnique(
77 new DnsClientImpl(net_log, ClientSocketFactory::GetDefaultFactory(), 98 new DnsClientImpl(net_log, ClientSocketFactory::GetDefaultFactory(),
78 base::Bind(&base::RandInt))); 99 base::Bind(&base::RandInt)));
100 #else // defined(OS_IOS)
101 NOTIMPLEMENTED();
102 return std::unique_ptr<DnsClient>(nullptr);
103 #endif // defined(OS_IOS)
79 } 104 }
80 105
81 // static 106 // static
82 std::unique_ptr<DnsClient> DnsClient::CreateClientForTesting( 107 std::unique_ptr<DnsClient> DnsClient::CreateClientForTesting(
83 NetLog* net_log, 108 NetLog* net_log,
84 ClientSocketFactory* socket_factory, 109 ClientSocketFactory* socket_factory,
85 const RandIntCallback& rand_int_callback) { 110 const RandIntCallback& rand_int_callback) {
111 #if !defined(OS_IOS)
86 return base::WrapUnique( 112 return base::WrapUnique(
87 new DnsClientImpl(net_log, socket_factory, rand_int_callback)); 113 new DnsClientImpl(net_log, socket_factory, rand_int_callback));
114 #else // defined(OS_IOS)
115 NOTIMPLEMENTED();
116 return std::unique_ptr<DnsClient>(nullptr);
117 #endif // defined(OS_IOS)
88 } 118 }
89 119
90 } // namespace net 120 } // namespace net
91 121
OLDNEW
« no previous file with comments | « net/dns/dns_client.h ('k') | net/dns/dns_session.h » ('j') | net/dns/host_resolver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698