| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_value_store_cache.h" | 5 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 return limits; | 34 return limits; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 SyncValueStoreCache::SyncValueStoreCache( | 39 SyncValueStoreCache::SyncValueStoreCache( |
| 40 const scoped_refptr<SettingsStorageFactory>& factory, | 40 const scoped_refptr<SettingsStorageFactory>& factory, |
| 41 const scoped_refptr<SettingsObserverList>& observers, | 41 const scoped_refptr<SettingsObserverList>& observers, |
| 42 const base::FilePath& profile_path) | 42 const base::FilePath& profile_path) |
| 43 : initialized_(false) { | 43 : initialized_(false) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 45 | 45 |
| 46 // This post is safe since the destructor can only be invoked from the | 46 // This post is safe since the destructor can only be invoked from the |
| 47 // same message loop, and any potential post of a deletion task must come | 47 // same message loop, and any potential post of a deletion task must come |
| 48 // after the constructor returns. | 48 // after the constructor returns. |
| 49 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
| 50 BrowserThread::FILE, FROM_HERE, | 50 BrowserThread::FILE, FROM_HERE, |
| 51 base::Bind(&SyncValueStoreCache::InitOnFileThread, | 51 base::Bind(&SyncValueStoreCache::InitOnFileThread, |
| 52 base::Unretained(this), | 52 base::Unretained(this), |
| 53 factory, observers, profile_path)); | 53 factory, observers, profile_path)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 SyncValueStoreCache::~SyncValueStoreCache() { | 56 SyncValueStoreCache::~SyncValueStoreCache() { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 57 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 58 } | 58 } |
| 59 | 59 |
| 60 syncer::SyncableService* SyncValueStoreCache::GetSyncableService( | 60 syncer::SyncableService* SyncValueStoreCache::GetSyncableService( |
| 61 syncer::ModelType type) const { | 61 syncer::ModelType type) const { |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 62 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 63 DCHECK(initialized_); | 63 DCHECK(initialized_); |
| 64 | 64 |
| 65 switch (type) { | 65 switch (type) { |
| 66 case syncer::APP_SETTINGS: | 66 case syncer::APP_SETTINGS: |
| 67 return app_backend_.get(); | 67 return app_backend_.get(); |
| 68 case syncer::EXTENSION_SETTINGS: | 68 case syncer::EXTENSION_SETTINGS: |
| 69 return extension_backend_.get(); | 69 return extension_backend_.get(); |
| 70 default: | 70 default: |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 return NULL; | 72 return NULL; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void SyncValueStoreCache::RunWithValueStoreForExtension( | 76 void SyncValueStoreCache::RunWithValueStoreForExtension( |
| 77 const StorageCallback& callback, | 77 const StorageCallback& callback, |
| 78 scoped_refptr<const Extension> extension) { | 78 scoped_refptr<const Extension> extension) { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 79 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 80 DCHECK(initialized_); | 80 DCHECK(initialized_); |
| 81 SyncStorageBackend* backend = | 81 SyncStorageBackend* backend = |
| 82 extension->is_app() ? app_backend_.get() : extension_backend_.get(); | 82 extension->is_app() ? app_backend_.get() : extension_backend_.get(); |
| 83 callback.Run(backend->GetStorage(extension->id())); | 83 callback.Run(backend->GetStorage(extension->id())); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { | 86 void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 87 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 88 app_backend_->DeleteStorage(extension_id); | 88 app_backend_->DeleteStorage(extension_id); |
| 89 extension_backend_->DeleteStorage(extension_id); | 89 extension_backend_->DeleteStorage(extension_id); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void SyncValueStoreCache::InitOnFileThread( | 92 void SyncValueStoreCache::InitOnFileThread( |
| 93 const scoped_refptr<SettingsStorageFactory>& factory, | 93 const scoped_refptr<SettingsStorageFactory>& factory, |
| 94 const scoped_refptr<SettingsObserverList>& observers, | 94 const scoped_refptr<SettingsObserverList>& observers, |
| 95 const base::FilePath& profile_path) { | 95 const base::FilePath& profile_path) { |
| 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 96 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 97 DCHECK(!initialized_); | 97 DCHECK(!initialized_); |
| 98 app_backend_.reset(new SyncStorageBackend( | 98 app_backend_.reset(new SyncStorageBackend( |
| 99 factory, | 99 factory, |
| 100 profile_path.AppendASCII(kSyncAppSettingsDirectoryName), | 100 profile_path.AppendASCII(kSyncAppSettingsDirectoryName), |
| 101 GetSyncQuotaLimits(), | 101 GetSyncQuotaLimits(), |
| 102 observers, | 102 observers, |
| 103 syncer::APP_SETTINGS, | 103 syncer::APP_SETTINGS, |
| 104 sync_start_util::GetFlareForSyncableService(profile_path))); | 104 sync_start_util::GetFlareForSyncableService(profile_path))); |
| 105 extension_backend_.reset(new SyncStorageBackend( | 105 extension_backend_.reset(new SyncStorageBackend( |
| 106 factory, | 106 factory, |
| 107 profile_path.AppendASCII(kSyncExtensionSettingsDirectoryName), | 107 profile_path.AppendASCII(kSyncExtensionSettingsDirectoryName), |
| 108 GetSyncQuotaLimits(), | 108 GetSyncQuotaLimits(), |
| 109 observers, | 109 observers, |
| 110 syncer::EXTENSION_SETTINGS, | 110 syncer::EXTENSION_SETTINGS, |
| 111 sync_start_util::GetFlareForSyncableService(profile_path))); | 111 sync_start_util::GetFlareForSyncableService(profile_path))); |
| 112 initialized_ = true; | 112 initialized_ = true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace extensions | 115 } // namespace extensions |
| OLD | NEW |