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

Side by Side Diff: components/gcm_driver/crypto/gcm_key_store.cc

Issue 1701973003: Remove associated keying material when unregistering from GCM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/gcm_driver/crypto/gcm_key_store.h" 5 #include "components/gcm_driver/crypto/gcm_key_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 callback.Run(KeyPair(), std::string() /* auth_secret */); 135 callback.Run(KeyPair(), std::string() /* auth_secret */);
136 return; 136 return;
137 } 137 }
138 138
139 key_pairs_[app_id] = pair; 139 key_pairs_[app_id] = pair;
140 auth_secrets_[app_id] = auth_secret; 140 auth_secrets_[app_id] = auth_secret;
141 141
142 callback.Run(key_pairs_[app_id], auth_secret); 142 callback.Run(key_pairs_[app_id], auth_secret);
143 } 143 }
144 144
145 void GCMKeyStore::DeleteKeys(const std::string& app_id, 145 void GCMKeyStore::RemoveKeys(const std::string& app_id,
146 const DeleteCallback& callback) { 146 const base::Closure& callback) {
147 LazyInitialize(base::Bind(&GCMKeyStore::DeleteKeysAfterInitialize, 147 LazyInitialize(base::Bind(&GCMKeyStore::RemoveKeysAfterInitialize,
148 weak_factory_.GetWeakPtr(), app_id, callback)); 148 weak_factory_.GetWeakPtr(), app_id, callback));
149 } 149 }
150 150
151 void GCMKeyStore::DeleteKeysAfterInitialize(const std::string& app_id, 151 void GCMKeyStore::RemoveKeysAfterInitialize(const std::string& app_id,
152 const DeleteCallback& callback) { 152 const base::Closure& callback) {
153 DCHECK(state_ == State::INITIALIZED || state_ == State::FAILED); 153 DCHECK(state_ == State::INITIALIZED || state_ == State::FAILED);
154 const auto iter = key_pairs_.find(app_id); 154 const auto iter = key_pairs_.find(app_id);
155 if (iter == key_pairs_.end() || state_ != State::INITIALIZED) { 155 if (iter == key_pairs_.end() || state_ != State::INITIALIZED) {
156 callback.Run(true /* success */); 156 callback.Run();
157 return; 157 return;
158 } 158 }
159 159
160 using EntryVectorType = 160 using EntryVectorType =
161 leveldb_proto::ProtoDatabase<EncryptionData>::KeyEntryVector; 161 leveldb_proto::ProtoDatabase<EncryptionData>::KeyEntryVector;
162 162
163 scoped_ptr<EntryVectorType> entries_to_save(new EntryVectorType()); 163 scoped_ptr<EntryVectorType> entries_to_save(new EntryVectorType());
164 scoped_ptr<std::vector<std::string>> keys_to_remove( 164 scoped_ptr<std::vector<std::string>> keys_to_remove(
165 new std::vector<std::string>(1, app_id)); 165 new std::vector<std::string>(1, app_id));
166 166
167 database_->UpdateEntries( 167 database_->UpdateEntries(
168 std::move(entries_to_save), std::move(keys_to_remove), 168 std::move(entries_to_save), std::move(keys_to_remove),
169 base::Bind(&GCMKeyStore::DidDeleteKeys, weak_factory_.GetWeakPtr(), 169 base::Bind(&GCMKeyStore::DidRemoveKeys, weak_factory_.GetWeakPtr(),
170 app_id, callback)); 170 app_id, callback));
171 } 171 }
172 172
173 void GCMKeyStore::DidDeleteKeys(const std::string& app_id, 173 void GCMKeyStore::DidRemoveKeys(const std::string& app_id,
174 const DeleteCallback& callback, 174 const base::Closure& callback,
175 bool success) { 175 bool success) {
176 if (!success) { 176 // TODO(peter): Add a histogram for tracking |success|.
177
178 if (success) {
179 key_pairs_.erase(app_id);
180 auth_secrets_.erase(app_id);
181 } else {
177 DVLOG(1) << "Unable to delete a key from the GCM Key Store."; 182 DVLOG(1) << "Unable to delete a key from the GCM Key Store.";
178 callback.Run(false /* success */);
179 return;
180 } 183 }
181 184
182 key_pairs_.erase(app_id); 185 callback.Run();
183 auth_secrets_.erase(app_id);
184
185 callback.Run(true /* success */);
186 } 186 }
187 187
188 void GCMKeyStore::LazyInitialize(const base::Closure& done_closure) { 188 void GCMKeyStore::LazyInitialize(const base::Closure& done_closure) {
189 if (delayed_task_controller_.CanRunTaskWithoutDelay()) { 189 if (delayed_task_controller_.CanRunTaskWithoutDelay()) {
190 done_closure.Run(); 190 done_closure.Run();
191 return; 191 return;
192 } 192 }
193 193
194 delayed_task_controller_.AddTask(done_closure); 194 delayed_task_controller_.AddTask(done_closure);
195 if (state_ == State::INITIALIZING) 195 if (state_ == State::INITIALIZING)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 key_pairs_[entry.app_id()] = entry.keys(0); 234 key_pairs_[entry.app_id()] = entry.keys(0);
235 auth_secrets_[entry.app_id()] = entry.auth_secret(); 235 auth_secrets_[entry.app_id()] = entry.auth_secret();
236 } 236 }
237 237
238 state_ = State::INITIALIZED; 238 state_ = State::INITIALIZED;
239 239
240 delayed_task_controller_.SetReady(); 240 delayed_task_controller_.SetReady();
241 } 241 }
242 242
243 } // namespace gcm 243 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/crypto/gcm_key_store.h ('k') | components/gcm_driver/crypto/gcm_key_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698