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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/password_manager/password_store_change.h"
13 #include "sync/api/sync_change.h"
14 #include "sync/api/sync_data.h"
15 #include "sync/api/sync_error.h"
16 #include "sync/api/syncable_service.h"
17 #include "sync/protocol/password_specifics.pb.h"
18 #include "sync/protocol/sync.pb.h"
25 class SyncErrorFactory;
30 class PasswordSyncableService : public syncer::SyncableService {
32 // TODO(lipalani) - The |PasswordStore| should outlive
33 // |PasswordSyncableService| and there should be a code
34 // guarantee to that effect. Currently this object is not instantiated.
35 // When this class is completed and instantiated the object lifetime
36 // guarantee will be implemented.
37 explicit PasswordSyncableService(
38 scoped_refptr<PasswordStore> password_store);
39 virtual ~PasswordSyncableService();
41 // syncer::SyncableServiceImplementations
42 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
43 syncer::ModelType type,
44 const syncer::SyncDataList& initial_sync_data,
45 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
46 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
47 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
48 virtual syncer::SyncDataList GetAllSyncData(
49 syncer::ModelType type) const OVERRIDE;
50 virtual syncer::SyncError ProcessSyncChanges(
51 const tracked_objects::Location& from_here,
52 const syncer::SyncChangeList& change_list) OVERRIDE;
54 // Notifies sync of changes to the password database.
55 void ActOnPasswordStoreChanges(const PasswordStoreChangeList& changes);
57 // Returns the unique tag that will serve as the sync identifier for the
59 static std::string MakeTag(const autofill::PasswordForm& password);
60 static std::string MakeTag(const sync_pb::PasswordSpecificsData& password);
61 static std::string MakeTag(const std::string& origin_url,
62 const std::string& username_element,
63 const std::string& username_value,
64 const std::string& password_element,
65 const std::string& signon_realm);
68 typedef std::vector<autofill::PasswordForm*> PasswordForms;
70 // Use the |PasswordStore| APIs to add and update entries.
71 void WriteToPasswordStore(PasswordForms* new_entries,
72 PasswordForms* udpated_entries);
74 // Converts the |PasswordForm| to |SyncData| suitable for syncing.
75 syncer::SyncData CreateSyncData(const autofill::PasswordForm& password);
77 // The factory that creates sync errors. |SyncError| has rich data
78 // suitable for debugging.
79 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
81 // |SyncProcessor| will mirror the |PasswordStore| changes in the sync db.
82 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
84 // The password store that adds/updates/deletes password entries.
85 scoped_refptr<PasswordStore> password_store_;
88 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_SYNCABLE_SERVICE_H__