OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/google_apis/auth_service.h" | 5 #include "chrome/browser/google_apis/auth_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 namespace google_apis { | 34 namespace google_apis { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // Used for success ratio histograms. 0 for failure, 1 for success, | 38 // Used for success ratio histograms. 0 for failure, 1 for success, |
39 // 2 for no connection (likely offline). | 39 // 2 for no connection (likely offline). |
40 const int kSuccessRatioHistogramFailure = 0; | 40 const int kSuccessRatioHistogramFailure = 0; |
41 const int kSuccessRatioHistogramSuccess = 1; | 41 const int kSuccessRatioHistogramSuccess = 1; |
42 const int kSuccessRatioHistogramNoConnection = 2; | 42 const int kSuccessRatioHistogramNoConnection = 2; |
43 const int kSuccessRatioHistogramMaxValue = 3; // The max value is exclusive. | 43 const int kSuccessRatioHistogramTemporaryFailure = 3; |
| 44 const int kSuccessRatioHistogramMaxValue = 4; // The max value is exclusive. |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 // OAuth2 authorization token retrieval operation. | 48 // OAuth2 authorization token retrieval operation. |
48 class AuthOperation : public OperationRegistry::Operation, | 49 class AuthOperation : public OperationRegistry::Operation, |
49 public OAuth2AccessTokenConsumer { | 50 public OAuth2AccessTokenConsumer { |
50 public: | 51 public: |
51 AuthOperation(OperationRegistry* registry, | 52 AuthOperation(OperationRegistry* registry, |
52 net::URLRequestContextGetter* url_request_context_getter, | 53 net::URLRequestContextGetter* url_request_context_getter, |
53 const AuthStatusCallback& callback, | 54 const AuthStatusCallback& callback, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 << error.ToString(); | 130 << error.ToString(); |
130 | 131 |
131 // There are many ways to fail, but if the failure is due to connection, | 132 // There are many ways to fail, but if the failure is due to connection, |
132 // it's likely that the device is off-line. We treat the error differently | 133 // it's likely that the device is off-line. We treat the error differently |
133 // so that the file manager works while off-line. | 134 // so that the file manager works while off-line. |
134 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { | 135 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { |
135 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", | 136 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", |
136 kSuccessRatioHistogramNoConnection, | 137 kSuccessRatioHistogramNoConnection, |
137 kSuccessRatioHistogramMaxValue); | 138 kSuccessRatioHistogramMaxValue); |
138 callback_.Run(GDATA_NO_CONNECTION, std::string()); | 139 callback_.Run(GDATA_NO_CONNECTION, std::string()); |
| 140 } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
| 141 // Temporary auth error. |
| 142 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", |
| 143 kSuccessRatioHistogramTemporaryFailure, |
| 144 kSuccessRatioHistogramMaxValue); |
| 145 callback_.Run(HTTP_FORBIDDEN, std::string()); |
139 } else { | 146 } else { |
| 147 // Permanent auth error. |
140 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", | 148 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", |
141 kSuccessRatioHistogramFailure, | 149 kSuccessRatioHistogramFailure, |
142 kSuccessRatioHistogramMaxValue); | 150 kSuccessRatioHistogramMaxValue); |
143 callback_.Run(HTTP_UNAUTHORIZED, std::string()); | 151 callback_.Run(HTTP_UNAUTHORIZED, std::string()); |
144 } | 152 } |
145 NotifyFinish(OPERATION_FAILED); | 153 NotifyFinish(OPERATION_FAILED); |
146 } | 154 } |
147 | 155 |
148 void AuthService::Initialize(Profile* profile) { | 156 void AuthService::Initialize(Profile* profile) { |
149 profile_ = profile; | 157 profile_ = profile; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 #endif // OS_CHROMEOS | 297 #endif // OS_CHROMEOS |
290 | 298 |
291 // Authentication cannot be done with the incognito mode profile. | 299 // Authentication cannot be done with the incognito mode profile. |
292 if (profile->IsOffTheRecord()) | 300 if (profile->IsOffTheRecord()) |
293 return false; | 301 return false; |
294 | 302 |
295 return true; | 303 return true; |
296 } | 304 } |
297 | 305 |
298 } // namespace google_apis | 306 } // namespace google_apis |
OLD | NEW |