summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/delete_directive_handler.h
blob: 31ed47ee0ae5966565bdda2263c8081dfd3ff5fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_HISTORY_DELETE_DIRECTIVE_HANDLER_H_
#define CHROME_BROWSER_HISTORY_DELETE_DIRECTIVE_HANDLER_H_

#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/threading/thread_checker.h"
#include "sync/api/sync_change_processor.h"
#include "sync/api/sync_data.h"

namespace sync_pb {
class HistoryDeleteDirectiveSpecifics;
}

class HistoryService;

namespace history {

// DeleteDirectiveHandler sends delete directives created locally to sync
// engine to propagate to other clients. It also expires local history entries
// according to given delete directives from server.
class DeleteDirectiveHandler {
 public:
  DeleteDirectiveHandler();
  ~DeleteDirectiveHandler();

  // Start/stop processing delete directives when sync is enabled/disabled.
  void Start(HistoryService* history_service,
             const syncer::SyncDataList& initial_sync_data,
             scoped_ptr<syncer::SyncChangeProcessor> sync_processor);
  void Stop();

  // Create delete directives for the deletion of visits identified by
  // |global_ids| (which may be empty), in the time range specified by
  // |begin_time| and |end_time|.
  bool CreateDeleteDirectives(
      const std::set<int64>& global_ids,
      base::Time begin_time,
      base::Time end_time);

  // Sends the given |delete_directive| to SyncChangeProcessor (if it exists).
  // Returns any error resulting from sending the delete directive to sync.
  // NOTE: the given |delete_directive| is not processed to remove local
  //       history entries that match. Caller still needs to call other
  //       interfaces, e.g. HistoryService::ExpireHistoryBetween(), to delete
  //       local history entries.
  syncer::SyncError ProcessLocalDeleteDirective(
      const sync_pb::HistoryDeleteDirectiveSpecifics& delete_directive);

  // Expires local history entries according to delete directives from server.
  syncer::SyncError ProcessSyncChanges(
      HistoryService* history_service,
      const syncer::SyncChangeList& change_list);

 private:
  class DeleteDirectiveTask;
  friend class DeleteDirectiveTask;

  // Action to take on processed delete directives.
  enum PostProcessingAction {
    KEEP_AFTER_PROCESSING,
    DROP_AFTER_PROCESSING
  };

  // Callback when history backend finishes deleting visits according to
  // |delete_directives|.
  void FinishProcessing(PostProcessingAction post_processing_action,
                        const syncer::SyncDataList& delete_directives);

  base::CancelableTaskTracker internal_tracker_;
  scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
  base::ThreadChecker thread_checker_;
  base::WeakPtrFactory<DeleteDirectiveHandler> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(DeleteDirectiveHandler);
};

}  // namespace history

#endif  // CHROME_BROWSER_HISTORY_DELETE_DIRECTIVE_HANDLER_H_