OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_POLICY_DEVICE_TOKEN_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ |
6 #define CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/waitable_event.h" | 13 #include "base/waitable_event.h" |
14 #include "chrome/browser/policy/device_management_backend.h" | 14 #include "chrome/browser/policy/device_management_backend.h" |
15 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
17 | 17 |
18 class Profile; | |
19 | |
18 namespace policy { | 20 namespace policy { |
19 | 21 |
20 namespace em = enterprise_management; | 22 namespace em = enterprise_management; |
21 | 23 |
22 // Fetches the device token that can be used for policy requests with the device | 24 // Fetches the device token that can be used for policy requests with the device |
23 // management server, either from disk if it already has been successfully | 25 // management server, either from disk if it already has been successfully |
24 // requested, otherwise from the device management server. An instance of the | 26 // requested, otherwise from the device management server. An instance of the |
25 // fetcher is shared as a singleton by all users of the device management token | 27 // fetcher is shared as a singleton by all users of the device management token |
26 // to ensure they all get the same token. | 28 // to ensure they all get the same token. |
27 class DeviceTokenFetcher | 29 class DeviceTokenFetcher |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 std::string GetDeviceToken(); | 64 std::string GetDeviceToken(); |
63 | 65 |
64 // True if the fetcher has a valid AuthToken for the device management server. | 66 // True if the fetcher has a valid AuthToken for the device management server. |
65 bool HasAuthToken() const { return !auth_token_.empty(); } | 67 bool HasAuthToken() const { return !auth_token_.empty(); } |
66 | 68 |
67 // True if the device token has been fetched and is valid. | 69 // True if the device token has been fetched and is valid. |
68 bool IsTokenValid() const; | 70 bool IsTokenValid() const; |
69 | 71 |
70 private: | 72 private: |
71 friend class DeviceTokenFetcherTest; | 73 friend class DeviceTokenFetcherTest; |
74 friend void SimulateUsernameAvailable(DeviceTokenFetcher* fetcher, | |
75 const std::string& username); | |
72 | 76 |
73 // The different states that the fetcher can be in during the process of | 77 // The different states that the fetcher can be in during the process of |
74 // getting the device token. | 78 // getting the device token. |
75 enum FetcherState { | 79 enum FetcherState { |
76 kStateNotStarted, | 80 kStateNotStarted, |
77 kStateLoadDeviceTokenFromDisk, | 81 kStateLoadDeviceTokenFromDisk, |
78 kStateReadyToRequestDeviceTokenFromServer, | 82 kStateReadyToRequestDeviceTokenFromServer, |
79 kStateRequestingDeviceTokenFromServer, | 83 kStateRequestingDeviceTokenFromServer, |
80 kStateHasDeviceToken, | 84 kStateHasDeviceToken, |
81 kStateFailure | 85 kStateFailure |
(...skipping 11 matching lines...) Expand all Loading... | |
93 // thread. | 97 // thread. |
94 void AttemptTokenLoadFromDisk(); | 98 void AttemptTokenLoadFromDisk(); |
95 | 99 |
96 // Called if it's not possible to load the device token from disk. Sets the | 100 // Called if it's not possible to load the device token from disk. Sets the |
97 // fetcher in a state that's ready to register the device with the device | 101 // fetcher in a state that's ready to register the device with the device |
98 // management server and receive the device token in return. If the AuthToken | 102 // management server and receive the device token in return. If the AuthToken |
99 // for the device management server is available, initiate the server | 103 // for the device management server is available, initiate the server |
100 // request. | 104 // request. |
101 void MakeReadyToRequestDeviceToken(); | 105 void MakeReadyToRequestDeviceToken(); |
102 | 106 |
107 // Returns the email address of the currently logged-in user. | |
108 std::string GetCurrentUser(); | |
109 | |
110 // Checks the email of the currently logged-in user against the list of | |
111 // non-domain names. Returns false if there is no user logged in, or if the | |
112 // domain part of the email of the currently logged in user is in | |
113 // |kNonDasherDomains|. | |
Mattias Nissler (ping if slow)
2010/11/16 09:54:31
I feel the reference to |kNonDasherDomains| here i
gfeher
2010/11/16 17:37:01
Done.
| |
114 bool CanCurrentUserBeDasher(); | |
115 | |
103 // Issues a registration request to the server if both the fetcher is in the | 116 // Issues a registration request to the server if both the fetcher is in the |
104 // ready-to-request state and the device management server AuthToken is | 117 // ready-to-request state and the device management server AuthToken is |
105 // available. | 118 // available. |
106 void SendServerRequestIfPossible(); | 119 void SendServerRequestIfPossible(); |
107 | 120 |
108 // Saves the device management token to disk once it has been retrieved from | 121 // Saves the device management token to disk once it has been retrieved from |
109 // the server. Must be called on the FILE thread. | 122 // the server. Must be called on the FILE thread. |
110 static void WriteDeviceTokenToDisk(const FilePath& path, | 123 static void WriteDeviceTokenToDisk(const FilePath& path, |
111 const std::string& token); | 124 const std::string& token); |
112 | 125 |
(...skipping 10 matching lines...) Expand all Loading... | |
123 // AuthToken hasn't been issued yet or that was an error getting the | 136 // AuthToken hasn't been issued yet or that was an error getting the |
124 // AuthToken. | 137 // AuthToken. |
125 std::string auth_token_; | 138 std::string auth_token_; |
126 | 139 |
127 // An event that is signaled only once the device token has been fetched | 140 // An event that is signaled only once the device token has been fetched |
128 // or it has been determined that there was an error during fetching. | 141 // or it has been determined that there was an error during fetching. |
129 base::WaitableEvent device_token_load_complete_event_; | 142 base::WaitableEvent device_token_load_complete_event_; |
130 | 143 |
131 // Registers the fetcher for notification of successful Gaia logins. | 144 // Registers the fetcher for notification of successful Gaia logins. |
132 NotificationRegistrar registrar_; | 145 NotificationRegistrar registrar_; |
146 | |
147 // Only set when a user is signed in via SigninManager. Only used to | |
148 // check later if the user is still logged on. | |
149 Profile* profile_; | |
150 | |
151 // Helper for testing: if this is not NULL, then DeviceTokenFetcher does not | |
152 // get the logged-in user's name from UserManager or SigninManager, but | |
153 // uses this value instead. | |
154 scoped_ptr<std::string> injected_username; | |
Mattias Nissler (ping if slow)
2010/11/16 09:54:31
Why scoped_ptr-wrapped?
Also, it seems a bit odd
gfeher
2010/11/16 17:37:01
To allow it to be NULL. Let's forget it. :)
| |
133 }; | 155 }; |
134 | 156 |
135 } // namespace policy | 157 } // namespace policy |
136 | 158 |
137 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ | 159 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ |
OLD | NEW |