1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_DATA_TYPE_CONTROLLER_H__ 6 #define CHROME_BROWSER_SYNC_GLUE_PASSWORD_DATA_TYPE_CONTROLLER_H__ 7 #pragma once 8 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "base/synchronization/waitable_event.h" 14 #include "chrome/browser/sync/profile_sync_service.h" 15 #include "chrome/browser/sync/glue/data_type_controller.h" 16 17 class PasswordStore; 18 class Profile; 19 class ProfileSyncFactory; 20 class ProfileSyncService; 21 22 namespace browser_sync { 23 24 class AssociatorInterface; 25 class ChangeProcessor; 26 class ControlTask; 27 28 // A class that manages the startup and shutdown of password sync. 29 class PasswordDataTypeController : public DataTypeController { 30 public: 31 PasswordDataTypeController( 32 ProfileSyncFactory* profile_sync_factory, 33 Profile* profile, 34 ProfileSyncService* sync_service); 35 virtual ~PasswordDataTypeController(); 36 37 // DataTypeController implementation 38 virtual void Start(StartCallback* start_callback); 39 40 virtual void Stop(); 41 42 virtual bool enabled(); 43 44 virtual syncable::ModelType type() const; 45 46 virtual browser_sync::ModelSafeGroup model_safe_group() const; 47 48 virtual std::string name() const; 49 50 virtual State state() const; 51 52 // UnrecoverableHandler implementation 53 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, 54 const std::string& message); 55 56 private: 57 void StartImpl(); 58 void StartDone(StartResult result, State state); 59 void StartDoneImpl(StartResult result, State state); 60 void StopImpl(); 61 void StartFailed(StartResult result); 62 void OnUnrecoverableErrorImpl(const tracked_objects::Location& from_here, 63 const std::string& message); 64 65 void set_state(State state) { 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 state_ = state; 68 } 69 70 ProfileSyncFactory* profile_sync_factory_; 71 Profile* profile_; 72 ProfileSyncService* sync_service_; 73 State state_; 74 75 scoped_ptr<AssociatorInterface> model_associator_; 76 scoped_ptr<ChangeProcessor> change_processor_; 77 scoped_ptr<StartCallback> start_callback_; 78 scoped_refptr<PasswordStore> password_store_; 79 80 base::Lock abort_association_lock_; 81 bool abort_association_; 82 base::WaitableEvent abort_association_complete_; 83 84 // Barrier to ensure that the datatype has been stopped on the DB thread 85 // from the UI thread. 86 base::WaitableEvent datatype_stopped_; 87 88 DISALLOW_COPY_AND_ASSIGN(PasswordDataTypeController); 89 }; 90 91 } // namespace browser_sync 92 93 #endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_DATA_TYPE_CONTROLLER_H__ 94