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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_channel_id_helper.cc

Issue 459233002: Browsing Data Deletion: Style fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-apply comment tweaks Created 6 years, 4 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/browsing_data/browsing_data_channel_id_helper.h" 5 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "net/ssl/channel_id_service.h" 13 #include "net/ssl/channel_id_service.h"
14 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
15 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_context_getter.h"
16 16
17 using content::BrowserThread;
18
17 namespace { 19 namespace {
18 20
19 class BrowsingDataChannelIDHelperImpl 21 class BrowsingDataChannelIDHelperImpl
20 : public BrowsingDataChannelIDHelper { 22 : public BrowsingDataChannelIDHelper {
21 public: 23 public:
22 explicit BrowsingDataChannelIDHelperImpl(Profile* profile); 24 explicit BrowsingDataChannelIDHelperImpl(Profile* profile);
23 25
24 // BrowsingDataChannelIDHelper methods. 26 // BrowsingDataChannelIDHelper methods.
25 virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE; 27 virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE;
26 virtual void DeleteChannelID(const std::string& server_id) OVERRIDE; 28 virtual void DeleteChannelID(const std::string& server_id) OVERRIDE;
(...skipping 13 matching lines...) Expand all
40 42
41 // Delete a single cert. This must be called in IO thread. 43 // Delete a single cert. This must be called in IO thread.
42 void DeleteOnIOThread(const std::string& server_id); 44 void DeleteOnIOThread(const std::string& server_id);
43 45
44 // Called when deletion is done. 46 // Called when deletion is done.
45 void DeleteCallback(); 47 void DeleteCallback();
46 48
47 // Indicates whether or not we're currently fetching information: 49 // Indicates whether or not we're currently fetching information:
48 // it's true when StartFetching() is called in the UI thread, and it's reset 50 // it's true when StartFetching() is called in the UI thread, and it's reset
49 // after we notify the callback in the UI thread. 51 // after we notify the callback in the UI thread.
50 // This only mutates on the UI thread. 52 // This member is only mutated on the UI thread.
51 bool is_fetching_; 53 bool is_fetching_;
52 54
53 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
54 56
55 // This only mutates on the UI thread. 57 // This member is only mutated on the UI thread.
56 FetchResultCallback completion_callback_; 58 FetchResultCallback completion_callback_;
57 59
58 DISALLOW_COPY_AND_ASSIGN(BrowsingDataChannelIDHelperImpl); 60 DISALLOW_COPY_AND_ASSIGN(BrowsingDataChannelIDHelperImpl);
59 }; 61 };
60 62
61 BrowsingDataChannelIDHelperImpl:: 63 BrowsingDataChannelIDHelperImpl::
62 BrowsingDataChannelIDHelperImpl(Profile* profile) 64 BrowsingDataChannelIDHelperImpl(Profile* profile)
63 : is_fetching_(false), 65 : is_fetching_(false),
64 request_context_getter_(profile->GetRequestContext()) { 66 request_context_getter_(profile->GetRequestContext()) {
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
66 } 68 }
67 69
68 BrowsingDataChannelIDHelperImpl:: 70 BrowsingDataChannelIDHelperImpl::
69 ~BrowsingDataChannelIDHelperImpl() { 71 ~BrowsingDataChannelIDHelperImpl() {
70 } 72 }
71 73
72 void BrowsingDataChannelIDHelperImpl::StartFetching( 74 void BrowsingDataChannelIDHelperImpl::StartFetching(
73 const FetchResultCallback& callback) { 75 const FetchResultCallback& callback) {
74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 76 DCHECK_CURRENTLY_ON(BrowserThread::UI);
75 DCHECK(!is_fetching_); 77 DCHECK(!is_fetching_);
76 DCHECK(!callback.is_null()); 78 DCHECK(!callback.is_null());
77 DCHECK(completion_callback_.is_null()); 79 DCHECK(completion_callback_.is_null());
78 is_fetching_ = true; 80 is_fetching_ = true;
79 completion_callback_ = callback; 81 completion_callback_ = callback;
80 content::BrowserThread::PostTask( 82 BrowserThread::PostTask(
81 content::BrowserThread::IO, FROM_HERE, 83 BrowserThread::IO,
82 base::Bind(&BrowsingDataChannelIDHelperImpl::FetchOnIOThread, 84 FROM_HERE,
83 this)); 85 base::Bind(&BrowsingDataChannelIDHelperImpl::FetchOnIOThread, this));
84 } 86 }
85 87
86 void BrowsingDataChannelIDHelperImpl::DeleteChannelID( 88 void BrowsingDataChannelIDHelperImpl::DeleteChannelID(
87 const std::string& server_id) { 89 const std::string& server_id) {
88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 90 DCHECK_CURRENTLY_ON(BrowserThread::UI);
89 content::BrowserThread::PostTask( 91 BrowserThread::PostTask(
90 content::BrowserThread::IO, FROM_HERE, 92 BrowserThread::IO,
91 base::Bind(&BrowsingDataChannelIDHelperImpl::DeleteOnIOThread, 93 FROM_HERE,
92 this, server_id)); 94 base::Bind(
95 &BrowsingDataChannelIDHelperImpl::DeleteOnIOThread, this, server_id));
93 } 96 }
94 97
95 void BrowsingDataChannelIDHelperImpl::FetchOnIOThread() { 98 void BrowsingDataChannelIDHelperImpl::FetchOnIOThread() {
96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 99 DCHECK_CURRENTLY_ON(BrowserThread::IO);
97 net::ChannelIDStore* cert_store = 100 net::ChannelIDStore* cert_store =
98 request_context_getter_->GetURLRequestContext()-> 101 request_context_getter_->GetURLRequestContext()->
99 channel_id_service()->GetChannelIDStore(); 102 channel_id_service()->GetChannelIDStore();
100 if (cert_store) { 103 if (cert_store) {
101 cert_store->GetAllChannelIDs(base::Bind( 104 cert_store->GetAllChannelIDs(base::Bind(
102 &BrowsingDataChannelIDHelperImpl::OnFetchComplete, this)); 105 &BrowsingDataChannelIDHelperImpl::OnFetchComplete, this));
103 } else { 106 } else {
104 OnFetchComplete(net::ChannelIDStore::ChannelIDList()); 107 OnFetchComplete(net::ChannelIDStore::ChannelIDList());
105 } 108 }
106 } 109 }
107 110
108 void BrowsingDataChannelIDHelperImpl::OnFetchComplete( 111 void BrowsingDataChannelIDHelperImpl::OnFetchComplete(
109 const net::ChannelIDStore::ChannelIDList& channel_id_list) { 112 const net::ChannelIDStore::ChannelIDList& channel_id_list) {
110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 113 DCHECK_CURRENTLY_ON(BrowserThread::IO);
111 content::BrowserThread::PostTask( 114 BrowserThread::PostTask(
112 content::BrowserThread::UI, FROM_HERE, 115 BrowserThread::UI,
116 FROM_HERE,
113 base::Bind(&BrowsingDataChannelIDHelperImpl::NotifyInUIThread, 117 base::Bind(&BrowsingDataChannelIDHelperImpl::NotifyInUIThread,
114 this, channel_id_list)); 118 this,
119 channel_id_list));
115 } 120 }
116 121
117 void BrowsingDataChannelIDHelperImpl::NotifyInUIThread( 122 void BrowsingDataChannelIDHelperImpl::NotifyInUIThread(
118 const net::ChannelIDStore::ChannelIDList& channel_id_list) { 123 const net::ChannelIDStore::ChannelIDList& channel_id_list) {
119 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 124 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 DCHECK(is_fetching_); 125 DCHECK(is_fetching_);
121 is_fetching_ = false; 126 is_fetching_ = false;
122 completion_callback_.Run(channel_id_list); 127 completion_callback_.Run(channel_id_list);
123 completion_callback_.Reset(); 128 completion_callback_.Reset();
124 } 129 }
125 130
126 void BrowsingDataChannelIDHelperImpl::DeleteOnIOThread( 131 void BrowsingDataChannelIDHelperImpl::DeleteOnIOThread(
127 const std::string& server_id) { 132 const std::string& server_id) {
128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 133 DCHECK_CURRENTLY_ON(BrowserThread::IO);
129 net::ChannelIDStore* cert_store = 134 net::ChannelIDStore* cert_store =
130 request_context_getter_->GetURLRequestContext()-> 135 request_context_getter_->GetURLRequestContext()->
131 channel_id_service()->GetChannelIDStore(); 136 channel_id_service()->GetChannelIDStore();
132 if (cert_store) { 137 if (cert_store) {
133 cert_store->DeleteChannelID( 138 cert_store->DeleteChannelID(
134 server_id, 139 server_id,
135 base::Bind(&BrowsingDataChannelIDHelperImpl::DeleteCallback, 140 base::Bind(&BrowsingDataChannelIDHelperImpl::DeleteCallback,
136 this)); 141 this));
137 } 142 }
138 } 143 }
139 144
140 void BrowsingDataChannelIDHelperImpl::DeleteCallback() { 145 void BrowsingDataChannelIDHelperImpl::DeleteCallback() {
141 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 146 DCHECK_CURRENTLY_ON(BrowserThread::IO);
142 // Need to close open SSL connections which may be using the channel ids we 147 // Need to close open SSL connections which may be using the channel ids we
143 // are deleting. 148 // are deleting.
144 // TODO(mattm): http://crbug.com/166069 Make the server bound cert 149 // TODO(mattm): http://crbug.com/166069 Make the server bound cert
145 // service/store have observers that can notify relevant things directly. 150 // service/store have observers that can notify relevant things directly.
146 request_context_getter_->GetURLRequestContext()->ssl_config_service()-> 151 request_context_getter_->GetURLRequestContext()->ssl_config_service()->
147 NotifySSLConfigChange(); 152 NotifySSLConfigChange();
148 } 153 }
149 154
150 } // namespace 155 } // namespace
151 156
152 // static 157 // static
153 BrowsingDataChannelIDHelper* 158 BrowsingDataChannelIDHelper*
154 BrowsingDataChannelIDHelper::Create(Profile* profile) { 159 BrowsingDataChannelIDHelper::Create(Profile* profile) {
155 return new BrowsingDataChannelIDHelperImpl(profile); 160 return new BrowsingDataChannelIDHelperImpl(profile);
156 } 161 }
157 162
158 CannedBrowsingDataChannelIDHelper:: 163 CannedBrowsingDataChannelIDHelper::
159 CannedBrowsingDataChannelIDHelper() {} 164 CannedBrowsingDataChannelIDHelper() {}
160 165
161 CannedBrowsingDataChannelIDHelper:: 166 CannedBrowsingDataChannelIDHelper::
162 ~CannedBrowsingDataChannelIDHelper() {} 167 ~CannedBrowsingDataChannelIDHelper() {}
163 168
164 CannedBrowsingDataChannelIDHelper* 169 CannedBrowsingDataChannelIDHelper*
165 CannedBrowsingDataChannelIDHelper::Clone() { 170 CannedBrowsingDataChannelIDHelper::Clone() {
166 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 171 DCHECK_CURRENTLY_ON(BrowserThread::UI);
167 CannedBrowsingDataChannelIDHelper* clone = 172 CannedBrowsingDataChannelIDHelper* clone =
168 new CannedBrowsingDataChannelIDHelper(); 173 new CannedBrowsingDataChannelIDHelper();
169 174
170 clone->channel_id_map_ = channel_id_map_; 175 clone->channel_id_map_ = channel_id_map_;
171 return clone; 176 return clone;
172 } 177 }
173 178
174 void CannedBrowsingDataChannelIDHelper::AddChannelID( 179 void CannedBrowsingDataChannelIDHelper::AddChannelID(
175 const net::ChannelIDStore::ChannelID& channel_id) { 180 const net::ChannelIDStore::ChannelID& channel_id) {
176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 181 DCHECK_CURRENTLY_ON(BrowserThread::UI);
177 channel_id_map_[channel_id.server_identifier()] = 182 channel_id_map_[channel_id.server_identifier()] =
178 channel_id; 183 channel_id;
179 } 184 }
180 185
181 void CannedBrowsingDataChannelIDHelper::Reset() { 186 void CannedBrowsingDataChannelIDHelper::Reset() {
182 channel_id_map_.clear(); 187 channel_id_map_.clear();
183 } 188 }
184 189
185 bool CannedBrowsingDataChannelIDHelper::empty() const { 190 bool CannedBrowsingDataChannelIDHelper::empty() const {
186 return channel_id_map_.empty(); 191 return channel_id_map_.empty();
187 } 192 }
188 193
189 size_t CannedBrowsingDataChannelIDHelper::GetChannelIDCount() const { 194 size_t CannedBrowsingDataChannelIDHelper::GetChannelIDCount() const {
190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 195 DCHECK_CURRENTLY_ON(BrowserThread::UI);
191 return channel_id_map_.size(); 196 return channel_id_map_.size();
192 } 197 }
193 198
194 void CannedBrowsingDataChannelIDHelper::StartFetching( 199 void CannedBrowsingDataChannelIDHelper::StartFetching(
195 const FetchResultCallback& callback) { 200 const FetchResultCallback& callback) {
196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 201 DCHECK_CURRENTLY_ON(BrowserThread::UI);
197 if (callback.is_null()) 202 if (callback.is_null())
198 return; 203 return;
199 // We post a task to emulate async fetching behavior. 204 // We post a task to emulate async fetching behavior.
200 completion_callback_ = callback; 205 completion_callback_ = callback;
201 base::MessageLoop::current()->PostTask( 206 base::MessageLoop::current()->PostTask(
202 FROM_HERE, 207 FROM_HERE,
203 base::Bind(&CannedBrowsingDataChannelIDHelper::FinishFetching, 208 base::Bind(&CannedBrowsingDataChannelIDHelper::FinishFetching,
204 this)); 209 this));
205 } 210 }
206 211
207 void CannedBrowsingDataChannelIDHelper::FinishFetching() { 212 void CannedBrowsingDataChannelIDHelper::FinishFetching() {
208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 213 DCHECK_CURRENTLY_ON(BrowserThread::UI);
209 net::ChannelIDStore::ChannelIDList channel_id_list; 214 net::ChannelIDStore::ChannelIDList channel_id_list;
210 for (ChannelIDMap::iterator i = channel_id_map_.begin(); 215 for (ChannelIDMap::iterator i = channel_id_map_.begin();
211 i != channel_id_map_.end(); ++i) 216 i != channel_id_map_.end(); ++i)
212 channel_id_list.push_back(i->second); 217 channel_id_list.push_back(i->second);
213 completion_callback_.Run(channel_id_list); 218 completion_callback_.Run(channel_id_list);
214 } 219 }
215 220
216 void CannedBrowsingDataChannelIDHelper::DeleteChannelID( 221 void CannedBrowsingDataChannelIDHelper::DeleteChannelID(
217 const std::string& server_id) { 222 const std::string& server_id) {
218 NOTREACHED(); 223 NOTREACHED();
219 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698