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

Side by Side Diff: chromeos/cryptohome/async_method_caller.cc

Issue 880303003: Cryptohome: Notify about error in async calls if cryptohome is not ready yet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 (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 "chromeos/cryptohome/async_method_caller.h" 5 #include "chromeos/cryptohome/async_method_caller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 const std::string& return_data) { 301 const std::string& return_data) {
302 const DataCallbackMap::iterator it = data_callback_map_.find(async_id); 302 const DataCallbackMap::iterator it = data_callback_map_.find(async_id);
303 if (it == data_callback_map_.end()) { 303 if (it == data_callback_map_.end()) {
304 LOG(ERROR) << "Received signal for unknown async_id " << async_id; 304 LOG(ERROR) << "Received signal for unknown async_id " << async_id;
305 return; 305 return;
306 } 306 }
307 it->second.proxy->PostTask(FROM_HERE, 307 it->second.proxy->PostTask(FROM_HERE,
308 base::Bind(it->second.data_callback, return_status, return_data)); 308 base::Bind(it->second.data_callback, return_status, return_data));
309 data_callback_map_.erase(it); 309 data_callback_map_.erase(it);
310 } 310 }
311
312 // Registers a callback which is called when the result for AsyncXXX is ready. 311 // Registers a callback which is called when the result for AsyncXXX is ready.
313 void RegisterAsyncCallback( 312 void RegisterAsyncCallback(
314 Callback callback, const char* error, int async_id) { 313 Callback callback, const char* error, int async_id) {
314 if (async_id == chromeos::kCryptohomeNotReadyAsyncId) {
315 base::MessageLoopProxy::current()->PostTask(
316 FROM_HERE, base::Bind(callback,
317 false, // return status
318 cryptohome::MOUNT_ERROR_FATAL));
319 return;
320 }
321
315 if (async_id == 0) { 322 if (async_id == 0) {
316 LOG(ERROR) << error; 323 LOG(ERROR) << error;
317 return; 324 return;
318 } 325 }
319 VLOG(1) << "Adding handler for " << async_id; 326 VLOG(1) << "Adding handler for " << async_id;
320 DCHECK_EQ(callback_map_.count(async_id), 0U); 327 DCHECK_EQ(callback_map_.count(async_id), 0U);
321 DCHECK_EQ(data_callback_map_.count(async_id), 0U); 328 DCHECK_EQ(data_callback_map_.count(async_id), 0U);
322 callback_map_[async_id] = CallbackElement(callback); 329 callback_map_[async_id] = CallbackElement(callback);
323 } 330 }
324 331
325 // Registers a callback which is called when the result for AsyncXXX is ready. 332 // Registers a callback which is called when the result for AsyncXXX is ready.
326 void RegisterAsyncDataCallback( 333 void RegisterAsyncDataCallback(
327 DataCallback callback, const char* error, int async_id) { 334 DataCallback callback, const char* error, int async_id) {
335 if (async_id == chromeos::kCryptohomeNotReadyAsyncId) {
336 base::MessageLoopProxy::current()->PostTask(
337 FROM_HERE, base::Bind(callback,
338 false, // return status
339 std::string()));
Daniel Erat 2015/01/28 18:01:46 nit: is there a reason for not using MOUNT_ERROR_F
Denis Kuznetsov (DE-MUC) 2015/01/28 19:45:26 This callback expects std::string() instead of enu
340 return;
341 }
328 if (async_id == 0) { 342 if (async_id == 0) {
329 LOG(ERROR) << error; 343 LOG(ERROR) << error;
330 return; 344 return;
331 } 345 }
332 VLOG(1) << "Adding handler for " << async_id; 346 VLOG(1) << "Adding handler for " << async_id;
333 DCHECK_EQ(callback_map_.count(async_id), 0U); 347 DCHECK_EQ(callback_map_.count(async_id), 0U);
334 DCHECK_EQ(data_callback_map_.count(async_id), 0U); 348 DCHECK_EQ(data_callback_map_.count(async_id), 0U);
335 data_callback_map_[async_id] = DataCallbackElement(callback); 349 data_callback_map_[async_id] = DataCallbackElement(callback);
336 } 350 }
337 351
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 g_async_method_caller = NULL; 389 g_async_method_caller = NULL;
376 VLOG(1) << "AsyncMethodCaller Shutdown completed"; 390 VLOG(1) << "AsyncMethodCaller Shutdown completed";
377 } 391 }
378 392
379 // static 393 // static
380 AsyncMethodCaller* AsyncMethodCaller::GetInstance() { 394 AsyncMethodCaller* AsyncMethodCaller::GetInstance() {
381 return g_async_method_caller; 395 return g_async_method_caller;
382 } 396 }
383 397
384 } // namespace cryptohome 398 } // namespace cryptohome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698