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

Side by Side Diff: chrome/service/gaia/service_gaia_authenticator.cc

Issue 10065040: RefCounted types should not have public destructors, chrome/ remaining parts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation fixes Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/service/gaia/service_gaia_authenticator.h" 5 #include "chrome/service/gaia/service_gaia_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "chrome/service/net/service_url_request_context.h" 9 #include "chrome/service/net/service_url_request_context.h"
10 #include "chrome/service/service_process.h" 10 #include "chrome/service/service_process.h"
11 #include "content/public/common/url_fetcher.h" 11 #include "content/public/common/url_fetcher.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 13
14 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( 14 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator(
15 const std::string& user_agent, const std::string& service_id, 15 const std::string& user_agent, const std::string& service_id,
16 const std::string& gaia_url, 16 const std::string& gaia_url,
17 base::MessageLoopProxy* io_message_loop_proxy) 17 base::MessageLoopProxy* io_message_loop_proxy)
18 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url), 18 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url),
19 http_post_completed_(false, false), 19 http_post_completed_(false, false),
20 io_message_loop_proxy_(io_message_loop_proxy), 20 io_message_loop_proxy_(io_message_loop_proxy),
21 http_response_code_(0) { 21 http_response_code_(0) {
22 } 22 }
23 23
24 ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() { 24 // content::URLFetcherDelegate implementation
25 void ServiceGaiaAuthenticator::OnURLFetchComplete(
26 const content::URLFetcher* source) {
27 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
28 http_response_code_ = source->GetResponseCode();
29 source->GetResponseAsString(&response_data_);
30 delete source;
31 // Add an extra reference because we want http_post_completed_ to remain
32 // valid until after Signal() returns.
33 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this);
34 // Wake the blocked thread in Post.
35 http_post_completed_.Signal();
36 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted!
25 } 37 }
26 38
27 bool ServiceGaiaAuthenticator::Post(const GURL& url, 39 bool ServiceGaiaAuthenticator::Post(const GURL& url,
28 const std::string& post_body, 40 const std::string& post_body,
29 unsigned long* response_code, 41 unsigned long* response_code,
30 std::string* response_body) { 42 std::string* response_body) {
31 DCHECK(url.SchemeIsSecure()); 43 DCHECK(url.SchemeIsSecure());
32 DCHECK(io_message_loop_proxy_); 44 DCHECK(io_message_loop_proxy_);
33 io_message_loop_proxy_->PostTask( 45 io_message_loop_proxy_->PostTask(
34 FROM_HERE, 46 FROM_HERE,
(...skipping 19 matching lines...) Expand all
54 ret = 1; 66 ret = 1;
55 } else { 67 } else {
56 ret = current_backoff_delay * 2; 68 ret = current_backoff_delay * 2;
57 } 69 }
58 if (ret > kMaxBackoffDelaySeconds) { 70 if (ret > kMaxBackoffDelaySeconds) {
59 ret = kMaxBackoffDelaySeconds; 71 ret = kMaxBackoffDelaySeconds;
60 } 72 }
61 return ret; 73 return ret;
62 } 74 }
63 75
76 ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() {}
77
64 void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, 78 void ServiceGaiaAuthenticator::DoPost(const GURL& post_url,
65 const std::string& post_body) { 79 const std::string& post_body) {
66 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 80 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
67 content::URLFetcher* request = content::URLFetcher::Create( 81 content::URLFetcher* request = content::URLFetcher::Create(
68 post_url, content::URLFetcher::POST, this); 82 post_url, content::URLFetcher::POST, this);
69 request->SetRequestContext( 83 request->SetRequestContext(
70 g_service_process->GetServiceURLRequestContextGetter()); 84 g_service_process->GetServiceURLRequestContextGetter());
71 request->SetUploadData("application/x-www-form-urlencoded", post_body); 85 request->SetUploadData("application/x-www-form-urlencoded", post_body);
72 request->Start(); 86 request->Start();
73 } 87 }
74
75 // content::URLFetcherDelegate implementation
76 void ServiceGaiaAuthenticator::OnURLFetchComplete(
77 const content::URLFetcher* source) {
78 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
79 http_response_code_ = source->GetResponseCode();
80 source->GetResponseAsString(&response_data_);
81 delete source;
82 // Add an extra reference because we want http_post_completed_ to remain
83 // valid until after Signal() returns.
84 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this);
85 // Wake the blocked thread in Post.
86 http_post_completed_.Signal();
87 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted!
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698