OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/policy/consumer_management_service.h" | 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/browser_process_platform_part.h" | 17 #include "chrome/browser/browser_process_platform_part.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
23 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
23 #include "chrome/browser/notifications/notification.h" | 24 #include "chrome/browser/notifications/notification.h" |
24 #include "chrome/browser/notifications/notification_ui_manager.h" | 25 #include "chrome/browser/notifications/notification_ui_manager.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
27 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
28 #include "chrome/browser/ui/browser_navigator.h" | 29 #include "chrome/browser/ui/browser_navigator.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 32 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
32 #include "chromeos/dbus/cryptohome_client.h" | 33 #include "chromeos/dbus/cryptohome_client.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
60 const char* kEnrollmentNotificationUrl = "chrome://consumer-management/enroll"; | 61 const char* kEnrollmentNotificationUrl = "chrome://consumer-management/enroll"; |
61 | 62 |
62 // URL | 63 // URL |
63 const char* kConsumerManagementOverlay = "/consumer-management-overlay"; | 64 const char* kConsumerManagementOverlay = "/consumer-management-overlay"; |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 namespace policy { | 68 namespace policy { |
68 | 69 |
69 ConsumerManagementService::ConsumerManagementService( | 70 ConsumerManagementService::ConsumerManagementService( |
70 chromeos::CryptohomeClient* client) | 71 chromeos::CryptohomeClient* client, |
72 chromeos::DeviceSettingsService* device_settings_service) | |
71 : Consumer("consumer_management_service"), | 73 : Consumer("consumer_management_service"), |
72 client_(client), | 74 client_(client), |
75 device_settings_service_(device_settings_service), | |
73 enrolling_token_service_(NULL), | 76 enrolling_token_service_(NULL), |
74 is_observing_token_service_(false), | 77 is_observing_token_service_(false), |
75 weak_ptr_factory_(this) { | 78 weak_ptr_factory_(this) { |
76 registrar_.Add(this, | 79 registrar_.Add(this, |
77 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 80 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
78 content::NotificationService::AllSources()); | 81 content::NotificationService::AllSources()); |
79 } | 82 } |
80 | 83 |
81 ConsumerManagementService::~ConsumerManagementService() { | 84 ConsumerManagementService::~ConsumerManagementService() { |
82 registrar_.Remove(this, | 85 registrar_.Remove(this, |
83 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 86 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
84 content::NotificationService::AllSources()); | 87 content::NotificationService::AllSources()); |
85 if (is_observing_token_service_) { | 88 if (is_observing_token_service_) { |
86 enrolling_token_service_->RemoveObserver(this); | 89 enrolling_token_service_->RemoveObserver(this); |
87 is_observing_token_service_ = false; | 90 is_observing_token_service_ = false; |
88 } | 91 } |
89 } | 92 } |
90 | 93 |
91 // static | 94 // static |
92 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { | 95 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { |
93 registry->RegisterIntegerPref( | 96 registry->RegisterIntegerPref( |
94 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); | 97 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); |
95 } | 98 } |
96 | 99 |
100 void ConsumerManagementService::AddObserver(Observer* observer) { | |
101 observers_.AddObserver(observer); | |
102 } | |
103 | |
104 void ConsumerManagementService::RemoveObserver(Observer* observer) { | |
105 observers_.RemoveObserver(observer); | |
106 } | |
107 | |
97 ConsumerManagementService::ConsumerEnrollmentState | 108 ConsumerManagementService::ConsumerEnrollmentState |
98 ConsumerManagementService::GetEnrollmentState() const { | 109 ConsumerManagementService::GetEnrollmentState() const { |
99 const PrefService* prefs = g_browser_process->local_state(); | 110 const PrefService* prefs = g_browser_process->local_state(); |
100 int state = prefs->GetInteger(prefs::kConsumerManagementEnrollmentState); | 111 int state = prefs->GetInteger(prefs::kConsumerManagementEnrollmentState); |
101 if (state < 0 || state >= ENROLLMENT_LAST) { | 112 if (state < 0 || state >= ENROLLMENT_LAST) { |
102 LOG(ERROR) << "Unknown enrollment state: " << state; | 113 LOG(ERROR) << "Unknown enrollment state: " << state; |
103 state = 0; | 114 state = 0; |
104 } | 115 } |
105 return static_cast<ConsumerEnrollmentState>(state); | 116 return static_cast<ConsumerEnrollmentState>(state); |
106 } | 117 } |
107 | 118 |
108 void ConsumerManagementService::SetEnrollmentState( | 119 void ConsumerManagementService::SetEnrollmentState( |
109 ConsumerEnrollmentState state) { | 120 ConsumerEnrollmentState state) { |
110 PrefService* prefs = g_browser_process->local_state(); | 121 PrefService* prefs = g_browser_process->local_state(); |
111 prefs->SetInteger(prefs::kConsumerManagementEnrollmentState, state); | 122 prefs->SetInteger(prefs::kConsumerManagementEnrollmentState, state); |
123 | |
124 NotifyEnrollmentStateChanged(); | |
bartfab (slow)
2014/08/20 14:40:02
Nit: Since this is the only caller of NotifyEnroll
davidyu
2014/08/21 09:40:29
Done.
| |
112 } | 125 } |
113 | 126 |
114 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { | 127 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { |
115 cryptohome::GetBootAttributeRequest request; | 128 cryptohome::GetBootAttributeRequest request; |
116 request.set_name(kAttributeOwnerId); | 129 request.set_name(kAttributeOwnerId); |
117 client_->GetBootAttribute( | 130 client_->GetBootAttribute( |
118 request, | 131 request, |
119 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, | 132 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, |
120 weak_ptr_factory_.GetWeakPtr(), | 133 weak_ptr_factory_.GetWeakPtr(), |
121 callback)); | 134 callback)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 const cryptohome::BaseReply& reply) { | 187 const cryptohome::BaseReply& reply) { |
175 if (!dbus_success || reply.error() != 0) { | 188 if (!dbus_success || reply.error() != 0) { |
176 LOG(ERROR) << "Failed to flush and sign boot lockbox."; | 189 LOG(ERROR) << "Failed to flush and sign boot lockbox."; |
177 callback.Run(false); | 190 callback.Run(false); |
178 return; | 191 return; |
179 } | 192 } |
180 | 193 |
181 callback.Run(true); | 194 callback.Run(true); |
182 } | 195 } |
183 | 196 |
197 bool ConsumerManagementService::IsEnrolled() const { | |
198 const enterprise_management::PolicyData* policy_data = | |
199 device_settings_service_->policy_data(); | |
200 return policy_data && policy_data->management_mode() == | |
bartfab (slow)
2014/08/20 14:40:02
What if policy data has not been retrieved yet? Th
davidyu
2014/08/21 09:40:29
Added a unknown state which is returned when polic
| |
201 enterprise_management::PolicyData::CONSUMER_MANAGED; | |
202 } | |
203 | |
204 bool ConsumerManagementService::IsEnrolling() const { | |
205 ConsumerEnrollmentState state = GetEnrollmentState(); | |
206 return state > ENROLLMENT_NONE && state < ENROLLMENT_SUCCESS; | |
207 } | |
208 | |
209 bool ConsumerManagementService::IsUnenrolling() const { | |
210 // TODO(davidyu): Implement this. | |
bartfab (slow)
2014/08/20 14:40:02
Nit: Can you add a bug number?
davidyu
2014/08/21 09:40:29
Done.
| |
211 return false; | |
212 } | |
213 | |
184 void ConsumerManagementService::Observe( | 214 void ConsumerManagementService::Observe( |
185 int type, | 215 int type, |
186 const content::NotificationSource& source, | 216 const content::NotificationSource& source, |
187 const content::NotificationDetails& details) { | 217 const content::NotificationDetails& details) { |
188 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { | 218 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { |
189 NOTREACHED() << "Unexpected notification " << type; | 219 NOTREACHED() << "Unexpected notification " << type; |
190 return; | 220 return; |
191 } | 221 } |
192 | 222 |
193 Profile* profile = content::Details<Profile>(details).ptr(); | 223 Profile* profile = content::Details<Profile>(details).ptr(); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 message_center::NotifierId::SYSTEM_COMPONENT, id), | 445 message_center::NotifierId::SYSTEM_COMPONENT, id), |
416 base::string16(), // display_source | 446 base::string16(), // display_source |
417 base::UTF8ToUTF16(id), | 447 base::UTF8ToUTF16(id), |
418 optional_field, | 448 optional_field, |
419 new DesktopNotificationDelegate(id, button_click_callback))); | 449 new DesktopNotificationDelegate(id, button_click_callback))); |
420 notification->SetSystemPriority(); | 450 notification->SetSystemPriority(); |
421 | 451 |
422 g_browser_process->notification_ui_manager()->Add(*notification, profile); | 452 g_browser_process->notification_ui_manager()->Add(*notification, profile); |
423 } | 453 } |
424 | 454 |
455 void ConsumerManagementService::NotifyEnrollmentStateChanged() { | |
456 FOR_EACH_OBSERVER(Observer, | |
457 observers_, | |
458 OnConsumerManagementEnrollmentStateChanged(this)); | |
459 } | |
460 | |
425 ConsumerManagementService::DesktopNotificationDelegate:: | 461 ConsumerManagementService::DesktopNotificationDelegate:: |
426 DesktopNotificationDelegate( | 462 DesktopNotificationDelegate( |
427 const std::string& id, | 463 const std::string& id, |
428 const base::Closure& button_click_callback) | 464 const base::Closure& button_click_callback) |
429 : id_(id), | 465 : id_(id), |
430 button_click_callback_(button_click_callback) { | 466 button_click_callback_(button_click_callback) { |
431 } | 467 } |
432 | 468 |
433 void ConsumerManagementService::DesktopNotificationDelegate::ButtonClick( | 469 void ConsumerManagementService::DesktopNotificationDelegate::ButtonClick( |
434 int button_index) { | 470 int button_index) { |
435 button_click_callback_.Run(); | 471 button_click_callback_.Run(); |
436 } | 472 } |
437 | 473 |
438 } // namespace policy | 474 } // namespace policy |
OLD | NEW |