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