| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/login/ownership_service.h" | 5 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 OwnershipService* OwnershipService::GetSharedInstance() { | 24 OwnershipService* OwnershipService::GetSharedInstance() { |
| 25 return g_ownership_service.Pointer(); | 25 return g_ownership_service.Pointer(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 OwnershipService::OwnershipService() | 28 OwnershipService::OwnershipService() |
| 29 : manager_(new OwnerManager), | 29 : manager_(new OwnerManager), |
| 30 utils_(OwnerKeyUtils::Create()), | 30 utils_(OwnerKeyUtils::Create()), |
| 31 ownership_status_(OWNERSHIP_UNKNOWN) { | 31 ownership_status_(OWNERSHIP_UNKNOWN) { |
| 32 notification_registrar_.Add(this, | 32 notification_registrar_.Add( |
| 33 NotificationType::OWNERSHIP_TAKEN, | 33 this, |
| 34 NotificationService::AllSources()); | 34 NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
| 35 NotificationService::AllSources()); |
| 35 if (g_ownership_service == this) { | 36 if (g_ownership_service == this) { |
| 36 // Start getting ownership status. | 37 // Start getting ownership status. |
| 37 BrowserThread::PostTask( | 38 BrowserThread::PostTask( |
| 38 BrowserThread::FILE, | 39 BrowserThread::FILE, |
| 39 FROM_HERE, | 40 FROM_HERE, |
| 40 NewRunnableMethod(this, &OwnershipService::FetchStatus)); | 41 NewRunnableMethod(this, &OwnershipService::FetchStatus)); |
| 41 } else { | 42 } else { |
| 42 // This can happen only for particular test: OwnershipServiceTest. It uses | 43 // This can happen only for particular test: OwnershipServiceTest. It uses |
| 43 // mocks and for that uses OwnershipService not as a regular singleton but | 44 // mocks and for that uses OwnershipService not as a regular singleton but |
| 44 // as a resurrecting object. This behaviour conflicts with | 45 // as a resurrecting object. This behaviour conflicts with |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 thread_id, | 111 thread_id, |
| 111 data, | 112 data, |
| 112 signature, | 113 signature, |
| 113 d)); | 114 d)); |
| 114 return; | 115 return; |
| 115 } | 116 } |
| 116 | 117 |
| 117 void OwnershipService::Observe(NotificationType type, | 118 void OwnershipService::Observe(NotificationType type, |
| 118 const NotificationSource& source, | 119 const NotificationSource& source, |
| 119 const NotificationDetails& details) { | 120 const NotificationDetails& details) { |
| 120 if (type.value == NotificationType::OWNERSHIP_TAKEN) { | 121 if (type.value == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
| 121 SetStatus(OWNERSHIP_TAKEN); | 122 SetStatus(OWNERSHIP_TAKEN); |
| 122 notification_registrar_.RemoveAll(); | 123 notification_registrar_.RemoveAll(); |
| 123 } else { | 124 } else { |
| 124 NOTREACHED(); | 125 NOTREACHED(); |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 bool OwnershipService::CurrentUserIsOwner() { | 129 bool OwnershipService::CurrentUserIsOwner() { |
| 129 // If this user has the private key associated with the owner's | 130 // If this user has the private key associated with the owner's |
| 130 // public key, this user is the owner. | 131 // public key, this user is the owner. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 187 } |
| 187 | 188 |
| 188 void OwnershipService::SetStatus(Status new_status) { | 189 void OwnershipService::SetStatus(Status new_status) { |
| 189 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE); | 190 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE); |
| 190 base::AutoLock lk(ownership_status_lock_); | 191 base::AutoLock lk(ownership_status_lock_); |
| 191 ownership_status_ = new_status; | 192 ownership_status_ = new_status; |
| 192 } | 193 } |
| 193 | 194 |
| 194 } // namespace chromeos | 195 } // namespace chromeos |
| 195 | 196 |
| OLD | NEW |