OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/settings/device_settings_service.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
14 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 13 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
15 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 14 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
16 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" | 15 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" |
17 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
30 // the battery is drained. | 29 // the battery is drained. |
31 int kLoadRetryDelayMs = 1000 * 5; | 30 int kLoadRetryDelayMs = 1000 * 5; |
32 // Maximal number of retries before we give up. Calculated to allow for 10 min | 31 // Maximal number of retries before we give up. Calculated to allow for 10 min |
33 // of retry time. | 32 // of retry time. |
34 int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs; | 33 int kMaxLoadRetries = (1000 * 60 * 10) / kLoadRetryDelayMs; |
35 | 34 |
36 } // namespace | 35 } // namespace |
37 | 36 |
38 namespace chromeos { | 37 namespace chromeos { |
39 | 38 |
40 static base::LazyInstance<DeviceSettingsService> g_device_settings_service = | |
41 LAZY_INSTANCE_INITIALIZER; | |
42 | |
43 OwnerKey::OwnerKey(scoped_ptr<std::vector<uint8> > public_key, | 39 OwnerKey::OwnerKey(scoped_ptr<std::vector<uint8> > public_key, |
44 scoped_ptr<crypto::RSAPrivateKey> private_key) | 40 scoped_ptr<crypto::RSAPrivateKey> private_key) |
45 : public_key_(public_key.Pass()), | 41 : public_key_(public_key.Pass()), |
46 private_key_(private_key.Pass()) {} | 42 private_key_(private_key.Pass()) {} |
47 | 43 |
48 OwnerKey::~OwnerKey() {} | 44 OwnerKey::~OwnerKey() {} |
49 | 45 |
50 DeviceSettingsService::Observer::~Observer() {} | 46 DeviceSettingsService::Observer::~Observer() {} |
51 | 47 |
52 DeviceSettingsService::DeviceSettingsService() | 48 static DeviceSettingsService* g_device_settings_service = NULL; |
Mattias Nissler (ping if slow)
2013/04/16 16:09:51
nit: spacing
stevenjb
2013/04/16 16:49:43
Done.
| |
53 : session_manager_client_(NULL), | |
54 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | |
55 store_status_(STORE_SUCCESS), | |
56 load_retries_left_(kMaxLoadRetries) {} | |
57 | 49 |
58 DeviceSettingsService::~DeviceSettingsService() { | 50 // static |
59 DCHECK(pending_operations_.empty()); | 51 void DeviceSettingsService::Initialize() { |
52 CHECK(!g_device_settings_service); | |
53 g_device_settings_service = new DeviceSettingsService(); | |
54 } | |
55 | |
56 // static | |
57 void DeviceSettingsService::Shutdown() { | |
58 CHECK(g_device_settings_service); | |
59 delete g_device_settings_service; | |
60 g_device_settings_service = NULL; | |
60 } | 61 } |
61 | 62 |
62 // static | 63 // static |
63 DeviceSettingsService* DeviceSettingsService::Get() { | 64 DeviceSettingsService* DeviceSettingsService::Get() { |
64 return g_device_settings_service.Pointer(); | 65 CHECK(g_device_settings_service); |
66 return g_device_settings_service; | |
65 } | 67 } |
66 | 68 |
67 void DeviceSettingsService::Initialize( | 69 void DeviceSettingsService::InitializeSessionManager( |
68 SessionManagerClient* session_manager_client, | 70 SessionManagerClient* session_manager_client, |
69 scoped_refptr<OwnerKeyUtil> owner_key_util) { | 71 scoped_refptr<OwnerKeyUtil> owner_key_util) { |
70 DCHECK(session_manager_client); | 72 DCHECK(session_manager_client); |
71 DCHECK(owner_key_util.get()); | 73 DCHECK(owner_key_util.get()); |
72 DCHECK(!session_manager_client_); | 74 DCHECK(!session_manager_client_); |
73 DCHECK(!owner_key_util_.get()); | 75 DCHECK(!owner_key_util_.get()); |
74 | 76 |
75 session_manager_client_ = session_manager_client; | 77 session_manager_client_ = session_manager_client; |
76 owner_key_util_ = owner_key_util; | 78 owner_key_util_ = owner_key_util; |
77 | 79 |
78 session_manager_client_->AddObserver(this); | 80 session_manager_client_->AddObserver(this); |
79 | 81 |
80 StartNextOperation(); | 82 StartNextOperation(); |
81 } | 83 } |
82 | 84 |
83 void DeviceSettingsService::Shutdown() { | 85 void DeviceSettingsService::ShutdownSessionManager() { |
84 STLDeleteContainerPointers(pending_operations_.begin(), | 86 STLDeleteContainerPointers(pending_operations_.begin(), |
85 pending_operations_.end()); | 87 pending_operations_.end()); |
86 pending_operations_.clear(); | 88 pending_operations_.clear(); |
87 | 89 |
88 if (session_manager_client_) | 90 if (session_manager_client_) |
89 session_manager_client_->RemoveObserver(this); | 91 session_manager_client_->RemoveObserver(this); |
90 session_manager_client_ = NULL; | 92 session_manager_client_ = NULL; |
91 owner_key_util_ = NULL; | 93 owner_key_util_ = NULL; |
92 } | 94 } |
93 | 95 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 186 |
185 void DeviceSettingsService::PropertyChangeComplete(bool success) { | 187 void DeviceSettingsService::PropertyChangeComplete(bool success) { |
186 if (!success) { | 188 if (!success) { |
187 LOG(ERROR) << "Policy update failed."; | 189 LOG(ERROR) << "Policy update failed."; |
188 return; | 190 return; |
189 } | 191 } |
190 | 192 |
191 EnsureReload(false); | 193 EnsureReload(false); |
192 } | 194 } |
193 | 195 |
196 DeviceSettingsService::DeviceSettingsService() | |
197 : session_manager_client_(NULL), | |
198 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | |
199 store_status_(STORE_SUCCESS), | |
200 load_retries_left_(kMaxLoadRetries) { | |
201 } | |
202 | |
203 DeviceSettingsService::~DeviceSettingsService() { | |
204 DCHECK(pending_operations_.empty()); | |
205 } | |
206 | |
194 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { | 207 void DeviceSettingsService::Enqueue(SessionManagerOperation* operation) { |
195 pending_operations_.push_back(operation); | 208 pending_operations_.push_back(operation); |
196 if (pending_operations_.front() == operation) | 209 if (pending_operations_.front() == operation) |
197 StartNextOperation(); | 210 StartNextOperation(); |
198 } | 211 } |
199 | 212 |
200 void DeviceSettingsService::EnqueueLoad(bool force_key_load) { | 213 void DeviceSettingsService::EnqueueLoad(bool force_key_load) { |
201 SessionManagerOperation* operation = | 214 SessionManagerOperation* operation = |
202 new LoadSettingsOperation( | 215 new LoadSettingsOperation( |
203 base::Bind(&DeviceSettingsService::HandleCompletedOperation, | 216 base::Bind(&DeviceSettingsService::HandleCompletedOperation, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 | 305 |
293 // Only remove the pending operation here, so new operations triggered by any | 306 // Only remove the pending operation here, so new operations triggered by any |
294 // of the callbacks above are queued up properly. | 307 // of the callbacks above are queued up properly. |
295 pending_operations_.pop_front(); | 308 pending_operations_.pop_front(); |
296 delete operation; | 309 delete operation; |
297 | 310 |
298 StartNextOperation(); | 311 StartNextOperation(); |
299 } | 312 } |
300 | 313 |
301 } // namespace chromeos | 314 } // namespace chromeos |
OLD | NEW |