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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 void ManagedValueStoreCache::DeleteStorageSoon( | 229 void ManagedValueStoreCache::DeleteStorageSoon( |
230 const std::string& extension_id) { | 230 const std::string& extension_id) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
232 PolicyValueStore* store = GetStoreFor(extension_id); | 232 PolicyValueStore* store = GetStoreFor(extension_id); |
233 if (!store) { | 233 if (!store) { |
234 // It's possible that the store exists, but hasn't been loaded yet | 234 // It's possible that the store exists, but hasn't been loaded yet |
235 // (because the extension is unloaded, for example). Open the database to | 235 // (because the extension is unloaded, for example). Open the database to |
236 // clear it if it exists. | 236 // clear it if it exists. |
237 // TODO(joaodasilva): move this check to a ValueStore method. | 237 // TODO(joaodasilva): move this check to a ValueStore method. |
238 if (file_util::DirectoryExists(base_path_.AppendASCII(extension_id))) { | 238 if (base::DirectoryExists(base_path_.AppendASCII(extension_id))) { |
239 CreateStoreFor( | 239 CreateStoreFor( |
240 extension_id, | 240 extension_id, |
241 false, | 241 false, |
242 base::Bind(&ManagedValueStoreCache::DeleteStorageSoon, | 242 base::Bind(&ManagedValueStoreCache::DeleteStorageSoon, |
243 base::Unretained(this), | 243 base::Unretained(this), |
244 extension_id)); | 244 extension_id)); |
245 } | 245 } |
246 } else { | 246 } else { |
247 store->DeleteStorage(); | 247 store->DeleteStorage(); |
248 store_map_.erase(extension_id); | 248 store_map_.erase(extension_id); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 // its UI task, then the 2nd will enter this function but the store has | 376 // its UI task, then the 2nd will enter this function but the store has |
377 // already been created. Check for that. | 377 // already been created. Check for that. |
378 PolicyValueStore* store = GetStoreFor(extension_id); | 378 PolicyValueStore* store = GetStoreFor(extension_id); |
379 | 379 |
380 if (!store) { | 380 if (!store) { |
381 // Create it now. | 381 // Create it now. |
382 | 382 |
383 // If the database doesn't exist yet then this is the initial install, | 383 // If the database doesn't exist yet then this is the initial install, |
384 // and no notifications should be issued in that case. | 384 // and no notifications should be issued in that case. |
385 // TODO(joaodasilva): move this check to a ValueStore method. | 385 // TODO(joaodasilva): move this check to a ValueStore method. |
386 if (!file_util::DirectoryExists(base_path_.AppendASCII(extension_id))) | 386 if (!base::DirectoryExists(base_path_.AppendASCII(extension_id))) |
387 notify_if_changed = false; | 387 notify_if_changed = false; |
388 | 388 |
389 store = new PolicyValueStore( | 389 store = new PolicyValueStore( |
390 extension_id, | 390 extension_id, |
391 observers_, | 391 observers_, |
392 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); | 392 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); |
393 store_map_[extension_id] = make_linked_ptr(store); | 393 store_map_[extension_id] = make_linked_ptr(store); |
394 } | 394 } |
395 | 395 |
396 // Send the latest policy to the store, if it's already available. | 396 // Send the latest policy to the store, if it's already available. |
397 if (initial_policy) | 397 if (initial_policy) |
398 store->SetCurrentPolicy(*initial_policy, notify_if_changed); | 398 store->SetCurrentPolicy(*initial_policy, notify_if_changed); |
399 | 399 |
400 // And finally resume from where this process started. | 400 // And finally resume from where this process started. |
401 if (!continuation.is_null()) | 401 if (!continuation.is_null()) |
402 continuation.Run(); | 402 continuation.Run(); |
403 } | 403 } |
404 | 404 |
405 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { | 405 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { |
406 policy::ProfilePolicyConnector* connector = | 406 policy::ProfilePolicyConnector* connector = |
407 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | 407 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); |
408 return connector->policy_service(); | 408 return connector->policy_service(); |
409 } | 409 } |
410 | 410 |
411 } // namespace extensions | 411 } // namespace extensions |
OLD | NEW |