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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | 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_notification_types.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 12 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
13 #include "chrome/common/net/gaia/gaia_constants.h" 13 #include "chrome/common/net/gaia/gaia_constants.h"
14 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
15 #include "content/common/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
17 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
18 18
19 // Unfortunately kNumServices must be defined in the .h. 19 // Unfortunately kNumServices must be defined in the .h.
20 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop 20 // TODO(chron): Sync doesn't use the TalkToken anymore so we can stop
21 // requesting it. 21 // requesting it.
22 const char* TokenService::kServices[] = { 22 const char* TokenService::kServices[] = {
23 GaiaConstants::kGaiaService, 23 GaiaConstants::kGaiaService,
24 GaiaConstants::kSyncService, 24 GaiaConstants::kSyncService,
25 GaiaConstants::kTalkService, 25 GaiaConstants::kTalkService,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Note that this can fire twice or more for any given service. 221 // Note that this can fire twice or more for any given service.
222 // It can fire once from the DB read, and then once from the initial 222 // It can fire once from the DB read, and then once from the initial
223 // fetcher. Future fetches can cause more notification firings. 223 // fetcher. Future fetches can cause more notification firings.
224 // The DB read will not however fire a notification if the fetcher 224 // The DB read will not however fire a notification if the fetcher
225 // returned first. So it's always safe to use the latest notification. 225 // returned first. So it's always safe to use the latest notification.
226 void TokenService::FireTokenAvailableNotification( 226 void TokenService::FireTokenAvailableNotification(
227 const std::string& service, 227 const std::string& service,
228 const std::string& auth_token) { 228 const std::string& auth_token) {
229 229
230 TokenAvailableDetails details(service, auth_token); 230 TokenAvailableDetails details(service, auth_token);
231 NotificationService::current()->Notify( 231 content::NotificationService::current()->Notify(
232 chrome::NOTIFICATION_TOKEN_AVAILABLE, 232 chrome::NOTIFICATION_TOKEN_AVAILABLE,
233 content::Source<TokenService>(this), 233 content::Source<TokenService>(this),
234 content::Details<const TokenAvailableDetails>(&details)); 234 content::Details<const TokenAvailableDetails>(&details));
235 } 235 }
236 236
237 void TokenService::FireTokenRequestFailedNotification( 237 void TokenService::FireTokenRequestFailedNotification(
238 const std::string& service, 238 const std::string& service,
239 const GoogleServiceAuthError& error) { 239 const GoogleServiceAuthError& error) {
240 240
241 TokenRequestFailedDetails details(service, error); 241 TokenRequestFailedDetails details(service, error);
242 NotificationService::current()->Notify( 242 content::NotificationService::current()->Notify(
243 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, 243 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
244 content::Source<TokenService>(this), 244 content::Source<TokenService>(this),
245 content::Details<const TokenRequestFailedDetails>(&details)); 245 content::Details<const TokenRequestFailedDetails>(&details));
246 } 246 }
247 247
248 void TokenService::IssueAuthTokenForTest(const std::string& service, 248 void TokenService::IssueAuthTokenForTest(const std::string& service,
249 const std::string& auth_token) { 249 const std::string& auth_token) {
250 token_map_[service] = auth_token; 250 token_map_[service] = auth_token;
251 FireTokenAvailableNotification(service, auth_token); 251 FireTokenAvailableNotification(service, auth_token);
252 } 252 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // If the fetch failed, there will be no result. In that case, we just don't 308 // If the fetch failed, there will be no result. In that case, we just don't
309 // load any tokens at all from the DB. 309 // load any tokens at all from the DB.
310 if (result) { 310 if (result) {
311 DCHECK(result->GetType() == TOKEN_RESULT); 311 DCHECK(result->GetType() == TOKEN_RESULT);
312 const WDResult<std::map<std::string, std::string> > * token_result = 312 const WDResult<std::map<std::string, std::string> > * token_result =
313 static_cast<const WDResult<std::map<std::string, std::string> > * > ( 313 static_cast<const WDResult<std::map<std::string, std::string> > * > (
314 result); 314 result);
315 LoadTokensIntoMemory(token_result->GetValue(), &token_map_); 315 LoadTokensIntoMemory(token_result->GetValue(), &token_map_);
316 } 316 }
317 317
318 NotificationService::current()->Notify( 318 content::NotificationService::current()->Notify(
319 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, 319 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
320 content::Source<TokenService>(this), 320 content::Source<TokenService>(this),
321 NotificationService::NoDetails()); 321 content::NotificationService::NoDetails());
322 } 322 }
323 323
324 // Load tokens from the db_token map into the in memory token map. 324 // Load tokens from the db_token map into the in memory token map.
325 void TokenService::LoadTokensIntoMemory( 325 void TokenService::LoadTokensIntoMemory(
326 const std::map<std::string, std::string>& db_tokens, 326 const std::map<std::string, std::string>& db_tokens,
327 std::map<std::string, std::string>* in_memory_tokens) { 327 std::map<std::string, std::string>* in_memory_tokens) {
328 328
329 for (int i = 0; i < kNumServices; i++) { 329 for (int i = 0; i < kNumServices; i++) {
330 // OnIssueAuthTokenSuccess should come from the same thread. 330 // OnIssueAuthTokenSuccess should come from the same thread.
331 // If a token is already present in the map, it could only have 331 // If a token is already present in the map, it could only have
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 408 }
409 409
410 void TokenService::Observe(int type, 410 void TokenService::Observe(int type,
411 const content::NotificationSource& source, 411 const content::NotificationSource& source,
412 const content::NotificationDetails& details) { 412 const content::NotificationDetails& details) {
413 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED); 413 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_UPDATED);
414 TokenAvailableDetails* tok_details = 414 TokenAvailableDetails* tok_details =
415 content::Details<TokenAvailableDetails>(details).ptr(); 415 content::Details<TokenAvailableDetails>(details).ptr();
416 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token()); 416 OnIssueAuthTokenSuccess(tok_details->service(), tok_details->token());
417 } 417 }
OLDNEW
« no previous file with comments | « chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc ('k') | chrome/browser/net/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698