OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "sync/engine/cleanup_disabled_types_command.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "sync/internal_api/public/base/model_type.h" | |
10 #include "sync/sessions/sync_session.h" | |
11 #include "sync/sessions/sync_session_context.h" | |
12 #include "sync/syncable/directory.h" | |
13 | |
14 namespace syncer { | |
15 | |
16 CleanupDisabledTypesCommand::CleanupDisabledTypesCommand() {} | |
17 CleanupDisabledTypesCommand::~CleanupDisabledTypesCommand() {} | |
18 | |
19 SyncerError CleanupDisabledTypesCommand::ExecuteImpl( | |
20 sessions::SyncSession* session) { | |
21 // Because a full directory purge is slow, we avoid purging | |
22 // undesired types unless we have reason to believe they were | |
23 // previously enabled. Because purging could theoretically fail on | |
24 // the first sync session (when there's no previous routing info) we | |
25 // pay the full directory scan price once and do a "deep clean" of | |
26 // types that may potentially need cleanup so that we converge to | |
27 // the correct state. | |
28 // | |
29 // in_previous | !in_previous | |
30 // | | |
31 // initial_sync_ended should clean | may have attempted cleanup | |
32 // !initial_sync_ended should clean | may have never been enabled, or | |
33 // | could have been disabled before | |
34 // | initial sync ended and cleanup | |
35 // | may not have happened yet | |
36 // | (failure, browser restart | |
37 // | before another sync session,..) | |
38 | |
39 const ModelTypeSet enabled_types = | |
40 GetRoutingInfoTypes(session->routing_info()); | |
41 | |
42 const ModelTypeSet previous_enabled_types = | |
43 GetRoutingInfoTypes( | |
44 session->context()->previous_session_routing_info()); | |
45 | |
46 ModelTypeSet to_cleanup = Difference(ModelTypeSet::All(), enabled_types); | |
47 | |
48 // If |previous_enabled_types| is non-empty (i.e., not the first | |
49 // sync session), set |to_cleanup| to its intersection with | |
50 // |previous_enabled_types|. | |
51 if (!previous_enabled_types.Empty()) { | |
52 to_cleanup.RetainAll(previous_enabled_types); | |
53 } | |
54 | |
55 DVLOG(1) << "enabled_types = " << ModelTypeSetToString(enabled_types) | |
56 << ", previous_enabled_types = " | |
57 << ModelTypeSetToString(previous_enabled_types) | |
58 << ", to_cleanup = " << ModelTypeSetToString(to_cleanup); | |
59 | |
60 if (to_cleanup.Empty()) | |
61 return SYNCER_OK; | |
62 | |
63 session->context()->directory()->PurgeEntriesWithTypeIn(to_cleanup); | |
64 return SYNCER_OK; | |
65 } | |
66 | |
67 } // namespace syncer | |
OLD | NEW |