summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/history_backend_android.cc
blob: 0e823a1cce86abd9726e76a623c538e424700490 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) 2012 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.

#include "chrome/browser/history/history_backend.h"

#include "chrome/browser/history/android/android_provider_backend.h"

namespace history {

void HistoryBackend::InsertHistoryAndBookmark(
    scoped_refptr<InsertRequest> request,
    const HistoryAndBookmarkRow& row) {
  if (request->canceled())
    return;

  AndroidURLID id = 0;
  if (android_provider_backend_)
    id = android_provider_backend_->InsertHistoryAndBookmark(row);

  request->ForwardResult(request->handle(), id != 0, id);
}

void HistoryBackend::QueryHistoryAndBookmarks(
    scoped_refptr<QueryRequest> request,
    const std::vector<HistoryAndBookmarkRow::ColumnID>& projections,
    const std::string& selection,
    const std::vector<string16>& selection_args,
    const std::string& sort_order) {
  if (request->canceled())
    return;

  AndroidStatement* statement = NULL;
  if (android_provider_backend_) {
    statement = android_provider_backend_->QueryHistoryAndBookmarks(
        projections, selection, selection_args, sort_order);
  }
  request->ForwardResult(request->handle(), statement, statement);
}

void HistoryBackend::UpdateHistoryAndBookmarks(
    scoped_refptr<UpdateRequest> request,
    const HistoryAndBookmarkRow& row,
    const std::string& selection,
    const std::vector<string16>& selection_args) {
  if (request->canceled())
    return;

  int count = 0;
  bool result = false;
  if (android_provider_backend_) {
    result = android_provider_backend_->UpdateHistoryAndBookmarks(row,
        selection, selection_args, &count);
  }

  request->ForwardResult(request->handle(), result, count);
}

void HistoryBackend::DeleteHistoryAndBookmarks(
    scoped_refptr<DeleteRequest> request,
    const std::string& selection,
    const std::vector<string16>& selection_args) {
  if (request->canceled())
    return;

  int count = 0;
  bool result = false;
  if (android_provider_backend_)
    result = android_provider_backend_->DeleteHistoryAndBookmarks(selection,
        selection_args, &count);

  request->ForwardResult(request->handle(), result, count);
}

void HistoryBackend::DeleteHistory(
    scoped_refptr<DeleteRequest> request,
    const std::string& selection,
    const std::vector<string16>& selection_args) {
  if (request->canceled())
    return;

  int count = 0;
  bool result = false;
  if (android_provider_backend_) {
    result = android_provider_backend_->DeleteHistory(selection, selection_args,
                                                      &count);
  }
  request->ForwardResult(request->handle(), result, count);
}

// Statement -------------------------------------------------------------------

void HistoryBackend::MoveStatement(
    scoped_refptr<MoveStatementRequest> request,
    history::AndroidStatement* statement,
    int current_pos,
    int destination) {
  DCHECK_LE(-1, current_pos);
  DCHECK_LE(-1, destination);

  int cur = current_pos;
  if (current_pos > destination) {
    statement->statement()->Reset(false);
    cur = -1;
  }
  for (; cur < destination; ++cur) {
    if (!statement->statement()->Step())
      break;
  }

  request->ForwardResult(request->handle(), cur);
}

void HistoryBackend::CloseStatement(AndroidStatement* statement) {
  delete statement;
}

// Search Term -----------------------------------------------------------------

void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request,
                                      const SearchRow& row) {
  if (request->canceled())
    return;

  SearchTermID id = 0;
  if (android_provider_backend_)
    id = android_provider_backend_->InsertSearchTerm(row);

  request->ForwardResult(request->handle(), id != 0, id);
}

void HistoryBackend::UpdateSearchTerms(
    scoped_refptr<UpdateRequest> request,
    const SearchRow& row,
    const std::string& selection,
    const std::vector<string16> selection_args) {
  if (request->canceled())
    return;

  int count = 0;
  bool result = false;
  if (android_provider_backend_) {
    result =  android_provider_backend_->UpdateSearchTerms(row, selection,
        selection_args, &count);
  }
  request->ForwardResult(request->handle(), result, count);
}

void HistoryBackend::DeleteSearchTerms(
    scoped_refptr<DeleteRequest> request,
    const std::string& selection,
    const std::vector<string16> selection_args) {
  if (request->canceled())
    return;

  int count = 0;
  bool result = false;
  if (android_provider_backend_) {
    result = android_provider_backend_->DeleteSearchTerms(selection,
        selection_args, &count);
  }

  request->ForwardResult(request->handle(), result, count);
}

void HistoryBackend::QuerySearchTerms(
    scoped_refptr<QueryRequest> request,
    const std::vector<SearchRow::ColumnID>& projections,
    const std::string& selection,
    const std::vector<string16>& selection_args,
    const std::string& sort_order) {
  if (request->canceled())
    return;

  AndroidStatement* statement = NULL;
  if (android_provider_backend_)
    statement = android_provider_backend_->QuerySearchTerms(projections,
        selection, selection_args, sort_order);

  request->ForwardResult(request->handle(), statement, statement);
}

}  // namespace history