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

Side by Side Diff: chrome/browser/net/gaia/token_service.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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/browser/net/gaia/token_service.h" 5 #include "chrome/browser/net/gaia/token_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 12 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
12 #include "chrome/common/net/gaia/gaia_constants.h" 13 #include "chrome/common/net/gaia/gaia_constants.h"
13 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
14 #include "content/common/notification_service.h" 15 #include "content/common/notification_service.h"
15 #include "net/url_request/url_request_context_getter.h" 16 #include "net/url_request/url_request_context_getter.h"
16 17
17 // Unfortunately kNumServices must be defined in the .h. 18 // Unfortunately kNumServices must be defined in the .h.
18 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop 19 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop
19 // requesting it. 20 // requesting it.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken); 60 std::string value = cmd_line->GetSwitchValueASCII(switches::kSetToken);
60 int separator = value.find(':'); 61 int separator = value.find(':');
61 std::string service = value.substr(0, separator); 62 std::string service = value.substr(0, separator);
62 std::string token = value.substr(separator + 1); 63 std::string token = value.substr(separator + 1);
63 token_map_[service] = token; 64 token_map_[service] = token;
64 SaveAuthTokenToDB(service, token); 65 SaveAuthTokenToDB(service, token);
65 } 66 }
66 #endif 67 #endif
67 68
68 registrar_.Add(this, 69 registrar_.Add(this,
69 NotificationType::TOKEN_UPDATED, 70 chrome::NOTIFICATION_TOKEN_UPDATED,
70 NotificationService::AllSources()); 71 NotificationService::AllSources());
71 } 72 }
72 73
73 void TokenService::ResetCredentialsInMemory() { 74 void TokenService::ResetCredentialsInMemory() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 76
76 // Terminate any running fetchers. Callbacks will not return. 77 // Terminate any running fetchers. Callbacks will not return.
77 for (int i = 0; i < kNumServices; i++) { 78 for (int i = 0; i < kNumServices; i++) {
78 fetchers_[i].reset(); 79 fetchers_[i].reset();
79 } 80 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // It can fire once from the DB read, and then once from the initial 161 // It can fire once from the DB read, and then once from the initial
161 // fetcher. Future fetches can cause more notification firings. 162 // fetcher. Future fetches can cause more notification firings.
162 // The DB read will not however fire a notification if the fetcher 163 // The DB read will not however fire a notification if the fetcher
163 // returned first. So it's always safe to use the latest notification. 164 // returned first. So it's always safe to use the latest notification.
164 void TokenService::FireTokenAvailableNotification( 165 void TokenService::FireTokenAvailableNotification(
165 const std::string& service, 166 const std::string& service,
166 const std::string& auth_token) { 167 const std::string& auth_token) {
167 168
168 TokenAvailableDetails details(service, auth_token); 169 TokenAvailableDetails details(service, auth_token);
169 NotificationService::current()->Notify( 170 NotificationService::current()->Notify(
170 NotificationType::TOKEN_AVAILABLE, 171 chrome::NOTIFICATION_TOKEN_AVAILABLE,
171 Source<TokenService>(this), 172 Source<TokenService>(this),
172 Details<const TokenAvailableDetails>(&details)); 173 Details<const TokenAvailableDetails>(&details));
173 } 174 }
174 175
175 void TokenService::FireTokenRequestFailedNotification( 176 void TokenService::FireTokenRequestFailedNotification(
176 const std::string& service, 177 const std::string& service,
177 const GoogleServiceAuthError& error) { 178 const GoogleServiceAuthError& error) {
178 179
179 TokenRequestFailedDetails details(service, error); 180 TokenRequestFailedDetails details(service, error);
180 NotificationService::current()->Notify( 181 NotificationService::current()->Notify(
181 NotificationType::TOKEN_REQUEST_FAILED, 182 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
182 Source<TokenService>(this), 183 Source<TokenService>(this),
183 Details<const TokenRequestFailedDetails>(&details)); 184 Details<const TokenRequestFailedDetails>(&details));
184 } 185 }
185 186
186 void TokenService::IssueAuthTokenForTest(const std::string& service, 187 void TokenService::IssueAuthTokenForTest(const std::string& service,
187 const std::string& auth_token) { 188 const std::string& auth_token) {
188 token_map_[service] = auth_token; 189 token_map_[service] = auth_token;
189 FireTokenAvailableNotification(service, auth_token); 190 FireTokenAvailableNotification(service, auth_token);
190 } 191 }
191 192
(...skipping 23 matching lines...) Expand all
215 // load any tokens at all from the DB. 216 // load any tokens at all from the DB.
216 if (result) { 217 if (result) {
217 DCHECK(result->GetType() == TOKEN_RESULT); 218 DCHECK(result->GetType() == TOKEN_RESULT);
218 const WDResult<std::map<std::string, std::string> > * token_result = 219 const WDResult<std::map<std::string, std::string> > * token_result =
219 static_cast<const WDResult<std::map<std::string, std::string> > * > ( 220 static_cast<const WDResult<std::map<std::string, std::string> > * > (
220 result); 221 result);
221 LoadTokensIntoMemory(token_result->GetValue(), &token_map_); 222 LoadTokensIntoMemory(token_result->GetValue(), &token_map_);
222 } 223 }
223 224
224 NotificationService::current()->Notify( 225 NotificationService::current()->Notify(
225 NotificationType::TOKEN_LOADING_FINISHED, 226 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
226 Source<TokenService>(this), 227 Source<TokenService>(this),
227 NotificationService::NoDetails()); 228 NotificationService::NoDetails());
228 } 229 }
229 230
230 // Load tokens from the db_token map into the in memory token map. 231 // Load tokens from the db_token map into the in memory token map.
231 void TokenService::LoadTokensIntoMemory( 232 void TokenService::LoadTokensIntoMemory(
232 const std::map<std::string, std::string>& db_tokens, 233 const std::map<std::string, std::string>& db_tokens,
233 std::map<std::string, std::string>* in_memory_tokens) { 234 std::map<std::string, std::string>* in_memory_tokens) {
234 235
235 for (int i = 0; i < kNumServices; i++) { 236 for (int i = 0; i < kNumServices; i++) {
(...skipping 11 matching lines...) Expand all
247 if (!db_token.empty()) { 248 if (!db_token.empty()) {
248 VLOG(1) << "Loading " << kServices[i] << "token from DB: " << db_token; 249 VLOG(1) << "Loading " << kServices[i] << "token from DB: " << db_token;
249 (*in_memory_tokens)[kServices[i]] = db_token; 250 (*in_memory_tokens)[kServices[i]] = db_token;
250 FireTokenAvailableNotification(kServices[i], db_token); 251 FireTokenAvailableNotification(kServices[i], db_token);
251 // Failures are only for network errors. 252 // Failures are only for network errors.
252 } 253 }
253 } 254 }
254 } 255 }
255 } 256 }
256 257
257 void TokenService::Observe(NotificationType type, 258 void TokenService::Observe(int type,
258 const NotificationSource& source, 259 const NotificationSource& source,
259 const NotificationDetails& details) { 260 const NotificationDetails& details) {
260 DCHECK(type == NotificationType::TOKEN_UPDATED); 261 DCHECK(type == chrome::NOTIFICATION_TOKEN_UPDATED);
261 TokenAvailableDetails* tok_details = 262 TokenAvailableDetails* tok_details =
262 Details<TokenAvailableDetails>(details).ptr(); 263 Details<TokenAvailableDetails>(details).ptr();
263 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); 264 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token());
264 } 265 }
OLDNEW
« no previous file with comments | « chrome/browser/net/gaia/token_service.h ('k') | chrome/browser/net/gaia/token_service_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698