| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/policy/device_token_fetcher.h" | 5 #include "chrome/browser/policy/device_token_fetcher.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 namespace policy { | 56 namespace policy { |
| 57 | 57 |
| 58 namespace em = enterprise_management; | 58 namespace em = enterprise_management; |
| 59 | 59 |
| 60 DeviceTokenFetcher::ObserverRegistrar::ObserverRegistrar() {} |
| 61 |
| 62 DeviceTokenFetcher::ObserverRegistrar::~ObserverRegistrar() { |
| 63 RemoveAll(); |
| 64 } |
| 65 |
| 66 void DeviceTokenFetcher::ObserverRegistrar::Init( |
| 67 DeviceTokenFetcher* token_fetcher) { |
| 68 token_fetcher_ = token_fetcher; |
| 69 } |
| 70 |
| 71 void DeviceTokenFetcher::ObserverRegistrar::AddObserver( |
| 72 DeviceTokenFetcher::Observer* observer) { |
| 73 observers_.push_back(observer); |
| 74 token_fetcher_->AddObserver(observer); |
| 75 } |
| 76 |
| 77 void DeviceTokenFetcher::ObserverRegistrar::RemoveAll() { |
| 78 for (std::vector<DeviceTokenFetcher::Observer*>::iterator it = |
| 79 observers_.begin(); it != observers_.end(); ++it) { |
| 80 token_fetcher_->RemoveObserver(*it); |
| 81 } |
| 82 observers_.clear(); |
| 83 } |
| 84 |
| 60 DeviceTokenFetcher::DeviceTokenFetcher( | 85 DeviceTokenFetcher::DeviceTokenFetcher( |
| 61 DeviceManagementBackend* backend, | 86 DeviceManagementBackend* backend, |
| 62 Profile* profile, | 87 Profile* profile, |
| 63 const FilePath& token_path) | 88 const FilePath& token_path) |
| 64 : profile_(profile), | 89 : profile_(profile), |
| 65 token_path_(token_path), | 90 token_path_(token_path), |
| 66 backend_(backend), | 91 backend_(backend), |
| 67 state_(kStateNotStarted), | 92 state_(kStateNotStarted), |
| 68 device_token_load_complete_event_(true, false) { | 93 device_token_load_complete_event_(true, false) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 registrar_.Add(this, | 106 registrar_.Add(this, |
| 82 NotificationType::LOGIN_USER_CHANGED, | 107 NotificationType::LOGIN_USER_CHANGED, |
| 83 NotificationService::AllSources()); | 108 NotificationService::AllSources()); |
| 84 #else | 109 #else |
| 85 registrar_.Add(this, | 110 registrar_.Add(this, |
| 86 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 111 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
| 87 Source<Profile>(profile_)); | 112 Source<Profile>(profile_)); |
| 88 #endif | 113 #endif |
| 89 } | 114 } |
| 90 | 115 |
| 116 DeviceTokenFetcher::~DeviceTokenFetcher() {} |
| 117 |
| 91 void DeviceTokenFetcher::Observe(NotificationType type, | 118 void DeviceTokenFetcher::Observe(NotificationType type, |
| 92 const NotificationSource& source, | 119 const NotificationSource& source, |
| 93 const NotificationDetails& details) { | 120 const NotificationDetails& details) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 95 if (type == NotificationType::TOKEN_AVAILABLE) { | 122 if (type == NotificationType::TOKEN_AVAILABLE) { |
| 96 if (Source<TokenService>(source).ptr() == profile_->GetTokenService()) { | 123 if (Source<TokenService>(source).ptr() == profile_->GetTokenService()) { |
| 97 const TokenService::TokenAvailableDetails* token_details = | 124 const TokenService::TokenAvailableDetails* token_details = |
| 98 Details<const TokenService::TokenAvailableDetails>(details).ptr(); | 125 Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
| 99 if (token_details->service() == GaiaConstants::kDeviceManagementService) { | 126 if (token_details->service() == GaiaConstants::kDeviceManagementService) { |
| 100 if (!HasAuthToken()) { | 127 if (!HasAuthToken()) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 DCHECK(no_error); | 331 DCHECK(no_error); |
| 305 file_util::WriteFile(path, data.c_str(), data.length()); | 332 file_util::WriteFile(path, data.c_str(), data.length()); |
| 306 } | 333 } |
| 307 | 334 |
| 308 // static | 335 // static |
| 309 std::string DeviceTokenFetcher::GenerateNewDeviceID() { | 336 std::string DeviceTokenFetcher::GenerateNewDeviceID() { |
| 310 return guid::GenerateGUID(); | 337 return guid::GenerateGUID(); |
| 311 } | 338 } |
| 312 | 339 |
| 313 } // namespace policy | 340 } // namespace policy |
| OLD | NEW |