OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 LAZY_INSTANCE_INITIALIZER; | 23 LAZY_INSTANCE_INITIALIZER; |
24 | 24 |
25 // static | 25 // static |
26 OwnershipService* OwnershipService::GetSharedInstance() { | 26 OwnershipService* OwnershipService::GetSharedInstance() { |
27 return g_ownership_service.Pointer(); | 27 return g_ownership_service.Pointer(); |
28 } | 28 } |
29 | 29 |
30 OwnershipService::OwnershipService() | 30 OwnershipService::OwnershipService() |
31 : manager_(new OwnerManager), | 31 : manager_(new OwnerManager), |
32 utils_(OwnerKeyUtils::Create()), | 32 utils_(OwnerKeyUtils::Create()), |
33 policy_(NULL), | |
34 ownership_status_(OWNERSHIP_UNKNOWN) { | 33 ownership_status_(OWNERSHIP_UNKNOWN) { |
35 notification_registrar_.Add( | 34 notification_registrar_.Add( |
36 this, | 35 this, |
37 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 36 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
38 content::NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
39 } | 38 } |
40 | 39 |
41 OwnershipService::~OwnershipService() {} | 40 OwnershipService::~OwnershipService() {} |
42 | 41 |
43 void OwnershipService::Prewarm() { | 42 void OwnershipService::Prewarm() { |
44 // Note that we cannot prewarm in constructor because in current codebase | 43 // Note that we cannot prewarm in constructor because in current codebase |
45 // object is created before spawning threads. | 44 // object is created before spawning threads. |
46 if (g_ownership_service == this) { | 45 if (g_ownership_service == this) { |
47 // Start getting ownership status. | 46 // Start getting ownership status. |
48 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
49 BrowserThread::FILE, FROM_HERE, | 48 BrowserThread::FILE, FROM_HERE, |
50 base::Bind(&OwnershipService::FetchStatus, base::Unretained(this))); | 49 base::Bind(&OwnershipService::FetchStatus, base::Unretained(this))); |
51 } else { | 50 } else { |
52 // This can happen only for particular test: OwnershipServiceTest. It uses | 51 // This can happen only for particular test: OwnershipServiceTest. It uses |
53 // mocks and for that uses OwnershipService not as a regular singleton but | 52 // mocks and for that uses OwnershipService not as a regular singleton but |
54 // as a resurrecting object. This behaviour conflicts with | 53 // as a resurrecting object. This behaviour conflicts with |
55 // DISABLE_RUNNABLE_METHOD_REFCOUNT. So avoid posting task in those | 54 // DISABLE_RUNNABLE_METHOD_REFCOUNT. So avoid posting task in those |
56 // circumstances in order to avoid accessing already deleted object. | 55 // circumstances in order to avoid accessing already deleted object. |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 void OwnershipService::set_cached_policy(const em::PolicyData& pol) { | |
61 policy_.reset(pol.New()); | |
62 policy_->CheckTypeAndMergeFrom(pol); | |
63 } | |
64 | |
65 bool OwnershipService::has_cached_policy() { | |
66 return policy_.get(); | |
67 } | |
68 | |
69 const em::PolicyData& OwnershipService::cached_policy() { | |
70 return *(policy_.get()); | |
71 } | |
72 | |
73 bool OwnershipService::IsAlreadyOwned() { | 59 bool OwnershipService::IsAlreadyOwned() { |
74 return file_util::PathExists(utils_->GetOwnerKeyFilePath()); | 60 return file_util::PathExists(utils_->GetOwnerKeyFilePath()); |
75 } | 61 } |
76 | 62 |
77 OwnershipService::Status OwnershipService::GetStatus(bool blocking) { | 63 OwnershipService::Status OwnershipService::GetStatus(bool blocking) { |
78 Status status = OWNERSHIP_UNKNOWN; | 64 Status status = OWNERSHIP_UNKNOWN; |
79 bool is_owned = false; | 65 bool is_owned = false; |
80 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 66 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
81 ownership_status_lock_.Acquire(); | 67 ownership_status_lock_.Acquire(); |
82 status = ownership_status_; | 68 status = ownership_status_; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 SetStatus(status); | 206 SetStatus(status); |
221 } | 207 } |
222 | 208 |
223 void OwnershipService::SetStatus(Status new_status) { | 209 void OwnershipService::SetStatus(Status new_status) { |
224 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE); | 210 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE); |
225 base::AutoLock lk(ownership_status_lock_); | 211 base::AutoLock lk(ownership_status_lock_); |
226 ownership_status_ = new_status; | 212 ownership_status_ = new_status; |
227 } | 213 } |
228 | 214 |
229 } // namespace chromeos | 215 } // namespace chromeos |
OLD | NEW |