OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/storage/managed_value_store_cache.h" | 5 #include "chrome/browser/extensions/api/storage/managed_value_store_cache.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 return; | 339 return; |
340 } | 340 } |
341 | 341 |
342 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); | 342 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); |
343 } | 343 } |
344 | 344 |
345 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( | 345 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( |
346 const std::string& extension_id) { | 346 const std::string& extension_id) { |
347 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 347 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
348 | 348 |
349 PolicyValueStoreMap::iterator it = store_map_.find(extension_id); | 349 auto it = store_map_.find(extension_id); |
350 if (it != store_map_.end()) | 350 if (it != store_map_.end()) |
351 return it->second.get(); | 351 return it->second.get(); |
352 | 352 |
353 // Create the store now, and serve the cached policy until the PolicyService | 353 // Create the store now, and serve the cached policy until the PolicyService |
354 // sends updated values. | 354 // sends updated values. |
355 PolicyValueStore* store = new PolicyValueStore( | 355 store_map_[extension_id] = base::MakeUnique<PolicyValueStore>( |
356 extension_id, observers_, | 356 extension_id, observers_, |
357 storage_factory_->CreateSettingsStore(settings_namespace::MANAGED, | 357 storage_factory_->CreateSettingsStore(settings_namespace::MANAGED, |
358 kManagedModelType, extension_id)); | 358 kManagedModelType, extension_id)); |
359 store_map_[extension_id] = make_linked_ptr(store); | |
360 | 359 |
361 return store; | 360 return store_map_[extension_id].get(); |
Devlin
2016/11/02 22:25:33
nit: we can save an extra map lookup here by doing
limasdf
2016/11/03 15:29:23
Done.
| |
362 } | 361 } |
363 | 362 |
364 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const { | 363 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const { |
365 // Note: Currently only manage extensions (not apps). | 364 // Note: Currently only manage extensions (not apps). |
366 return storage_factory_->HasSettings(settings_namespace::MANAGED, | 365 return storage_factory_->HasSettings(settings_namespace::MANAGED, |
367 kManagedModelType, extension_id); | 366 kManagedModelType, extension_id); |
368 } | 367 } |
369 | 368 |
370 } // namespace extensions | 369 } // namespace extensions |
OLD | NEW |