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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_auth_service.cc

Issue 10827018: gdata: Rename functions in GDataAuthService per OAuth2 terminology (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 4 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) 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/chromeos/gdata/gdata_auth_service.h" 5 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 GDataAuthService::~GDataAuthService() { 49 GDataAuthService::~GDataAuthService() {
50 } 50 }
51 51
52 void GDataAuthService::StartAuthentication( 52 void GDataAuthService::StartAuthentication(
53 GDataOperationRegistry* registry, 53 GDataOperationRegistry* registry,
54 const AuthStatusCallback& callback) { 54 const AuthStatusCallback& callback) {
55 scoped_refptr<base::MessageLoopProxy> relay_proxy( 55 scoped_refptr<base::MessageLoopProxy> relay_proxy(
56 base::MessageLoopProxy::current()); 56 base::MessageLoopProxy::current());
57 57
58 if (IsFullyAuthenticated()) { 58 if (HasAccessToken()) {
59 relay_proxy->PostTask(FROM_HERE, 59 relay_proxy->PostTask(FROM_HERE,
60 base::Bind(callback, gdata::HTTP_SUCCESS, oauth2_auth_token())); 60 base::Bind(callback, gdata::HTTP_SUCCESS, access_token_));
61 } else if (IsPartiallyAuthenticated()) { 61 } else if (HasRefreshToken()) {
62 BrowserThread::PostTask( 62 BrowserThread::PostTask(
63 BrowserThread::UI, 63 BrowserThread::UI,
64 FROM_HERE, 64 FROM_HERE,
65 base::Bind(&GDataAuthService::StartAuthenticationOnUIThread, 65 base::Bind(&GDataAuthService::StartAuthenticationOnUIThread,
66 weak_ptr_bound_to_ui_thread_, 66 weak_ptr_bound_to_ui_thread_,
67 registry, 67 registry,
68 relay_proxy, 68 relay_proxy,
69 base::Bind(&GDataAuthService::OnAuthCompleted, 69 base::Bind(&GDataAuthService::OnAuthCompleted,
70 weak_ptr_bound_to_ui_thread_, 70 weak_ptr_bound_to_ui_thread_,
71 relay_proxy, 71 relay_proxy,
72 callback))); 72 callback)));
73 } else { 73 } else {
74 relay_proxy->PostTask(FROM_HERE, 74 relay_proxy->PostTask(FROM_HERE,
75 base::Bind(callback, gdata::HTTP_UNAUTHORIZED, std::string())); 75 base::Bind(callback, gdata::HTTP_UNAUTHORIZED, std::string()));
76 } 76 }
77 } 77 }
78 78
79 void GDataAuthService::StartAuthenticationOnUIThread( 79 void GDataAuthService::StartAuthenticationOnUIThread(
80 GDataOperationRegistry* registry, 80 GDataOperationRegistry* registry,
81 scoped_refptr<base::MessageLoopProxy> relay_proxy, 81 scoped_refptr<base::MessageLoopProxy> relay_proxy,
82 const AuthStatusCallback& callback) { 82 const AuthStatusCallback& callback) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 // We have refresh token, let's gets authenticated. 84 // We have refresh token, let's gets authenticated.
85 (new AuthOperation(registry, profile_, 85 (new AuthOperation(registry, profile_,
86 callback, GetOAuth2RefreshToken()))->Start(); 86 callback, refresh_token_))->Start();
87 } 87 }
88 88
89 void GDataAuthService::OnAuthCompleted( 89 void GDataAuthService::OnAuthCompleted(
90 scoped_refptr<base::MessageLoopProxy> relay_proxy, 90 scoped_refptr<base::MessageLoopProxy> relay_proxy,
91 const AuthStatusCallback& callback, 91 const AuthStatusCallback& callback,
92 GDataErrorCode error, 92 GDataErrorCode error,
93 const std::string& auth_token) { 93 const std::string& access_token) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95 95
96 if (error == HTTP_SUCCESS) 96 if (error == HTTP_SUCCESS)
97 auth_token_ = auth_token; 97 access_token_ = access_token;
98 98
99 // TODO(zelidrag): Add retry, back-off logic when things go wrong here. 99 // TODO(zelidrag): Add retry, back-off logic when things go wrong here.
100 if (!callback.is_null()) 100 if (!callback.is_null())
101 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, auth_token)); 101 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error, access_token));
102 } 102 }
103 103
104 void GDataAuthService::AddObserver(Observer* observer) { 104 void GDataAuthService::AddObserver(Observer* observer) {
105 observers_.AddObserver(observer); 105 observers_.AddObserver(observer);
106 } 106 }
107 107
108 void GDataAuthService::RemoveObserver(Observer* observer) { 108 void GDataAuthService::RemoveObserver(Observer* observer) {
109 observers_.RemoveObserver(observer); 109 observers_.RemoveObserver(observer);
110 } 110 }
111 111
112 void GDataAuthService::Observe(int type, 112 void GDataAuthService::Observe(int type,
113 const content::NotificationSource& source, 113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) { 114 const content::NotificationDetails& details) {
115 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE || 115 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE ||
116 type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED); 116 type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED);
117 117
118 TokenService::TokenAvailableDetails* token_details = 118 TokenService::TokenAvailableDetails* token_details =
119 content::Details<TokenService::TokenAvailableDetails>(details).ptr(); 119 content::Details<TokenService::TokenAvailableDetails>(details).ptr();
120 if (token_details->service() != GaiaConstants::kGaiaOAuth2LoginRefreshToken) 120 if (token_details->service() != GaiaConstants::kGaiaOAuth2LoginRefreshToken)
121 return; 121 return;
122 122
123 auth_token_.clear(); 123 access_token_.clear();
124 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { 124 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) {
125 TokenService* service = TokenServiceFactory::GetForProfile(profile_); 125 TokenService* service = TokenServiceFactory::GetForProfile(profile_);
126 refresh_token_ = service->GetOAuth2LoginRefreshToken(); 126 refresh_token_ = service->GetOAuth2LoginRefreshToken();
127 } else { 127 } else {
128 refresh_token_.clear(); 128 refresh_token_.clear();
129 } 129 }
130 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); 130 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged());
131 } 131 }
132 132
133 } // namespace gdata 133 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_auth_service.h ('k') | chrome/browser/chromeos/gdata/gdata_documents_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698