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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_service.cc

Issue 14200028: Make CrosSettings and DeviceSettingsService non Lazy instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months 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) 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
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
48 static DeviceSettingsService* g_device_settings_service = NULL;
49
50 // static
51 void DeviceSettingsService::Initialize() {
52 CHECK(!g_device_settings_service);
53 g_device_settings_service = new DeviceSettingsService();
54 }
55
56 // static
57 bool DeviceSettingsService::IsInitialized() {
58 return g_device_settings_service;
59 }
60
61 // static
62 void DeviceSettingsService::Shutdown() {
63 CHECK(g_device_settings_service);
64 delete g_device_settings_service;
65 g_device_settings_service = NULL;
66 }
67
68 // static
69 DeviceSettingsService* DeviceSettingsService::Get() {
70 CHECK(g_device_settings_service);
71 return g_device_settings_service;
72 }
73
52 DeviceSettingsService::DeviceSettingsService() 74 DeviceSettingsService::DeviceSettingsService()
53 : session_manager_client_(NULL), 75 : session_manager_client_(NULL),
54 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 76 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
55 store_status_(STORE_SUCCESS), 77 store_status_(STORE_SUCCESS),
56 load_retries_left_(kMaxLoadRetries) {} 78 load_retries_left_(kMaxLoadRetries) {
79 }
57 80
58 DeviceSettingsService::~DeviceSettingsService() { 81 DeviceSettingsService::~DeviceSettingsService() {
59 DCHECK(pending_operations_.empty()); 82 DCHECK(pending_operations_.empty());
60 } 83 }
61 84
62 // static 85 void DeviceSettingsService::SetSessionManager(
63 DeviceSettingsService* DeviceSettingsService::Get() {
64 return g_device_settings_service.Pointer();
65 }
66
67 void DeviceSettingsService::Initialize(
68 SessionManagerClient* session_manager_client, 86 SessionManagerClient* session_manager_client,
69 scoped_refptr<OwnerKeyUtil> owner_key_util) { 87 scoped_refptr<OwnerKeyUtil> owner_key_util) {
70 DCHECK(session_manager_client); 88 DCHECK(session_manager_client);
71 DCHECK(owner_key_util.get()); 89 DCHECK(owner_key_util.get());
72 DCHECK(!session_manager_client_); 90 DCHECK(!session_manager_client_);
73 DCHECK(!owner_key_util_.get()); 91 DCHECK(!owner_key_util_.get());
74 92
75 session_manager_client_ = session_manager_client; 93 session_manager_client_ = session_manager_client;
76 owner_key_util_ = owner_key_util; 94 owner_key_util_ = owner_key_util;
77 95
78 session_manager_client_->AddObserver(this); 96 session_manager_client_->AddObserver(this);
79 97
80 StartNextOperation(); 98 StartNextOperation();
81 } 99 }
82 100
83 void DeviceSettingsService::Shutdown() { 101 void DeviceSettingsService::UnsetSessionManager() {
84 STLDeleteContainerPointers(pending_operations_.begin(), 102 STLDeleteContainerPointers(pending_operations_.begin(),
85 pending_operations_.end()); 103 pending_operations_.end());
86 pending_operations_.clear(); 104 pending_operations_.clear();
87 105
88 if (session_manager_client_) 106 if (session_manager_client_)
89 session_manager_client_->RemoveObserver(this); 107 session_manager_client_->RemoveObserver(this);
90 session_manager_client_ = NULL; 108 session_manager_client_ = NULL;
91 owner_key_util_ = NULL; 109 owner_key_util_ = NULL;
92 } 110 }
93 111
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 310
293 // Only remove the pending operation here, so new operations triggered by any 311 // Only remove the pending operation here, so new operations triggered by any
294 // of the callbacks above are queued up properly. 312 // of the callbacks above are queued up properly.
295 pending_operations_.pop_front(); 313 pending_operations_.pop_front();
296 delete operation; 314 delete operation;
297 315
298 StartNextOperation(); 316 StartNextOperation();
299 } 317 }
300 318
301 } // namespace chromeos 319 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698