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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "chrome/browser/notifications/notification_delegate.h" | 17 #include "chrome/browser/notifications/notification_delegate.h" |
17 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
20 #include "google_apis/gaia/oauth2_token_service.h" | 21 #include "google_apis/gaia/oauth2_token_service.h" |
21 | 22 |
22 class NotificationUIManager; | 23 class NotificationUIManager; |
23 class PrefRegistrySimple; | 24 class PrefRegistrySimple; |
24 class Profile; | 25 class Profile; |
25 class ProfileOAuth2TokenService; | 26 class ProfileOAuth2TokenService; |
26 | 27 |
27 namespace chromeos { | 28 namespace chromeos { |
28 class CryptohomeClient; | 29 class CryptohomeClient; |
30 class DeviceSettingsService; | |
29 } | 31 } |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 class WebContents; | 34 class WebContents; |
33 } | 35 } |
34 | 36 |
35 namespace cryptohome { | 37 namespace cryptohome { |
36 class BaseReply; | 38 class BaseReply; |
37 } | 39 } |
38 | 40 |
(...skipping 29 matching lines...) Expand all Loading... | |
68 | 70 |
69 // Error states. | 71 // Error states. |
70 ENROLLMENT_CANCELED, // Canceled by the user. | 72 ENROLLMENT_CANCELED, // Canceled by the user. |
71 ENROLLMENT_BOOT_LOCKBOX_FAILED, // Failed to write to the boot lockbox. | 73 ENROLLMENT_BOOT_LOCKBOX_FAILED, // Failed to write to the boot lockbox. |
72 ENROLLMENT_GET_TOKEN_FAILED, // Failed to get the access token. | 74 ENROLLMENT_GET_TOKEN_FAILED, // Failed to get the access token. |
73 ENROLLMENT_DM_SERVER_FAILED, // Failed to register the device. | 75 ENROLLMENT_DM_SERVER_FAILED, // Failed to register the device. |
74 | 76 |
75 ENROLLMENT_LAST, // This should always be the last one. | 77 ENROLLMENT_LAST, // This should always be the last one. |
76 }; | 78 }; |
77 | 79 |
80 class Observer { | |
81 public: | |
82 // Called when the enrollment state is changed. | |
bartfab (slow)
2014/08/20 14:40:02
Nit: s/is changed/changes/
davidyu
2014/08/21 09:40:29
Done.
| |
83 virtual void OnConsumerManagementEnrollmentStateChanged( | |
84 ConsumerManagementService* service) = 0; | |
bartfab (slow)
2014/08/20 14:40:02
Why not just pass the state here instead of the en
davidyu
2014/08/21 09:40:29
Done.
| |
85 }; | |
86 | |
78 // GetOwner() invokes this with an argument set to the owner user ID, | 87 // GetOwner() invokes this with an argument set to the owner user ID, |
79 // or an empty string on failure. | 88 // or an empty string on failure. |
80 typedef base::Callback<void(const std::string&)> GetOwnerCallback; | 89 typedef base::Callback<void(const std::string&)> GetOwnerCallback; |
81 | 90 |
82 // SetOwner() invokes this with an argument indicating success or failure. | 91 // SetOwner() invokes this with an argument indicating success or failure. |
83 typedef base::Callback<void(bool)> SetOwnerCallback; | 92 typedef base::Callback<void(bool)> SetOwnerCallback; |
84 | 93 |
85 explicit ConsumerManagementService(chromeos::CryptohomeClient* client); | 94 ConsumerManagementService( |
95 chromeos::CryptohomeClient* client, | |
96 chromeos::DeviceSettingsService* device_settings_service); | |
86 | 97 |
87 virtual ~ConsumerManagementService(); | 98 virtual ~ConsumerManagementService(); |
88 | 99 |
89 // Registers prefs. | 100 // Registers prefs. |
90 static void RegisterPrefs(PrefRegistrySimple* registry); | 101 static void RegisterPrefs(PrefRegistrySimple* registry); |
91 | 102 |
103 void AddObserver(Observer* observer); | |
104 void RemoveObserver(Observer* observer); | |
105 | |
92 // Returns the enrollment state. | 106 // Returns the enrollment state. |
93 ConsumerEnrollmentState GetEnrollmentState() const; | 107 ConsumerEnrollmentState GetEnrollmentState() const; |
94 | 108 |
95 // Sets the enrollment state. | 109 // Sets the enrollment state. |
96 void SetEnrollmentState(ConsumerEnrollmentState state); | 110 void SetEnrollmentState(ConsumerEnrollmentState state); |
97 | 111 |
98 // Returns the device owner stored in the boot lockbox via |callback|. | 112 // Returns the device owner stored in the boot lockbox via |callback|. |
99 void GetOwner(const GetOwnerCallback& callback); | 113 void GetOwner(const GetOwnerCallback& callback); |
100 | 114 |
101 // Stores the device owner user ID into the boot lockbox and signs it. | 115 // Stores the device owner user ID into the boot lockbox and signs it. |
102 // |callback| is invoked with an agument indicating success or failure. | 116 // |callback| is invoked with an agument indicating success or failure. |
103 void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); | 117 void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); |
104 | 118 |
119 // Returns true if the device is consumer managed. | |
120 bool IsEnrolled() const; | |
121 | |
122 // Returns true if the enrollment is in progress. | |
bartfab (slow)
2014/08/20 14:40:02
Nit: s/the/consumer/
davidyu
2014/08/21 09:40:29
Done.
| |
123 bool IsEnrolling() const; | |
124 | |
125 // Returns true if the unenrollment is in progress. | |
bartfab (slow)
2014/08/20 14:40:02
Nit: s/the/consumer/
davidyu
2014/08/21 09:40:29
Done.
| |
126 bool IsUnenrolling() const; | |
127 | |
105 // content::NotificationObserver implmentation. | 128 // content::NotificationObserver implmentation. |
106 virtual void Observe(int type, | 129 virtual void Observe(int type, |
107 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
108 const content::NotificationDetails& details) OVERRIDE; | 131 const content::NotificationDetails& details) OVERRIDE; |
109 | 132 |
110 // OAuth2TokenService::Observer implementation. | 133 // OAuth2TokenService::Observer implementation. |
111 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 134 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
112 | 135 |
113 // OAuth2TokenService::Consumer implementation. | 136 // OAuth2TokenService::Consumer implementation. |
114 virtual void OnGetTokenSuccess( | 137 virtual void OnGetTokenSuccess( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 // Shows a desktop notification with a button. | 228 // Shows a desktop notification with a button. |
206 void ShowDesktopNotification( | 229 void ShowDesktopNotification( |
207 Profile* profile, | 230 Profile* profile, |
208 const std::string& id, | 231 const std::string& id, |
209 const std::string& origin_url, | 232 const std::string& origin_url, |
210 const base::string16& title, | 233 const base::string16& title, |
211 const base::string16& body, | 234 const base::string16& body, |
212 const base::string16& button_label, | 235 const base::string16& button_label, |
213 const base::Closure& button_click_callback) const; | 236 const base::Closure& button_click_callback) const; |
214 | 237 |
238 void NotifyEnrollmentStateChanged(); | |
239 | |
215 chromeos::CryptohomeClient* client_; | 240 chromeos::CryptohomeClient* client_; |
241 chromeos::DeviceSettingsService* device_settings_service_; | |
216 | 242 |
217 std::string enrolling_account_id_; | 243 std::string enrolling_account_id_; |
218 Profile* enrolling_profile_; | 244 Profile* enrolling_profile_; |
219 ProfileOAuth2TokenService* enrolling_token_service_; | 245 ProfileOAuth2TokenService* enrolling_token_service_; |
220 bool is_observing_token_service_; | 246 bool is_observing_token_service_; |
221 | 247 |
222 scoped_ptr<OAuth2TokenService::Request> token_request_; | 248 scoped_ptr<OAuth2TokenService::Request> token_request_; |
223 content::NotificationRegistrar registrar_; | 249 content::NotificationRegistrar registrar_; |
250 ObserverList<Observer, true> observers_; | |
224 base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; | 251 base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; |
225 | 252 |
226 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); | 253 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); |
227 }; | 254 }; |
228 | 255 |
229 } // namespace policy | 256 } // namespace policy |
230 | 257 |
231 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 258 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
OLD | NEW |