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

Side by Side Diff: chrome/browser/chromeos/login/ownership_service.cc

Issue 8899002: [cros] Add --stub-cros-settings option for testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years 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 | Annotate | Revision Log
OLDNEW
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/command_line.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
9 #include "base/file_path.h" 10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
17 19
18 using content::BrowserThread; 20 using content::BrowserThread;
19 21
20 namespace chromeos { 22 namespace chromeos {
21 23
22 static base::LazyInstance<OwnershipService> g_ownership_service = 24 static base::LazyInstance<OwnershipService> g_ownership_service =
23 LAZY_INSTANCE_INITIALIZER; 25 LAZY_INSTANCE_INITIALIZER;
24 26
25 // static 27 // static
26 OwnershipService* OwnershipService::GetSharedInstance() { 28 OwnershipService* OwnershipService::GetSharedInstance() {
27 return g_ownership_service.Pointer(); 29 return g_ownership_service.Pointer();
28 } 30 }
29 31
30 OwnershipService::OwnershipService() 32 OwnershipService::OwnershipService()
31 : manager_(new OwnerManager), 33 : manager_(new OwnerManager),
32 utils_(OwnerKeyUtils::Create()), 34 utils_(OwnerKeyUtils::Create()),
33 ownership_status_(OWNERSHIP_UNKNOWN) { 35 ownership_status_(OWNERSHIP_UNKNOWN),
36 force_ownership_(CommandLine::ForCurrentProcess()->HasSwitch(
37 switches::kStubCrosSettings)) {
34 notification_registrar_.Add( 38 notification_registrar_.Add(
35 this, 39 this,
36 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 40 chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
37 content::NotificationService::AllSources()); 41 content::NotificationService::AllSources());
38 } 42 }
39 43
40 OwnershipService::~OwnershipService() {} 44 OwnershipService::~OwnershipService() {}
41 45
42 void OwnershipService::Prewarm() { 46 void OwnershipService::Prewarm() {
43 // Note that we cannot prewarm in constructor because in current codebase 47 // Note that we cannot prewarm in constructor because in current codebase
(...skipping 10 matching lines...) Expand all
54 // DISABLE_RUNNABLE_METHOD_REFCOUNT. So avoid posting task in those 58 // DISABLE_RUNNABLE_METHOD_REFCOUNT. So avoid posting task in those
55 // circumstances in order to avoid accessing already deleted object. 59 // circumstances in order to avoid accessing already deleted object.
56 } 60 }
57 } 61 }
58 62
59 bool OwnershipService::IsAlreadyOwned() { 63 bool OwnershipService::IsAlreadyOwned() {
60 return file_util::PathExists(utils_->GetOwnerKeyFilePath()); 64 return file_util::PathExists(utils_->GetOwnerKeyFilePath());
61 } 65 }
62 66
63 OwnershipService::Status OwnershipService::GetStatus(bool blocking) { 67 OwnershipService::Status OwnershipService::GetStatus(bool blocking) {
68 if (force_ownership_)
69 return OWNERSHIP_TAKEN;
64 Status status = OWNERSHIP_UNKNOWN; 70 Status status = OWNERSHIP_UNKNOWN;
65 bool is_owned = false; 71 bool is_owned = false;
66 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 72 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
67 ownership_status_lock_.Acquire(); 73 ownership_status_lock_.Acquire();
68 status = ownership_status_; 74 status = ownership_status_;
69 ownership_status_lock_.Release(); 75 ownership_status_lock_.Release();
70 if (status != OWNERSHIP_UNKNOWN || !blocking) 76 if (status != OWNERSHIP_UNKNOWN || !blocking)
71 return status; 77 return status;
72 // Under common usage there is very short lapse of time when ownership 78 // Under common usage there is very short lapse of time when ownership
73 // status is still unknown after constructing OwnershipService. 79 // status is still unknown after constructing OwnershipService.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const content::NotificationDetails& details) { 137 const content::NotificationDetails& details) {
132 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { 138 if (type == chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) {
133 SetStatus(OWNERSHIP_TAKEN); 139 SetStatus(OWNERSHIP_TAKEN);
134 notification_registrar_.RemoveAll(); 140 notification_registrar_.RemoveAll();
135 } else { 141 } else {
136 NOTREACHED(); 142 NOTREACHED();
137 } 143 }
138 } 144 }
139 145
140 bool OwnershipService::CurrentUserIsOwner() { 146 bool OwnershipService::CurrentUserIsOwner() {
147 if (force_ownership_)
148 return true;
141 // If this user has the private key associated with the owner's 149 // If this user has the private key associated with the owner's
142 // public key, this user is the owner. 150 // public key, this user is the owner.
143 return IsAlreadyOwned() && manager_->EnsurePrivateKey(); 151 return IsAlreadyOwned() && manager_->EnsurePrivateKey();
144 } 152 }
145 153
146 // static 154 // static
147 void OwnershipService::UpdateOwnerKey(OwnershipService* service, 155 void OwnershipService::UpdateOwnerKey(OwnershipService* service,
148 const BrowserThread::ID thread_id, 156 const BrowserThread::ID thread_id,
149 const std::vector<uint8>& new_key, 157 const std::vector<uint8>& new_key,
150 OwnerManager::KeyUpdateDelegate* d) { 158 OwnerManager::KeyUpdateDelegate* d) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 SetStatus(status); 214 SetStatus(status);
207 } 215 }
208 216
209 void OwnershipService::SetStatus(Status new_status) { 217 void OwnershipService::SetStatus(Status new_status) {
210 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE); 218 DCHECK(new_status == OWNERSHIP_TAKEN || new_status == OWNERSHIP_NONE);
211 base::AutoLock lk(ownership_status_lock_); 219 base::AutoLock lk(ownership_status_lock_);
212 ownership_status_ = new_status; 220 ownership_status_ = new_status;
213 } 221 }
214 222
215 } // namespace chromeos 223 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/ownership_service.h ('k') | chrome/browser/chromeos/stub_cros_settings_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698