Home | History | Annotate | Download | only in history
      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 "chrome/browser/history/history_backend.h"
      6 
      7 #include "chrome/browser/history/android/android_provider_backend.h"
      8 
      9 namespace history {
     10 
     11 void HistoryBackend::InsertHistoryAndBookmark(
     12     scoped_refptr<InsertRequest> request,
     13     const HistoryAndBookmarkRow& row) {
     14   if (request->canceled())
     15     return;
     16 
     17   AndroidURLID id = 0;
     18   if (android_provider_backend_)
     19     id = android_provider_backend_->InsertHistoryAndBookmark(row);
     20 
     21   request->ForwardResult(request->handle(), id != 0, id);
     22 }
     23 
     24 void HistoryBackend::QueryHistoryAndBookmarks(
     25     scoped_refptr<QueryRequest> request,
     26     const std::vector<HistoryAndBookmarkRow::ColumnID>& projections,
     27     const std::string& selection,
     28     const std::vector<string16>& selection_args,
     29     const std::string& sort_order) {
     30   if (request->canceled())
     31     return;
     32 
     33   AndroidStatement* statement = NULL;
     34   if (android_provider_backend_) {
     35     statement = android_provider_backend_->QueryHistoryAndBookmarks(
     36         projections, selection, selection_args, sort_order);
     37   }
     38   request->ForwardResult(request->handle(), statement, statement);
     39 }
     40 
     41 void HistoryBackend::UpdateHistoryAndBookmarks(
     42     scoped_refptr<UpdateRequest> request,
     43     const HistoryAndBookmarkRow& row,
     44     const std::string& selection,
     45     const std::vector<string16>& selection_args) {
     46   if (request->canceled())
     47     return;
     48 
     49   int count = 0;
     50   bool result = false;
     51   if (android_provider_backend_) {
     52     result = android_provider_backend_->UpdateHistoryAndBookmarks(row,
     53         selection, selection_args, &count);
     54   }
     55 
     56   request->ForwardResult(request->handle(), result, count);
     57 }
     58 
     59 void HistoryBackend::DeleteHistoryAndBookmarks(
     60     scoped_refptr<DeleteRequest> request,
     61     const std::string& selection,
     62     const std::vector<string16>& selection_args) {
     63   if (request->canceled())
     64     return;
     65 
     66   int count = 0;
     67   bool result = false;
     68   if (android_provider_backend_)
     69     result = android_provider_backend_->DeleteHistoryAndBookmarks(selection,
     70         selection_args, &count);
     71 
     72   request->ForwardResult(request->handle(), result, count);
     73 }
     74 
     75 void HistoryBackend::DeleteHistory(
     76     scoped_refptr<DeleteRequest> request,
     77     const std::string& selection,
     78     const std::vector<string16>& selection_args) {
     79   if (request->canceled())
     80     return;
     81 
     82   int count = 0;
     83   bool result = false;
     84   if (android_provider_backend_) {
     85     result = android_provider_backend_->DeleteHistory(selection, selection_args,
     86                                                       &count);
     87   }
     88   request->ForwardResult(request->handle(), result, count);
     89 }
     90 
     91 // Statement -------------------------------------------------------------------
     92 
     93 void HistoryBackend::MoveStatement(
     94     scoped_refptr<MoveStatementRequest> request,
     95     history::AndroidStatement* statement,
     96     int current_pos,
     97     int destination) {
     98   DCHECK_LE(-1, current_pos);
     99   DCHECK_LE(-1, destination);
    100 
    101   int cur = current_pos;
    102   if (current_pos > destination) {
    103     statement->statement()->Reset(false);
    104     cur = -1;
    105   }
    106   for (; cur < destination; ++cur) {
    107     if (!statement->statement()->Step())
    108       break;
    109   }
    110 
    111   request->ForwardResult(request->handle(), cur);
    112 }
    113 
    114 void HistoryBackend::CloseStatement(AndroidStatement* statement) {
    115   delete statement;
    116 }
    117 
    118 // Search Term -----------------------------------------------------------------
    119 
    120 void HistoryBackend::InsertSearchTerm(scoped_refptr<InsertRequest> request,
    121                                       const SearchRow& row) {
    122   if (request->canceled())
    123     return;
    124 
    125   SearchTermID id = 0;
    126   if (android_provider_backend_)
    127     id = android_provider_backend_->InsertSearchTerm(row);
    128 
    129   request->ForwardResult(request->handle(), id != 0, id);
    130 }
    131 
    132 void HistoryBackend::UpdateSearchTerms(
    133     scoped_refptr<UpdateRequest> request,
    134     const SearchRow& row,
    135     const std::string& selection,
    136     const std::vector<string16> selection_args) {
    137   if (request->canceled())
    138     return;
    139 
    140   int count = 0;
    141   bool result = false;
    142   if (android_provider_backend_) {
    143     result =  android_provider_backend_->UpdateSearchTerms(row, selection,
    144         selection_args, &count);
    145   }
    146   request->ForwardResult(request->handle(), result, count);
    147 }
    148 
    149 void HistoryBackend::DeleteSearchTerms(
    150     scoped_refptr<DeleteRequest> request,
    151     const std::string& selection,
    152     const std::vector<string16> selection_args) {
    153   if (request->canceled())
    154     return;
    155 
    156   int count = 0;
    157   bool result = false;
    158   if (android_provider_backend_) {
    159     result = android_provider_backend_->DeleteSearchTerms(selection,
    160         selection_args, &count);
    161   }
    162 
    163   request->ForwardResult(request->handle(), result, count);
    164 }
    165 
    166 void HistoryBackend::QuerySearchTerms(
    167     scoped_refptr<QueryRequest> request,
    168     const std::vector<SearchRow::ColumnID>& projections,
    169     const std::string& selection,
    170     const std::vector<string16>& selection_args,
    171     const std::string& sort_order) {
    172   if (request->canceled())
    173     return;
    174 
    175   AndroidStatement* statement = NULL;
    176   if (android_provider_backend_)
    177     statement = android_provider_backend_->QuerySearchTerms(projections,
    178         selection, selection_args, sort_order);
    179 
    180   request->ForwardResult(request->handle(), statement, statement);
    181 }
    182 
    183 }  // namespace history
    184