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

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service.h

Issue 17109006: Device robot refresh token integrity validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Extend device_oauth2_token_service_unittest.cc to cover refresh token validation cases. Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
Mattias Nissler (ping if slow) 2013/06/19 17:53:17 forward-declare base::DictionaryValue?
David Roche 2013/06/20 17:49:29 Moved to .cc file with new ValidatingConsumer.
13 #include "chrome/browser/signin/oauth2_token_service.h" 15 #include "chrome/browser/signin/oauth2_token_service.h"
16 #include "google_apis/gaia/gaia_oauth_client.h"
14 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
15 18
16 namespace net { 19 namespace net {
17 class URLRequestContextGetter; 20 class URLRequestContextGetter;
18 } 21 }
19 22
20 class GoogleServiceAuthError; 23 class GoogleServiceAuthError;
21 class PrefRegistrySimple; 24 class PrefRegistrySimple;
22 class PrefService; 25 class PrefService;
23 class Profile; 26 class Profile;
24 27
25 namespace chromeos { 28 namespace chromeos {
26 29
27 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given 30 // DeviceOAuth2TokenService retrieves OAuth2 access tokens for a given
28 // set of scopes using the device-level OAuth2 any-api refresh token 31 // set of scopes using the device-level OAuth2 any-api refresh token
29 // obtained during enterprise device enrollment. 32 // obtained during enterprise device enrollment.
30 // 33 //
31 // See |OAuth2TokenService| for usage details. 34 // See |OAuth2TokenService| for usage details.
32 // 35 //
33 // Note that requests must be made from the UI thread. 36 // Note that requests must be made from the UI thread.
34 class DeviceOAuth2TokenService : public OAuth2TokenService { 37 class DeviceOAuth2TokenService : public OAuth2TokenService,
38 public gaia::GaiaOAuthClient::Delegate {
35 public: 39 public:
36 // Persist the given refresh token on the device. Overwrites any previous 40 // Persist the given refresh token on the device. Overwrites any previous
37 // value. Should only be called during initial device setup. 41 // value. Should only be called during initial device setup.
38 void SetAndSaveRefreshToken(const std::string& refresh_token); 42 void SetAndSaveRefreshToken(const std::string& refresh_token);
39 43
40 static void RegisterPrefs(PrefRegistrySimple* registry); 44 static void RegisterPrefs(PrefRegistrySimple* registry);
41 45
42 virtual std::string GetRefreshToken() OVERRIDE; 46 virtual std::string GetRefreshToken() OVERRIDE;
43 47
48 virtual bool StartRefreshTokenValidation(
49 const std::string refresh_token,
50 RefreshTokenValidationConsumer* consumer) OVERRIDE;
51
52 // gaia::GaiaOAuthClient::Delegate implementation.
53 virtual void OnRefreshTokenResponse(const std::string& access_token,
54 int expires_in_seconds) OVERRIDE;
55 virtual void OnGetTokenInfoResponse(scoped_ptr<DictionaryValue> token_info)
56 OVERRIDE;
57 virtual void OnOAuthError() OVERRIDE;
58 virtual void OnNetworkError(int response_code) OVERRIDE;
59
60 protected:
61 // Pull the robot account ID from device policy.
62 virtual std::string GetRobotAccountId();
63
44 private: 64 private:
45 friend class DeviceOAuth2TokenServiceFactory; 65 friend class DeviceOAuth2TokenServiceFactory;
46 FRIEND_TEST_ALL_PREFIXES(DeviceOAuth2TokenServiceTest, SaveEncryptedToken); 66 friend class DeviceOAuth2TokenServiceTest;
67 friend class TestDeviceOAuth2TokenService;
Mattias Nissler (ping if slow) 2013/06/19 17:53:17 Is this friend decl really needed?
David Roche 2013/06/20 17:49:29 Yes, since the constructor/destructor is private h
47 68
48 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class. 69 // Use DeviceOAuth2TokenServiceFactory to get an instance of this class.
49 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter, 70 explicit DeviceOAuth2TokenService(net::URLRequestContextGetter* getter,
50 PrefService* local_state); 71 PrefService* local_state);
51 virtual ~DeviceOAuth2TokenService(); 72 virtual ~DeviceOAuth2TokenService();
52 73
74 // Inform all waiting RefreshTokenValidationConsumer instances of the current
75 // value of refresh_token_is_valid_.
76 void InformAllConsumers();
77
78 std::vector<RefreshTokenValidationConsumer*>
79 refresh_token_validation_consumers_;
80 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_;
81 bool refresh_token_is_valid_;
82 int max_refresh_token_validation_retries_;
83
53 // Cache the decrypted refresh token, so we only decrypt once. 84 // Cache the decrypted refresh token, so we only decrypt once.
54 std::string refresh_token_; 85 std::string refresh_token_;
55 PrefService* local_state_; 86 PrefService* local_state_;
56 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService); 87 DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenService);
57 }; 88 };
58 89
59 } // namespace chromeos 90 } // namespace chromeos
60 91
61 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_ 92 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698