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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "chrome/browser/extensions/api/storage/sync_storage_backend.h" | 9 #include "chrome/browser/extensions/api/storage/sync_storage_backend.h" |
10 #include "chrome/browser/sync/glue/sync_start_util.h" | 10 #include "chrome/browser/sync/glue/sync_start_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 static_cast<size_t>(api::storage::sync::MAX_ITEMS)}; | 28 static_cast<size_t>(api::storage::sync::MAX_ITEMS)}; |
29 return limits; | 29 return limits; |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 SyncValueStoreCache::SyncValueStoreCache( | 34 SyncValueStoreCache::SyncValueStoreCache( |
35 const scoped_refptr<ValueStoreFactory>& factory, | 35 const scoped_refptr<ValueStoreFactory>& factory, |
36 const scoped_refptr<SettingsObserverList>& observers, | 36 const scoped_refptr<SettingsObserverList>& observers, |
37 const base::FilePath& profile_path) | 37 const base::FilePath& profile_path) |
38 : initialized_(false) { | 38 : initialized_(false), weak_ptr_factory_(this) { |
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
40 | 40 |
41 // This post is safe since the destructor can only be invoked from the | 41 // This post is safe since the destructor can only be invoked from the |
42 // same message loop, and any potential post of a deletion task must come | 42 // same message loop, and any potential post of a deletion task must come |
43 // after the constructor returns. | 43 // after the constructor returns. |
44 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
45 BrowserThread::FILE, FROM_HERE, | 45 BrowserThread::FILE, FROM_HERE, |
46 base::Bind(&SyncValueStoreCache::InitOnFileThread, | 46 base::Bind(&SyncValueStoreCache::InitOnFileThread, |
47 base::Unretained(this), | 47 base::Unretained(this), |
48 factory, observers, profile_path)); | 48 factory, observers, profile_path)); |
49 } | 49 } |
50 | 50 |
51 SyncValueStoreCache::~SyncValueStoreCache() { | 51 SyncValueStoreCache::~SyncValueStoreCache() { |
52 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 52 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
53 } | 53 } |
54 | 54 |
| 55 base::WeakPtr<SyncValueStoreCache> SyncValueStoreCache::AsWeakPtr() { |
| 56 return weak_ptr_factory_.GetWeakPtr(); |
| 57 } |
| 58 |
55 syncer::SyncableService* SyncValueStoreCache::GetSyncableService( | 59 syncer::SyncableService* SyncValueStoreCache::GetSyncableService( |
56 syncer::ModelType type) const { | 60 syncer::ModelType type) const { |
57 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 61 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
58 DCHECK(initialized_); | 62 DCHECK(initialized_); |
59 | 63 |
60 switch (type) { | 64 switch (type) { |
61 case syncer::APP_SETTINGS: | 65 case syncer::APP_SETTINGS: |
62 return app_backend_.get(); | 66 return app_backend_.get(); |
63 case syncer::EXTENSION_SETTINGS: | 67 case syncer::EXTENSION_SETTINGS: |
64 return extension_backend_.get(); | 68 return extension_backend_.get(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 extension_backend_.reset(new SyncStorageBackend( | 103 extension_backend_.reset(new SyncStorageBackend( |
100 factory, | 104 factory, |
101 GetSyncQuotaLimits(), | 105 GetSyncQuotaLimits(), |
102 observers, | 106 observers, |
103 syncer::EXTENSION_SETTINGS, | 107 syncer::EXTENSION_SETTINGS, |
104 sync_start_util::GetFlareForSyncableService(profile_path))); | 108 sync_start_util::GetFlareForSyncableService(profile_path))); |
105 initialized_ = true; | 109 initialized_ = true; |
106 } | 110 } |
107 | 111 |
108 } // namespace extensions | 112 } // namespace extensions |
OLD | NEW |