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/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 23 matching lines...) Expand all Loading... |
34 registrar_.Add(this, | 34 registrar_.Add(this, |
35 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | 35 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
36 content::Source<TokenService>(service)); | 36 content::Source<TokenService>(service)); |
37 | 37 |
38 if (!refresh_token_.empty()) | 38 if (!refresh_token_.empty()) |
39 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); | 39 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); |
40 } | 40 } |
41 | 41 |
42 GDataAuthService::GDataAuthService() | 42 GDataAuthService::GDataAuthService() |
43 : profile_(NULL), | 43 : profile_(NULL), |
44 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 44 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 45 weak_ptr_bound_to_ui_thread_(weak_ptr_factory_.GetWeakPtr()) { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
46 } | 47 } |
47 | 48 |
48 GDataAuthService::~GDataAuthService() { | 49 GDataAuthService::~GDataAuthService() { |
49 } | 50 } |
50 | 51 |
51 void GDataAuthService::StartAuthentication( | 52 void GDataAuthService::StartAuthentication( |
52 GDataOperationRegistry* registry, | 53 GDataOperationRegistry* registry, |
53 const AuthStatusCallback& callback) { | 54 const AuthStatusCallback& callback) { |
54 scoped_refptr<base::MessageLoopProxy> relay_proxy( | 55 scoped_refptr<base::MessageLoopProxy> relay_proxy( |
55 base::MessageLoopProxy::current()); | 56 base::MessageLoopProxy::current()); |
56 | 57 |
57 if (HasAccessToken()) { | 58 if (HasAccessToken()) { |
58 relay_proxy->PostTask(FROM_HERE, | 59 relay_proxy->PostTask(FROM_HERE, |
59 base::Bind(callback, gdata::HTTP_SUCCESS, access_token_)); | 60 base::Bind(callback, gdata::HTTP_SUCCESS, access_token_)); |
60 } else if (HasRefreshToken()) { | 61 } else if (HasRefreshToken()) { |
61 BrowserThread::PostTask( | 62 BrowserThread::PostTask( |
62 BrowserThread::UI, | 63 BrowserThread::UI, |
63 FROM_HERE, | 64 FROM_HERE, |
64 base::Bind(&GDataAuthService::StartAuthenticationOnUIThread, | 65 base::Bind(&GDataAuthService::StartAuthenticationOnUIThread, |
65 weak_ptr_factory_.GetWeakPtr(), | 66 weak_ptr_bound_to_ui_thread_, |
66 registry, | 67 registry, |
67 relay_proxy, | 68 relay_proxy, |
68 base::Bind(&GDataAuthService::OnAuthCompleted, | 69 base::Bind(&GDataAuthService::OnAuthCompleted, |
69 weak_ptr_factory_.GetWeakPtr(), | 70 weak_ptr_bound_to_ui_thread_, |
70 relay_proxy, | 71 relay_proxy, |
71 callback))); | 72 callback))); |
72 } else { | 73 } else { |
73 relay_proxy->PostTask(FROM_HERE, | 74 relay_proxy->PostTask(FROM_HERE, |
74 base::Bind(callback, gdata::HTTP_UNAUTHORIZED, std::string())); | 75 base::Bind(callback, gdata::HTTP_UNAUTHORIZED, std::string())); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void GDataAuthService::StartAuthenticationOnUIThread( | 79 void GDataAuthService::StartAuthenticationOnUIThread( |
79 GDataOperationRegistry* registry, | 80 GDataOperationRegistry* registry, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 124 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
124 TokenService* service = TokenServiceFactory::GetForProfile(profile_); | 125 TokenService* service = TokenServiceFactory::GetForProfile(profile_); |
125 refresh_token_ = service->GetOAuth2LoginRefreshToken(); | 126 refresh_token_ = service->GetOAuth2LoginRefreshToken(); |
126 } else { | 127 } else { |
127 refresh_token_.clear(); | 128 refresh_token_.clear(); |
128 } | 129 } |
129 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); | 130 FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); |
130 } | 131 } |
131 | 132 |
132 } // namespace gdata | 133 } // namespace gdata |
OLD | NEW |