| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 12 | |
| 13 namespace cryptohome { | |
| 14 | |
| 15 // This class manages calls to Cryptohome service's 'async' methods. | |
| 16 // Note: This class is placed in ::cryptohome instead of ::chromeos::cryptohome | |
| 17 // since there is already a namespace ::cryptohome which holds the error code | |
| 18 // enum (MountError) and referencing ::chromeos::cryptohome and ::cryptohome | |
| 19 // within the same code is confusing. | |
| 20 class AsyncMethodCaller { | |
| 21 public: | |
| 22 // A callback type which is called back on the UI thread when the results of | |
| 23 // method calls are ready. | |
| 24 typedef base::Callback<void(bool success, MountError return_code)> Callback; | |
| 25 | |
| 26 virtual ~AsyncMethodCaller() {} | |
| 27 | |
| 28 // Asks cryptohomed to asynchronously try to find the cryptohome for | |
| 29 // |user_email| and then use |passhash| to unlock the key. | |
| 30 // |callback| will be called with status info on completion. | |
| 31 virtual void AsyncCheckKey(const std::string& user_email, | |
| 32 const std::string& passhash, | |
| 33 Callback callback) = 0; | |
| 34 | |
| 35 // Asks cryptohomed to asynchronously try to find the cryptohome for | |
| 36 // |user_email| and then change from using |old_hash| to lock the | |
| 37 // key to using |new_hash|. | |
| 38 // |callback| will be called with status info on completion. | |
| 39 virtual void AsyncMigrateKey(const std::string& user_email, | |
| 40 const std::string& old_hash, | |
| 41 const std::string& new_hash, | |
| 42 Callback callback) = 0; | |
| 43 | |
| 44 // Asks cryptohomed to asynchronously try to find the cryptohome for | |
| 45 // |user_email| and then mount it using |passhash| to unlock the key. | |
| 46 // |create_if_missing| controls whether or not we ask cryptohomed to | |
| 47 // create a new home dir if one does not yet exist for |user_email|. | |
| 48 // |callback| will be called with status info on completion. | |
| 49 // If |create_if_missing| is false, and no cryptohome exists for |user_email|, | |
| 50 // we'll get | |
| 51 // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist). | |
| 52 // Otherwise, we expect the normal range of return codes. | |
| 53 virtual void AsyncMount(const std::string& user_email, | |
| 54 const std::string& passhash, | |
| 55 const bool create_if_missing, | |
| 56 Callback callback) = 0; | |
| 57 | |
| 58 // Asks cryptohomed to asynchronously to mount a tmpfs for guest mode. | |
| 59 // |callback| will be called with status info on completion. | |
| 60 virtual void AsyncMountGuest(Callback callback) = 0; | |
| 61 | |
| 62 // Asks cryptohomed to asynchronously try to find the cryptohome for | |
| 63 // |user_email| and then nuke it. | |
| 64 virtual void AsyncRemove(const std::string& user_email, | |
| 65 Callback callback) = 0; | |
| 66 | |
| 67 // Creates the global AsyncMethodCaller instance. | |
| 68 static void Initialize(); | |
| 69 | |
| 70 // Similar to Initialize(), but can inject an alternative | |
| 71 // AsyncMethodCaller such as MockAsyncMethodCaller for testing. | |
| 72 // The injected object will be owned by the internal pointer and deleted | |
| 73 // by Shutdown(). | |
| 74 static void InitializeForTesting(AsyncMethodCaller* async_method_caller); | |
| 75 | |
| 76 // Destroys the global AsyncMethodCaller instance if it exists. | |
| 77 static void Shutdown(); | |
| 78 | |
| 79 // Returns a pointer to the global AsyncMethodCaller instance. | |
| 80 // Initialize() should already have been called. | |
| 81 static AsyncMethodCaller* GetInstance(); | |
| 82 }; | |
| 83 | |
| 84 } // namespace cryptohome | |
| 85 | |
| 86 #endif // CHROME_BROWSER_CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | |
| OLD | NEW |