Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/browser/extensions/api/storage/sync_value_store_cache.cc

Issue 2965153002: Migrate Extensions code to Task Scheduler API (Closed)
Patch Set: Self review Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "extensions/browser/api/storage/backend_task_runner.h"
12 #include "extensions/browser/value_store/value_store_factory.h" 13 #include "extensions/browser/value_store/value_store_factory.h"
13 #include "extensions/common/api/storage.h" 14 #include "extensions/common/api/storage.h"
14 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 namespace { 21 namespace {
21 22
(...skipping 12 matching lines...) Expand all
34 SyncValueStoreCache::SyncValueStoreCache( 35 SyncValueStoreCache::SyncValueStoreCache(
35 const scoped_refptr<ValueStoreFactory>& factory, 36 const scoped_refptr<ValueStoreFactory>& factory,
36 const scoped_refptr<SettingsObserverList>& observers, 37 const scoped_refptr<SettingsObserverList>& observers,
37 const base::FilePath& profile_path) 38 const base::FilePath& profile_path)
38 : initialized_(false) { 39 : initialized_(false) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI); 40 DCHECK_CURRENTLY_ON(BrowserThread::UI);
40 41
41 // This post is safe since the destructor can only be invoked from the 42 // 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 43 // same message loop, and any potential post of a deletion task must come
43 // after the constructor returns. 44 // after the constructor returns.
44 BrowserThread::PostTask( 45 GetBackendTaskRunner()->PostTask(
45 BrowserThread::FILE, FROM_HERE, 46 FROM_HERE,
46 base::BindOnce(&SyncValueStoreCache::InitOnFileThread, 47 base::BindOnce(&SyncValueStoreCache::InitOnBackend,
47 base::Unretained(this), factory, observers, profile_path)); 48 base::Unretained(this), factory, observers, profile_path));
48 } 49 }
49 50
50 SyncValueStoreCache::~SyncValueStoreCache() { 51 SyncValueStoreCache::~SyncValueStoreCache() {
51 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 52 DCHECK(IsOnBackendSequence());
52 } 53 }
53 54
54 syncer::SyncableService* SyncValueStoreCache::GetSyncableService( 55 syncer::SyncableService* SyncValueStoreCache::GetSyncableService(
55 syncer::ModelType type) const { 56 syncer::ModelType type) const {
56 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 57 DCHECK(IsOnBackendSequence());
57 DCHECK(initialized_); 58 DCHECK(initialized_);
58 59
59 switch (type) { 60 switch (type) {
60 case syncer::APP_SETTINGS: 61 case syncer::APP_SETTINGS:
61 return app_backend_.get(); 62 return app_backend_.get();
62 case syncer::EXTENSION_SETTINGS: 63 case syncer::EXTENSION_SETTINGS:
63 return extension_backend_.get(); 64 return extension_backend_.get();
64 default: 65 default:
65 NOTREACHED(); 66 NOTREACHED();
66 return NULL; 67 return NULL;
67 } 68 }
68 } 69 }
69 70
70 void SyncValueStoreCache::RunWithValueStoreForExtension( 71 void SyncValueStoreCache::RunWithValueStoreForExtension(
71 const StorageCallback& callback, 72 const StorageCallback& callback,
72 scoped_refptr<const Extension> extension) { 73 scoped_refptr<const Extension> extension) {
73 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 74 DCHECK(IsOnBackendSequence());
74 DCHECK(initialized_); 75 DCHECK(initialized_);
75 SyncStorageBackend* backend = 76 SyncStorageBackend* backend =
76 extension->is_app() ? app_backend_.get() : extension_backend_.get(); 77 extension->is_app() ? app_backend_.get() : extension_backend_.get();
77 callback.Run(backend->GetStorage(extension->id())); 78 callback.Run(backend->GetStorage(extension->id()));
78 } 79 }
79 80
80 void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { 81 void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
81 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 82 DCHECK(IsOnBackendSequence());
82 app_backend_->DeleteStorage(extension_id); 83 app_backend_->DeleteStorage(extension_id);
83 extension_backend_->DeleteStorage(extension_id); 84 extension_backend_->DeleteStorage(extension_id);
84 } 85 }
85 86
86 void SyncValueStoreCache::InitOnFileThread( 87 void SyncValueStoreCache::InitOnBackend(
87 const scoped_refptr<ValueStoreFactory>& factory, 88 const scoped_refptr<ValueStoreFactory>& factory,
88 const scoped_refptr<SettingsObserverList>& observers, 89 const scoped_refptr<SettingsObserverList>& observers,
89 const base::FilePath& profile_path) { 90 const base::FilePath& profile_path) {
90 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 91 DCHECK(IsOnBackendSequence());
91 DCHECK(!initialized_); 92 DCHECK(!initialized_);
92 app_backend_.reset(new SyncStorageBackend( 93 app_backend_.reset(new SyncStorageBackend(
93 factory, 94 factory,
94 GetSyncQuotaLimits(), 95 GetSyncQuotaLimits(),
95 observers, 96 observers,
96 syncer::APP_SETTINGS, 97 syncer::APP_SETTINGS,
97 sync_start_util::GetFlareForSyncableService(profile_path))); 98 sync_start_util::GetFlareForSyncableService(profile_path)));
98 extension_backend_.reset(new SyncStorageBackend( 99 extension_backend_.reset(new SyncStorageBackend(
99 factory, 100 factory,
100 GetSyncQuotaLimits(), 101 GetSyncQuotaLimits(),
101 observers, 102 observers,
102 syncer::EXTENSION_SETTINGS, 103 syncer::EXTENSION_SETTINGS,
103 sync_start_util::GetFlareForSyncableService(profile_path))); 104 sync_start_util::GetFlareForSyncableService(profile_path)));
104 initialized_ = true; 105 initialized_ = true;
105 } 106 }
106 107
107 } // namespace extensions 108 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698