Chromium Code Reviews| 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/sync_or_local_value_store_cache. h" | 5 #include "chrome/browser/extensions/api/storage/sync_or_local_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" |
| 11 #include "chrome/browser/extensions/api/storage/settings_backend.h" | 11 #include "chrome/browser/extensions/api/storage/local_storage_backend.h" |
| 12 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 12 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
| 13 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer. h" | 13 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer. h" |
| 14 #include "chrome/browser/extensions/api/storage/sync_storage_backend.h" | |
| 14 #include "chrome/browser/extensions/api/storage/weak_unlimited_settings_storage. h" | 15 #include "chrome/browser/extensions/api/storage/weak_unlimited_settings_storage. h" |
| 15 #include "chrome/browser/sync/glue/sync_start_util.h" | 16 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/permissions/api_permission.h" | 20 #include "extensions/common/permissions/api_permission.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 40 BrowserThread::FILE, FROM_HERE, | 41 BrowserThread::FILE, FROM_HERE, |
| 41 base::Bind(&SyncOrLocalValueStoreCache::InitOnFileThread, | 42 base::Bind(&SyncOrLocalValueStoreCache::InitOnFileThread, |
| 42 base::Unretained(this), | 43 base::Unretained(this), |
| 43 factory, quota, observers, profile_path)); | 44 factory, quota, observers, profile_path)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 SyncOrLocalValueStoreCache::~SyncOrLocalValueStoreCache() { | 47 SyncOrLocalValueStoreCache::~SyncOrLocalValueStoreCache() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 48 } | 49 } |
| 49 | 50 |
| 50 SettingsBackend* SyncOrLocalValueStoreCache::GetAppBackend() const { | 51 syncer::SyncableService* SyncOrLocalValueStoreCache::GetSyncableService( |
| 52 syncer::ModelType type) const { | |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 52 DCHECK(app_backend_.get()); | 54 switch (type) { |
| 53 return app_backend_.get(); | 55 case syncer::APP_SETTINGS: |
| 54 } | 56 DCHECK(app_backend_.get()); |
|
not at google - send to devlin
2014/02/14 19:35:56
all this DCHECK'ing of backends looks weird. Let's
Devlin
2014/02/18 23:55:22
Done.
| |
| 55 | 57 return app_backend_->GetAsSyncableService(); |
| 56 SettingsBackend* SyncOrLocalValueStoreCache::GetExtensionBackend() const { | 58 case syncer::EXTENSION_SETTINGS: |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 59 DCHECK(extension_backend_.get()); |
| 58 DCHECK(extension_backend_.get()); | 60 return extension_backend_->GetAsSyncableService(); |
| 59 return extension_backend_.get(); | 61 default: |
| 62 NOTREACHED(); | |
| 63 return NULL; | |
| 64 } | |
| 60 } | 65 } |
| 61 | 66 |
| 62 void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension( | 67 void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension( |
| 63 const StorageCallback& callback, | 68 const StorageCallback& callback, |
| 64 scoped_refptr<const Extension> extension) { | 69 scoped_refptr<const Extension> extension) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 66 DCHECK(app_backend_.get()); | 71 DCHECK(app_backend_.get()); |
| 67 DCHECK(extension_backend_.get()); | 72 DCHECK(extension_backend_.get()); |
| 68 SettingsBackend* backend = | 73 SettingsBackend* backend = |
| 69 extension->is_app() ? app_backend_.get() : extension_backend_.get(); | 74 extension->is_app() ? app_backend_.get() : extension_backend_.get(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 94 } | 99 } |
| 95 | 100 |
| 96 void SyncOrLocalValueStoreCache::InitOnFileThread( | 101 void SyncOrLocalValueStoreCache::InitOnFileThread( |
| 97 const scoped_refptr<SettingsStorageFactory>& factory, | 102 const scoped_refptr<SettingsStorageFactory>& factory, |
| 98 const SettingsStorageQuotaEnforcer::Limits& quota, | 103 const SettingsStorageQuotaEnforcer::Limits& quota, |
| 99 const scoped_refptr<SettingsObserverList>& observers, | 104 const scoped_refptr<SettingsObserverList>& observers, |
| 100 const base::FilePath& profile_path) { | 105 const base::FilePath& profile_path) { |
| 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 102 DCHECK(!app_backend_.get()); | 107 DCHECK(!app_backend_.get()); |
| 103 DCHECK(!extension_backend_.get()); | 108 DCHECK(!extension_backend_.get()); |
| 104 const bool local = settings_namespace_ == settings_namespace::LOCAL; | 109 const bool local = settings_namespace_ == settings_namespace::LOCAL; |
|
not at google - send to devlin
2014/02/14 19:35:56
use switch
Devlin
2014/02/18 23:55:22
Done.
| |
| 105 const base::FilePath app_path = profile_path.AppendASCII( | 110 if (local) { |
| 106 local ? extensions::kLocalAppSettingsDirectoryName | 111 app_backend_.reset(new LocalStorageBackend( |
| 107 : extensions::kSyncAppSettingsDirectoryName); | 112 factory, |
| 108 const base::FilePath extension_path = profile_path.AppendASCII( | 113 profile_path.AppendASCII(kLocalAppSettingsDirectoryName), |
| 109 local ? extensions::kLocalExtensionSettingsDirectoryName | 114 quota)); |
| 110 : extensions::kSyncExtensionSettingsDirectoryName); | 115 extension_backend_.reset(new LocalStorageBackend( |
| 111 app_backend_.reset(new SettingsBackend( | 116 factory, |
| 112 factory, app_path, syncer::APP_SETTINGS, | 117 profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName), |
| 113 sync_start_util::GetFlareForSyncableService(profile_path), | 118 quota)); |
| 114 quota, observers)); | 119 } else { |
| 115 extension_backend_.reset(new SettingsBackend( | 120 app_backend_.reset(new SyncStorageBackend( |
| 116 factory, extension_path, syncer::EXTENSION_SETTINGS, | 121 factory, |
| 117 sync_start_util::GetFlareForSyncableService(profile_path), | 122 profile_path.AppendASCII(kSyncAppSettingsDirectoryName), |
| 118 quota, observers)); | 123 quota, |
| 124 observers, | |
| 125 syncer::APP_SETTINGS, | |
| 126 sync_start_util::GetFlareForSyncableService(profile_path))); | |
| 127 extension_backend_.reset(new SyncStorageBackend( | |
| 128 factory, | |
| 129 profile_path.AppendASCII(kSyncExtensionSettingsDirectoryName), | |
| 130 quota, | |
| 131 observers, | |
| 132 syncer::EXTENSION_SETTINGS, | |
| 133 sync_start_util::GetFlareForSyncableService(profile_path))); | |
| 134 } | |
| 119 } | 135 } |
| 120 | 136 |
| 121 } // namespace extensions | 137 } // namespace extensions |
| OLD | NEW |