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/history/web_history_service.h" | 5 #include "chrome/browser/history/web_history_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 virtual ~RequestImpl() { | 52 virtual ~RequestImpl() { |
53 } | 53 } |
54 | 54 |
55 // Returns the response code received from the server, which will only be | 55 // Returns the response code received from the server, which will only be |
56 // valid if the request succeeded. | 56 // valid if the request succeeded. |
57 int response_code() { return response_code_; } | 57 int response_code() { return response_code_; } |
58 | 58 |
59 // Returns the contents of the response body received from the server. | 59 // Returns the contents of the response body received from the server. |
60 const std::string& response_body() { return response_body_; } | 60 const std::string& response_body() { return response_body_; } |
61 | 61 |
62 virtual bool is_pending() OVERRIDE { return is_pending_; } | 62 virtual bool is_pending() override { return is_pending_; } |
63 | 63 |
64 private: | 64 private: |
65 friend class history::WebHistoryService; | 65 friend class history::WebHistoryService; |
66 | 66 |
67 typedef base::Callback<void(Request*, bool)> CompletionCallback; | 67 typedef base::Callback<void(Request*, bool)> CompletionCallback; |
68 | 68 |
69 RequestImpl(Profile* profile, | 69 RequestImpl(Profile* profile, |
70 const GURL& url, | 70 const GURL& url, |
71 const CompletionCallback& callback) | 71 const CompletionCallback& callback) |
72 : OAuth2TokenService::Consumer("web_history"), | 72 : OAuth2TokenService::Consumer("web_history"), |
(...skipping 13 matching lines...) Expand all Loading... |
86 ProfileOAuth2TokenService* token_service = | 86 ProfileOAuth2TokenService* token_service = |
87 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 87 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
88 SigninManagerBase* signin_manager = | 88 SigninManagerBase* signin_manager = |
89 SigninManagerFactory::GetForProfile(profile_); | 89 SigninManagerFactory::GetForProfile(profile_); |
90 token_request_ = token_service->StartRequest( | 90 token_request_ = token_service->StartRequest( |
91 signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this); | 91 signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this); |
92 is_pending_ = true; | 92 is_pending_ = true; |
93 } | 93 } |
94 | 94 |
95 // content::URLFetcherDelegate interface. | 95 // content::URLFetcherDelegate interface. |
96 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { | 96 virtual void OnURLFetchComplete(const net::URLFetcher* source) override { |
97 DCHECK_EQ(source, url_fetcher_.get()); | 97 DCHECK_EQ(source, url_fetcher_.get()); |
98 response_code_ = url_fetcher_->GetResponseCode(); | 98 response_code_ = url_fetcher_->GetResponseCode(); |
99 | 99 |
100 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", | 100 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", |
101 net::HttpUtil::MapStatusCodeForHistogram(response_code_), | 101 net::HttpUtil::MapStatusCodeForHistogram(response_code_), |
102 net::HttpUtil::GetStatusCodesForHistogram()); | 102 net::HttpUtil::GetStatusCodesForHistogram()); |
103 | 103 |
104 // If the response code indicates that the token might not be valid, | 104 // If the response code indicates that the token might not be valid, |
105 // invalidate the token and try again. | 105 // invalidate the token and try again. |
106 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { | 106 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
(...skipping 17 matching lines...) Expand all Loading... |
124 is_pending_ = false; | 124 is_pending_ = false; |
125 callback_.Run(this, true); | 125 callback_.Run(this, true); |
126 // It is valid for the callback to delete |this|, so do not access any | 126 // It is valid for the callback to delete |this|, so do not access any |
127 // members below here. | 127 // members below here. |
128 } | 128 } |
129 | 129 |
130 // OAuth2TokenService::Consumer interface. | 130 // OAuth2TokenService::Consumer interface. |
131 virtual void OnGetTokenSuccess( | 131 virtual void OnGetTokenSuccess( |
132 const OAuth2TokenService::Request* request, | 132 const OAuth2TokenService::Request* request, |
133 const std::string& access_token, | 133 const std::string& access_token, |
134 const base::Time& expiration_time) OVERRIDE { | 134 const base::Time& expiration_time) override { |
135 token_request_.reset(); | 135 token_request_.reset(); |
136 DCHECK(!access_token.empty()); | 136 DCHECK(!access_token.empty()); |
137 access_token_ = access_token; | 137 access_token_ = access_token; |
138 | 138 |
139 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", true); | 139 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", true); |
140 | 140 |
141 // Got an access token -- start the actual API request. | 141 // Got an access token -- start the actual API request. |
142 url_fetcher_.reset(CreateUrlFetcher(access_token)); | 142 url_fetcher_.reset(CreateUrlFetcher(access_token)); |
143 url_fetcher_->Start(); | 143 url_fetcher_->Start(); |
144 } | 144 } |
145 | 145 |
146 virtual void OnGetTokenFailure( | 146 virtual void OnGetTokenFailure( |
147 const OAuth2TokenService::Request* request, | 147 const OAuth2TokenService::Request* request, |
148 const GoogleServiceAuthError& error) OVERRIDE { | 148 const GoogleServiceAuthError& error) override { |
149 token_request_.reset(); | 149 token_request_.reset(); |
150 is_pending_ = false; | 150 is_pending_ = false; |
151 | 151 |
152 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", false); | 152 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", false); |
153 | 153 |
154 callback_.Run(this, false); | 154 callback_.Run(this, false); |
155 // It is valid for the callback to delete |this|, so do not access any | 155 // It is valid for the callback to delete |this|, so do not access any |
156 // members below here. | 156 // members below here. |
157 } | 157 } |
158 | 158 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 if (response_value) | 406 if (response_value) |
407 response_value->GetString("version_info", &server_version_info_); | 407 response_value->GetString("version_info", &server_version_info_); |
408 } | 408 } |
409 callback.Run(response_value.get() && success); | 409 callback.Run(response_value.get() && success); |
410 // Clean up from pending requests. | 410 // Clean up from pending requests. |
411 pending_expire_requests_.erase(request); | 411 pending_expire_requests_.erase(request); |
412 delete request; | 412 delete request; |
413 } | 413 } |
414 | 414 |
415 } // namespace history | 415 } // namespace history |
OLD | NEW |