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

Side by Side Diff: chrome/browser/policy/device_token_fetcher.cc

Issue 4960003: Don't register gmail users at the device management server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 10 years, 1 month 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) 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 #include "chrome/browser/policy/device_token_fetcher.h" 5 #include "chrome/browser/policy/device_token_fetcher.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/singleton.h" 9 #include "base/singleton.h"
10 #include "base/string_util.h"
11 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/net/gaia/token_service.h" 12 #include "chrome/browser/net/gaia/token_service.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profile.h"
11 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/net/gaia/gaia_constants.h" 16 #include "chrome/common/net/gaia/gaia_constants.h"
13 #include "chrome/common/notification_details.h" 17 #include "chrome/common/notification_details.h"
14 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
15 #include "chrome/common/notification_source.h" 19 #include "chrome/common/notification_source.h"
16 #include "chrome/common/notification_type.h" 20 #include "chrome/common/notification_type.h"
21 #include "chrome/common/pref_names.h"
22
23 #if defined(OS_CHROMEOS)
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #else
26 #include "chrome/browser/sync/signin_manager.h"
27 #endif
28
29 class PrefService;
17 30
18 namespace { 31 namespace {
19 32
20 static const char kPlaceholderDeviceID[] = "placeholder_device_id"; 33 static const char kPlaceholderDeviceID[] = "placeholder_device_id";
21 34
35 int kNumNonDasherDomains = 2;
Mattias Nissler (ping if slow) 2010/11/16 09:54:31 You can move this down and use arraysize(kNonDashe
gfeher 2010/11/16 17:37:01 Done.
36
37 // Domain names that are known not to support Dasher.
38 // We don't register the device when such a user logs in.
39 const char* kNonDasherDomains[] = {
40 "@googlemail.com",
41 "@gmail.com"
42 };
43
22 } // namespace 44 } // namespace
23 45
24 namespace policy { 46 namespace policy {
25 47
26 DeviceTokenFetcher::DeviceTokenFetcher( 48 DeviceTokenFetcher::DeviceTokenFetcher(
27 DeviceManagementBackend* backend, 49 DeviceManagementBackend* backend,
28 const FilePath& token_path) 50 const FilePath& token_path)
29 : token_path_(token_path), 51 : token_path_(token_path),
30 backend_(backend), 52 backend_(backend),
31 state_(kStateNotStarted), 53 state_(kStateNotStarted),
32 device_token_load_complete_event_(true, false) { 54 device_token_load_complete_event_(true, false),
55 profile_(NULL) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 // The token fetcher gets initialized AuthTokens for the device management 57 // The token fetcher gets initialized AuthTokens for the device management
35 // server are available. Install a notification observer to ensure that the 58 // server are available. Install a notification observer to ensure that the
36 // device management token gets fetched after the AuthTokens are available. 59 // device management token gets fetched after the AuthTokens are available.
37 registrar_.Add(this, 60 registrar_.Add(this,
38 NotificationType::TOKEN_AVAILABLE, 61 NotificationType::TOKEN_AVAILABLE,
39 NotificationService::AllSources()); 62 NotificationService::AllSources());
63 // Register for the event of user login. The device management token won't
64 // be fetched until we know the domain of the currently logged in user.
65 #if defined(OS_CHROMEOS)
66 registrar_.Add(this,
67 NotificationType::LOGIN_USER_CHANGED,
68 NotificationService::AllSources());
69 #else
70 registrar_.Add(this,
71 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL,
72 NotificationService::AllSources());
73 #endif
40 } 74 }
41 75
42 void DeviceTokenFetcher::Observe(NotificationType type, 76 void DeviceTokenFetcher::Observe(NotificationType type,
43 const NotificationSource& source, 77 const NotificationSource& source,
44 const NotificationDetails& details) { 78 const NotificationDetails& details) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 if (type == NotificationType::TOKEN_AVAILABLE) { 80 if (type == NotificationType::TOKEN_AVAILABLE) {
47 const Source<TokenService> token_service(source);
48 const TokenService::TokenAvailableDetails* token_details = 81 const TokenService::TokenAvailableDetails* token_details =
49 Details<const TokenService::TokenAvailableDetails>(details).ptr(); 82 Details<const TokenService::TokenAvailableDetails>(details).ptr();
50 if (token_details->service() == GaiaConstants::kDeviceManagementService) { 83 if (token_details->service() == GaiaConstants::kDeviceManagementService) {
51 if (!HasAuthToken()) { 84 if (!HasAuthToken()) {
52 auth_token_ = token_details->token(); 85 auth_token_ = token_details->token();
53 SendServerRequestIfPossible(); 86 SendServerRequestIfPossible();
54 } 87 }
55 } 88 }
89 #if defined(OS_CHROMEOS)
90 } else if (type == NotificationType::LOGIN_USER_CHANGED) {
91 SendServerRequestIfPossible();
92 #else
93 } else if (type == NotificationType::GOOGLE_SIGNIN_SUCCESSFUL) {
94 profile_ = Source<Profile>(source).ptr();
95 SendServerRequestIfPossible();
96 #endif
56 } else { 97 } else {
57 NOTREACHED(); 98 NOTREACHED();
58 } 99 }
59 } 100 }
60 101
102 std::string DeviceTokenFetcher::GetCurrentUser() {
103 if (injected_username.get() == NULL) {
Mattias Nissler (ping if slow) 2010/11/16 09:54:31 Is the inject_username quirk really necessary? I s
gfeher 2010/11/16 17:37:01 Done.
104 #if defined(OS_CHROMEOS)
105 return chromeos::UserManager::Get()->logged_in_user().email();
106 #else
107 if (profile_ == NULL) {
108 return "";
109 }
110 return profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
111 #endif
112 } else {
113 return *(injected_username.get());
114 }
115 }
116
117 bool DeviceTokenFetcher::CanCurrentUserBeDasher() {
118 std::string username = GetCurrentUser();
119 if (username.empty()) {
120 // This means incognito user in case of ChromiumOS and
121 // no logged-in user in case of Chromium (SigninService).
122 return false;
123 }
124 for (int i = 0; i < kNumNonDasherDomains; i++) {
125 if (EndsWith(username, kNonDasherDomains[i], true)) {
126 return false;
127 }
128 }
129 return true;
130 }
131
61 void DeviceTokenFetcher::HandleRegisterResponse( 132 void DeviceTokenFetcher::HandleRegisterResponse(
62 const em::DeviceRegisterResponse& response) { 133 const em::DeviceRegisterResponse& response) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 DCHECK_EQ(kStateRequestingDeviceTokenFromServer, state_); 135 DCHECK_EQ(kStateRequestingDeviceTokenFromServer, state_);
65 if (response.has_device_management_token()) { 136 if (response.has_device_management_token()) {
66 device_token_ = response.device_management_token(); 137 device_token_ = response.device_management_token();
67 BrowserThread::PostTask( 138 BrowserThread::PostTask(
68 BrowserThread::FILE, 139 BrowserThread::FILE,
69 FROM_HERE, 140 FROM_HERE,
70 NewRunnableFunction(&WriteDeviceTokenToDisk, 141 NewRunnableFunction(&WriteDeviceTokenToDisk,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 193
123 void DeviceTokenFetcher::MakeReadyToRequestDeviceToken() { 194 void DeviceTokenFetcher::MakeReadyToRequestDeviceToken() {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 SetState(kStateReadyToRequestDeviceTokenFromServer); 196 SetState(kStateReadyToRequestDeviceTokenFromServer);
126 SendServerRequestIfPossible(); 197 SendServerRequestIfPossible();
127 } 198 }
128 199
129 void DeviceTokenFetcher::SendServerRequestIfPossible() { 200 void DeviceTokenFetcher::SendServerRequestIfPossible() {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
131 if (state_ == kStateReadyToRequestDeviceTokenFromServer 202 if (state_ == kStateReadyToRequestDeviceTokenFromServer
132 && HasAuthToken()) { 203 && HasAuthToken() && CanCurrentUserBeDasher()) {
133 em::DeviceRegisterRequest register_request; 204 em::DeviceRegisterRequest register_request;
134 SetState(kStateRequestingDeviceTokenFromServer); 205 SetState(kStateRequestingDeviceTokenFromServer);
135 backend_->ProcessRegisterRequest(auth_token_, 206 backend_->ProcessRegisterRequest(auth_token_,
136 GetDeviceID(), 207 GetDeviceID(),
137 register_request, 208 register_request,
138 this); 209 this);
139 } 210 }
140 } 211 }
141 212
142 bool DeviceTokenFetcher::IsTokenPending() { 213 bool DeviceTokenFetcher::IsTokenPending() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 device_token.length()); 256 device_token.length());
186 } 257 }
187 258
188 // static 259 // static
189 std::string DeviceTokenFetcher::GetDeviceID() { 260 std::string DeviceTokenFetcher::GetDeviceID() {
190 // TODO(danno): fetch a real device_id 261 // TODO(danno): fetch a real device_id
191 return kPlaceholderDeviceID; 262 return kPlaceholderDeviceID;
192 } 263 }
193 264
194 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698