OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/notification_type.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 // static |
| 16 OwnershipService* OwnershipService::GetSharedInstance() { |
| 17 return Singleton<OwnershipService>::get(); |
| 18 } |
| 19 |
| 20 OwnershipService::OwnershipService() |
| 21 : manager_(new OwnerManager), |
| 22 utils_(OwnerKeyUtils::Create()) { |
| 23 } |
| 24 |
| 25 OwnershipService::~OwnershipService() {} |
| 26 |
| 27 |
| 28 bool OwnershipService::IsAlreadyOwned() { |
| 29 return file_util::PathExists(utils_->GetOwnerKeyFilePath()); |
| 30 } |
| 31 |
| 32 bool OwnershipService::StartLoadOwnerKeyAttempt() { |
| 33 if (!IsAlreadyOwned()) { |
| 34 LOG(ERROR) << "Device not yet owned"; |
| 35 return false; |
| 36 } |
| 37 ChromeThread::PostTask( |
| 38 ChromeThread::FILE, FROM_HERE, |
| 39 NewRunnableMethod(manager_.get(), &OwnerManager::LoadOwnerKey)); |
| 40 return true; |
| 41 } |
| 42 |
| 43 bool OwnershipService::StartTakeOwnershipAttempt() { |
| 44 if (IsAlreadyOwned()) { |
| 45 LOG(ERROR) << "Device is already owned"; |
| 46 return false; |
| 47 } |
| 48 ChromeThread::PostTask( |
| 49 ChromeThread::FILE, FROM_HERE, |
| 50 NewRunnableMethod(manager_.get(), |
| 51 &OwnerManager::GenerateKeysAndExportPublic)); |
| 52 return true; |
| 53 } |
| 54 |
| 55 bool OwnershipService::StartSigningAttempt(const std::string& data, |
| 56 OwnerManager::Delegate* d) { |
| 57 if (!IsAlreadyOwned()) { |
| 58 LOG(ERROR) << "Device not yet owned"; |
| 59 return false; |
| 60 } |
| 61 ChromeThread::ID thread_id; |
| 62 if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id)) |
| 63 thread_id = ChromeThread::UI; |
| 64 ChromeThread::PostTask( |
| 65 ChromeThread::FILE, FROM_HERE, |
| 66 NewRunnableMethod(manager_.get(), |
| 67 &OwnerManager::Sign, |
| 68 thread_id, |
| 69 data, d)); |
| 70 return true; |
| 71 } |
| 72 |
| 73 bool OwnershipService::StartVerifyAttempt(const std::string& data, |
| 74 const std::string& signature, |
| 75 OwnerManager::Delegate* d) { |
| 76 if (!IsAlreadyOwned()) { |
| 77 LOG(ERROR) << "Device not yet owned"; |
| 78 return false; |
| 79 } |
| 80 ChromeThread::ID thread_id; |
| 81 if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id)) |
| 82 thread_id = ChromeThread::UI; |
| 83 ChromeThread::PostTask( |
| 84 ChromeThread::FILE, FROM_HERE, |
| 85 NewRunnableMethod(manager_.get(), |
| 86 &OwnerManager::Verify, |
| 87 thread_id, |
| 88 data, |
| 89 signature, |
| 90 d)); |
| 91 return true; |
| 92 } |
| 93 |
| 94 } // namespace chromeos |
OLD | NEW |