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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/sync_engine.cc

Issue 288193002: [SyncFS] Construct and destruct sync_worker in worker_task_runner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work for a nit, from offline chat Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/sync_worker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sync_file_system/drive_backend/sync_engine.h" 5 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 factories->insert( 198 factories->insert(
199 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 199 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
200 } 200 }
201 201
202 SyncEngine::~SyncEngine() { 202 SyncEngine::~SyncEngine() {
203 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 203 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
204 GetDriveService()->RemoveObserver(this); 204 GetDriveService()->RemoveObserver(this);
205 if (notification_manager_) 205 if (notification_manager_)
206 notification_manager_->RemoveObserver(this); 206 notification_manager_->RemoveObserver(this);
207 207
208 // TODO(tzik): Destroy |sync_worker_| and |worker_observer_| on the worker. 208 WorkerObserver* worker_observer = worker_observer_.release();
209 if (!worker_task_runner_->DeleteSoon(FROM_HERE, worker_observer))
210 delete worker_observer;
211
212 SyncWorker* sync_worker = sync_worker_.release();
213 if (!worker_task_runner_->DeleteSoon(FROM_HERE, sync_worker))
214 delete sync_worker;
209 } 215 }
210 216
211 void SyncEngine::Initialize(const base::FilePath& base_dir, 217 void SyncEngine::Initialize(const base::FilePath& base_dir,
212 base::SequencedTaskRunner* file_task_runner, 218 base::SequencedTaskRunner* file_task_runner,
213 leveldb::Env* env_override) { 219 leveldb::Env* env_override) {
214 // DriveServiceWrapper and DriveServiceOnWorker relay communications 220 // DriveServiceWrapper and DriveServiceOnWorker relay communications
215 // between DriveService and syncers in SyncWorker. 221 // between DriveService and syncers in SyncWorker.
216 scoped_ptr<drive::DriveServiceInterface> 222 scoped_ptr<drive::DriveServiceInterface>
217 drive_service_on_worker( 223 drive_service_on_worker(
218 new DriveServiceOnWorker(drive_service_wrapper_->AsWeakPtr(), 224 new DriveServiceOnWorker(drive_service_wrapper_->AsWeakPtr(),
(...skipping 13 matching lines...) Expand all
232 file_task_runner)); 238 file_task_runner));
233 239
234 worker_observer_.reset( 240 worker_observer_.reset(
235 new WorkerObserver(base::MessageLoopProxy::current(), 241 new WorkerObserver(base::MessageLoopProxy::current(),
236 weak_ptr_factory_.GetWeakPtr())); 242 weak_ptr_factory_.GetWeakPtr()));
237 243
238 base::WeakPtr<ExtensionServiceInterface> extension_service_weak_ptr; 244 base::WeakPtr<ExtensionServiceInterface> extension_service_weak_ptr;
239 if (extension_service_) 245 if (extension_service_)
240 extension_service_weak_ptr = extension_service_->AsWeakPtr(); 246 extension_service_weak_ptr = extension_service_->AsWeakPtr();
241 247
242 // TODO(peria): Use PostTask on |worker_task_runner_| to call this function. 248 sync_worker_.reset(new SyncWorker(
243 sync_worker_ = SyncWorker::CreateOnWorker(
244 base_dir, 249 base_dir,
245 worker_observer_.get(),
246 extension_service_weak_ptr, 250 extension_service_weak_ptr,
247 sync_engine_context.Pass(), 251 sync_engine_context.Pass(),
248 env_override); 252 env_override));
253 sync_worker_->AddObserver(worker_observer_.get());
254 worker_task_runner_->PostTask(
255 FROM_HERE,
256 base::Bind(&SyncWorker::Initialize,
257 base::Unretained(sync_worker_.get())));
249 258
250 if (notification_manager_) 259 if (notification_manager_)
251 notification_manager_->AddObserver(this); 260 notification_manager_->AddObserver(this);
252 GetDriveService()->AddObserver(this); 261 GetDriveService()->AddObserver(this);
253 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 262 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
254 } 263 }
255 264
256 void SyncEngine::AddServiceObserver(SyncServiceObserver* observer) { 265 void SyncEngine::AddServiceObserver(SyncServiceObserver* observer) {
257 service_observers_.AddObserver(observer); 266 service_observers_.AddObserver(observer);
258 } 267 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 tracker.tracker_kind() == TRACKER_KIND_APP_ROOT; 549 tracker.tracker_kind() == TRACKER_KIND_APP_ROOT;
541 if (is_app_enabled && !is_app_root_tracker_enabled) 550 if (is_app_enabled && !is_app_root_tracker_enabled)
542 EnableOrigin(origin, base::Bind(&EmptyStatusCallback)); 551 EnableOrigin(origin, base::Bind(&EmptyStatusCallback));
543 else if (!is_app_enabled && is_app_root_tracker_enabled) 552 else if (!is_app_enabled && is_app_root_tracker_enabled)
544 DisableOrigin(origin, base::Bind(&EmptyStatusCallback)); 553 DisableOrigin(origin, base::Bind(&EmptyStatusCallback));
545 } 554 }
546 } 555 }
547 556
548 } // namespace drive_backend 557 } // namespace drive_backend
549 } // namespace sync_file_system 558 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/sync_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698