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

Side by Side Diff: chrome/browser/history/web_history_service.cc

Issue 666673010: Standardize usage of virtual/override/final in chrome/browser/history (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 (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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 const char kPostDataMimeType[] = "text/plain"; 43 const char kPostDataMimeType[] = "text/plain";
44 44
45 // The maximum number of retries for the URLFetcher requests. 45 // The maximum number of retries for the URLFetcher requests.
46 const size_t kMaxRetries = 1; 46 const size_t kMaxRetries = 1;
47 47
48 class RequestImpl : public WebHistoryService::Request, 48 class RequestImpl : public WebHistoryService::Request,
49 private OAuth2TokenService::Consumer, 49 private OAuth2TokenService::Consumer,
50 private net::URLFetcherDelegate { 50 private net::URLFetcherDelegate {
51 public: 51 public:
52 virtual ~RequestImpl() { 52 ~RequestImpl() override {}
53 }
54 53
55 // Returns the response code received from the server, which will only be 54 // Returns the response code received from the server, which will only be
56 // valid if the request succeeded. 55 // valid if the request succeeded.
57 int response_code() { return response_code_; } 56 int response_code() { return response_code_; }
58 57
59 // Returns the contents of the response body received from the server. 58 // Returns the contents of the response body received from the server.
60 const std::string& response_body() { return response_body_; } 59 const std::string& response_body() { return response_body_; }
61 60
62 virtual bool is_pending() override { return is_pending_; } 61 bool is_pending() override { return is_pending_; }
63 62
64 private: 63 private:
65 friend class history::WebHistoryService; 64 friend class history::WebHistoryService;
66 65
67 typedef base::Callback<void(Request*, bool)> CompletionCallback; 66 typedef base::Callback<void(Request*, bool)> CompletionCallback;
68 67
69 RequestImpl(Profile* profile, 68 RequestImpl(Profile* profile,
70 const GURL& url, 69 const GURL& url,
71 const CompletionCallback& callback) 70 const CompletionCallback& callback)
72 : OAuth2TokenService::Consumer("web_history"), 71 : OAuth2TokenService::Consumer("web_history"),
(...skipping 13 matching lines...) Expand all
86 ProfileOAuth2TokenService* token_service = 85 ProfileOAuth2TokenService* token_service =
87 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 86 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
88 SigninManagerBase* signin_manager = 87 SigninManagerBase* signin_manager =
89 SigninManagerFactory::GetForProfile(profile_); 88 SigninManagerFactory::GetForProfile(profile_);
90 token_request_ = token_service->StartRequest( 89 token_request_ = token_service->StartRequest(
91 signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this); 90 signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this);
92 is_pending_ = true; 91 is_pending_ = true;
93 } 92 }
94 93
95 // content::URLFetcherDelegate interface. 94 // content::URLFetcherDelegate interface.
96 virtual void OnURLFetchComplete(const net::URLFetcher* source) override { 95 void OnURLFetchComplete(const net::URLFetcher* source) override {
97 DCHECK_EQ(source, url_fetcher_.get()); 96 DCHECK_EQ(source, url_fetcher_.get());
98 response_code_ = url_fetcher_->GetResponseCode(); 97 response_code_ = url_fetcher_->GetResponseCode();
99 98
100 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode", 99 UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebHistory.OAuthTokenResponseCode",
101 net::HttpUtil::MapStatusCodeForHistogram(response_code_), 100 net::HttpUtil::MapStatusCodeForHistogram(response_code_),
102 net::HttpUtil::GetStatusCodesForHistogram()); 101 net::HttpUtil::GetStatusCodesForHistogram());
103 102
104 // If the response code indicates that the token might not be valid, 103 // If the response code indicates that the token might not be valid,
105 // invalidate the token and try again. 104 // invalidate the token and try again.
106 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { 105 if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) {
(...skipping 14 matching lines...) Expand all
121 } 120 }
122 url_fetcher_->GetResponseAsString(&response_body_); 121 url_fetcher_->GetResponseAsString(&response_body_);
123 url_fetcher_.reset(); 122 url_fetcher_.reset();
124 is_pending_ = false; 123 is_pending_ = false;
125 callback_.Run(this, true); 124 callback_.Run(this, true);
126 // It is valid for the callback to delete |this|, so do not access any 125 // It is valid for the callback to delete |this|, so do not access any
127 // members below here. 126 // members below here.
128 } 127 }
129 128
130 // OAuth2TokenService::Consumer interface. 129 // OAuth2TokenService::Consumer interface.
131 virtual void OnGetTokenSuccess( 130 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
132 const OAuth2TokenService::Request* request, 131 const std::string& access_token,
133 const std::string& access_token, 132 const base::Time& expiration_time) override {
134 const base::Time& expiration_time) override {
135 token_request_.reset(); 133 token_request_.reset();
136 DCHECK(!access_token.empty()); 134 DCHECK(!access_token.empty());
137 access_token_ = access_token; 135 access_token_ = access_token;
138 136
139 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", true); 137 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", true);
140 138
141 // Got an access token -- start the actual API request. 139 // Got an access token -- start the actual API request.
142 url_fetcher_.reset(CreateUrlFetcher(access_token)); 140 url_fetcher_.reset(CreateUrlFetcher(access_token));
143 url_fetcher_->Start(); 141 url_fetcher_->Start();
144 } 142 }
145 143
146 virtual void OnGetTokenFailure( 144 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
147 const OAuth2TokenService::Request* request, 145 const GoogleServiceAuthError& error) override {
148 const GoogleServiceAuthError& error) override {
149 token_request_.reset(); 146 token_request_.reset();
150 is_pending_ = false; 147 is_pending_ = false;
151 148
152 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", false); 149 UMA_HISTOGRAM_BOOLEAN("WebHistory.OAuthTokenCompletion", false);
153 150
154 callback_.Run(this, false); 151 callback_.Run(this, false);
155 // It is valid for the callback to delete |this|, so do not access any 152 // It is valid for the callback to delete |this|, so do not access any
156 // members below here. 153 // members below here.
157 } 154 }
158 155
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (response_value) 403 if (response_value)
407 response_value->GetString("version_info", &server_version_info_); 404 response_value->GetString("version_info", &server_version_info_);
408 } 405 }
409 callback.Run(response_value.get() && success); 406 callback.Run(response_value.get() && success);
410 // Clean up from pending requests. 407 // Clean up from pending requests.
411 pending_expire_requests_.erase(request); 408 pending_expire_requests_.erase(request);
412 delete request; 409 delete request;
413 } 410 }
414 411
415 } // namespace history 412 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/web_history_service.h ('k') | chrome/browser/history/web_history_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698