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

Side by Side Diff: components/os_crypt/os_crypt_linux.cc

Issue 2262693002: Initialize OSCrypt with a TaskRunner on the main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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
« no previous file with comments | « components/os_crypt/os_crypt.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/os_crypt/os_crypt.h" 5 #include "components/os_crypt/os_crypt.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 219 }
220 220
221 // static 221 // static
222 void OSCrypt::SetProductName(const std::string& product_name) { 222 void OSCrypt::SetProductName(const std::string& product_name) {
223 // Setting the product name makes no sense after initializing. 223 // Setting the product name makes no sense after initializing.
224 DCHECK(!g_cache.Get().is_key_storage_cached); 224 DCHECK(!g_cache.Get().is_key_storage_cached);
225 225
226 KeyStorageLinux::SetProductName(product_name); 226 KeyStorageLinux::SetProductName(product_name);
227 } 227 }
228 228
229 // static
230 void OSCrypt::SetMainThreadRunner(
231 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner) {
232 // Setting the task runner makes no sense after initializing.
233 DCHECK(!g_cache.Get().is_key_storage_cached);
234
235 KeyStorageLinux::SetMainThreadRunner(main_thread_runner);
236 }
237
229 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(), 238 void UseMockKeyStorageForTesting(KeyStorageLinux* (*get_key_storage_mock)(),
230 std::string* (*get_password_v11_mock)()) { 239 std::string* (*get_password_v11_mock)()) {
231 // Save the real implementation to restore it later. 240 // Save the real implementation to restore it later.
232 static bool is_get_password_saved = false; 241 static bool is_get_password_saved = false;
233 static std::string* (*get_password_save[arraysize(g_get_password)])(); 242 static std::string* (*get_password_save[arraysize(g_get_password)])();
234 if (!is_get_password_saved) { 243 if (!is_get_password_saved) {
235 std::copy(std::begin(g_get_password), std::end(g_get_password), 244 std::copy(std::begin(g_get_password), std::end(g_get_password),
236 std::begin(get_password_save)); 245 std::begin(get_password_save));
237 is_get_password_saved = true; 246 is_get_password_saved = true;
238 } 247 }
239 248
240 if (get_key_storage_mock && get_password_v11_mock) { 249 if (get_key_storage_mock && get_password_v11_mock) {
241 // Bypass calling KeyStorage::CreateService and caching of the key for V11 250 // Bypass calling KeyStorage::CreateService and caching of the key for V11
242 g_get_password[Version::V11] = get_password_v11_mock; 251 g_get_password[Version::V11] = get_password_v11_mock;
243 // OSCrypt will determine the encryption version by checking if a 252 // OSCrypt will determine the encryption version by checking if a
244 // |KeyStorage| instance can be created. Enable V11 by returning the mock. 253 // |KeyStorage| instance can be created. Enable V11 by returning the mock.
245 g_key_storage_provider = get_key_storage_mock; 254 g_key_storage_provider = get_key_storage_mock;
246 } else { 255 } else {
247 // Restore real implementation 256 // Restore real implementation
248 std::copy(std::begin(get_password_save), std::end(get_password_save), 257 std::copy(std::begin(get_password_save), std::end(get_password_save),
249 std::begin(g_get_password)); 258 std::begin(g_get_password));
250 } 259 }
251 } 260 }
OLDNEW
« no previous file with comments | « components/os_crypt/os_crypt.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698