1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ 73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/sync/glue/change_processor.h" 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h" 12ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/compiler_specific.h" 13ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "chrome/browser/sync/glue/password_model_associator.h" 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/sync/glue/sync_backend_host.h" 15ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "content/common/notification_observer.h" 16ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "content/common/notification_registrar.h" 17ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "content/common/notification_type.h" 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PasswordStore; 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass MessageLoop; 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NotificationService; 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace browser_sync { 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass UnrecoverableErrorHandler; 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This class is responsible for taking changes from the password backend and 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// applying them to the sync_api 'syncable' model, and vice versa. All 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// operations and use of this class are from the DB thread on Windows and Linux, 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// or the password thread on Mac. 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PasswordChangeProcessor : public ChangeProcessor, 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public NotificationObserver { 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PasswordChangeProcessor(PasswordModelAssociator* model_associator, 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PasswordStore* password_store, 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnrecoverableErrorHandler* error_handler); 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ~PasswordChangeProcessor(); 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // NotificationObserver implementation. 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Passwords -> sync_api model change application. 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void Observe(NotificationType type, 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const NotificationSource& source, 43ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const NotificationDetails& details) OVERRIDE; 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // sync_api model -> WebDataService change application. 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void ApplyChangesFromSyncModel( 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const sync_api::BaseTransaction* trans, 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const sync_api::SyncManager::ChangeRecord* changes, 49ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen int change_count) OVERRIDE; 50ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 51ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Commit changes buffered during ApplyChanges. We must commit them to the 52ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // password store only after the sync_api transaction is released, else there 53ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // is risk of deadlock due to the password store posting tasks to the UI 54ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // thread (http://crbug.com/70658). 55ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual void CommitChangesFromSyncModel() OVERRIDE; 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected: 58ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual void StartImpl(Profile* profile) OVERRIDE; 59ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual void StopImpl() OVERRIDE; 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void StartObserving(); 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void StopObserving(); 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The two models should be associated according to this ModelAssociator. 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PasswordModelAssociator* model_associator_; 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The model we are processing changes from. This is owned by the 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // WebDataService which is kept alive by our data type controller 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // holding a reference. 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch PasswordStore* password_store_; 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 73ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // Buffers used between ApplyChangesFromSyncModel and 74ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen // CommitChangesFromSyncModel. 75ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen PasswordModelAssociator::PasswordVector new_passwords_; 76ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen PasswordModelAssociator::PasswordVector updated_passwords_; 77ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen PasswordModelAssociator::PasswordVector deleted_passwords_; 78ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen 79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch NotificationRegistrar notification_registrar_; 80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool observing_; 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch MessageLoop* expected_loop_; 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DISALLOW_COPY_AND_ASSIGN(PasswordChangeProcessor); 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} // namespace browser_sync 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // CHROME_BROWSER_SYNC_GLUE_PASSWORD_CHANGE_PROCESSOR_H_ 91