| OLD | NEW |
| 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/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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 namespace em = enterprise_management; | 58 namespace em = enterprise_management; |
| 59 | 59 |
| 60 DeviceTokenFetcher::ObserverRegistrar::ObserverRegistrar() {} | 60 DeviceTokenFetcher::ObserverRegistrar::ObserverRegistrar() {} |
| 61 | 61 |
| 62 DeviceTokenFetcher::ObserverRegistrar::~ObserverRegistrar() { | 62 DeviceTokenFetcher::ObserverRegistrar::~ObserverRegistrar() { |
| 63 RemoveAll(); | 63 RemoveAll(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DeviceTokenFetcher::ObserverRegistrar::Init( | 66 void DeviceTokenFetcher::ObserverRegistrar::Init( |
| 67 DeviceTokenFetcher* token_fetcher) { | 67 DeviceTokenFetcher* token_fetcher) { |
| 68 RemoveAll(); |
| 68 token_fetcher_ = token_fetcher; | 69 token_fetcher_ = token_fetcher; |
| 69 } | 70 } |
| 70 | 71 |
| 71 void DeviceTokenFetcher::ObserverRegistrar::AddObserver( | 72 void DeviceTokenFetcher::ObserverRegistrar::AddObserver( |
| 72 DeviceTokenFetcher::Observer* observer) { | 73 DeviceTokenFetcher::Observer* observer) { |
| 73 observers_.push_back(observer); | 74 observers_.push_back(observer); |
| 74 token_fetcher_->AddObserver(observer); | 75 token_fetcher_->AddObserver(observer); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void DeviceTokenFetcher::ObserverRegistrar::RemoveAll() { | 78 void DeviceTokenFetcher::ObserverRegistrar::RemoveAll() { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // The Windows compiler needs explicit template instantiation. | 186 // The Windows compiler needs explicit template instantiation. |
| 186 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>( | 187 NewRunnableFunction<bool(*)(const FilePath&, bool), FilePath, bool>( |
| 187 &file_util::Delete, token_path_, false)); | 188 &file_util::Delete, token_path_, false)); |
| 188 SetState(kStateNotManaged); | 189 SetState(kStateNotManaged); |
| 189 return; | 190 return; |
| 190 } | 191 } |
| 191 SetState(kStateFailure); | 192 SetState(kStateFailure); |
| 192 } | 193 } |
| 193 | 194 |
| 194 void DeviceTokenFetcher::Restart() { | 195 void DeviceTokenFetcher::Restart() { |
| 195 DCHECK(!IsTokenPending()); | 196 // Complain if there's currently an asynchronous operation going on. |
| 197 DCHECK(state_ == kStateNotStarted || |
| 198 state_ == kStateHasDeviceToken || |
| 199 state_ == kStateFailure || |
| 200 state_ == kStateNotManaged); |
| 196 device_token_.clear(); | 201 device_token_.clear(); |
| 197 device_token_load_complete_event_.Reset(); | 202 device_token_load_complete_event_.Reset(); |
| 198 MakeReadyToRequestDeviceToken(); | 203 MakeReadyToRequestDeviceToken(); |
| 199 } | 204 } |
| 200 | 205 |
| 201 void DeviceTokenFetcher::StartFetching() { | 206 void DeviceTokenFetcher::StartFetching() { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 203 if (state_ == kStateNotStarted) { | 208 if (state_ == kStateNotStarted) { |
| 204 SetState(kStateLoadDeviceTokenFromDisk); | 209 SetState(kStateLoadDeviceTokenFromDisk); |
| 205 // The file calls for loading the persisted token must be deferred to the | 210 // The file calls for loading the persisted token must be deferred to the |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 DCHECK(no_error); | 331 DCHECK(no_error); |
| 327 file_util::WriteFile(path, data.c_str(), data.length()); | 332 file_util::WriteFile(path, data.c_str(), data.length()); |
| 328 } | 333 } |
| 329 | 334 |
| 330 // static | 335 // static |
| 331 std::string DeviceTokenFetcher::GenerateNewDeviceID() { | 336 std::string DeviceTokenFetcher::GenerateNewDeviceID() { |
| 332 return guid::GenerateGUID(); | 337 return guid::GenerateGUID(); |
| 333 } | 338 } |
| 334 | 339 |
| 335 } // namespace policy | 340 } // namespace policy |
| OLD | NEW |