Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/logging.h" | |
| 5 #include "chrome/browser/extensions/token_cache/token_cache_service.h" | 6 #include "chrome/browser/extensions/token_cache/token_cache_service.h" |
| 6 | 7 #include "chrome/browser/signin/signin_manager.h" |
| 7 #include "base/logging.h" | 8 #include "chrome/browser/signin/signin_manager_factory.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "content/public/browser/notification_source.h" | |
| 10 | 9 |
| 11 using base::Time; | 10 using base::Time; |
| 12 using base::TimeDelta; | 11 using base::TimeDelta; |
| 13 | 12 |
| 14 namespace extensions { | 13 namespace extensions { |
| 15 | 14 |
| 16 TokenCacheService::TokenCacheService(Profile* profile) : profile_(profile) { | 15 TokenCacheService::TokenCacheService(Profile* profile) : profile_(profile) { |
| 17 registrar_.Add(this, | 16 SigninManagerFactory::GetForProfile(profile)->AddObserver(this); |
| 18 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
| 19 content::Source<Profile>(profile_)); | |
| 20 } | 17 } |
| 21 | 18 |
| 22 TokenCacheService::~TokenCacheService() { | 19 TokenCacheService::~TokenCacheService() { |
| 20 SigninManagerFactory::GetForProfile(const_cast<Profile*>(profile_)) | |
|
Yoyo Zhou
2014/02/18 17:45:54
This should be in TokenCacheService::Shutdown.
Al
blundell
2014/02/18 19:53:42
Great catches, thanks. Done.
On 2014/02/18 17:45:
| |
| 21 ->RemoveObserver(this); | |
| 23 } | 22 } |
| 24 | 23 |
| 25 void TokenCacheService::StoreToken(const std::string& token_name, | 24 void TokenCacheService::StoreToken(const std::string& token_name, |
| 26 const std::string& token_value, | 25 const std::string& token_value, |
| 27 base::TimeDelta time_to_live) { | 26 base::TimeDelta time_to_live) { |
| 28 TokenCacheData token_data; | 27 TokenCacheData token_data; |
| 29 | 28 |
| 30 // Get the current time, and make sure that the token has not already expired. | 29 // Get the current time, and make sure that the token has not already expired. |
| 31 Time expiration_time; | 30 Time expiration_time; |
| 32 TimeDelta zero_delta; | 31 TimeDelta zero_delta; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 60 } else { | 59 } else { |
| 61 // Remove this entry if it is expired. | 60 // Remove this entry if it is expired. |
| 62 token_cache_.erase(it); | 61 token_cache_.erase(it); |
| 63 return std::string(); | 62 return std::string(); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 | 65 |
| 67 return std::string(); | 66 return std::string(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 // Inherited from NotificationObserver. | 69 void TokenCacheService::GoogleSignedOut(const std::string& username) { |
| 71 void TokenCacheService::Observe(int type, | |
| 72 const content::NotificationSource& source, | |
| 73 const content::NotificationDetails& details) { | |
| 74 DCHECK(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT == type); | |
| 75 token_cache_.clear(); | 70 token_cache_.clear(); |
| 76 } | 71 } |
| 77 | 72 |
| 78 } // namespace extensions | 73 } // namespace extensions |
| OLD | NEW |