| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/android/sqlite_cursor.h" | 5 #include "chrome/browser/history/android/sqlite_cursor.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool success() const { | 124 bool success() const { |
| 125 return success_; | 125 return success_; |
| 126 } | 126 } |
| 127 | 127 |
| 128 AndroidStatement* statement() const { | 128 AndroidStatement* statement() const { |
| 129 return statement_; | 129 return statement_; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void OnInserted(AndroidHistoryProviderService::Handle handle, | 132 void OnInserted(int64 id) { |
| 133 bool success, | 133 success_ = id != 0; |
| 134 int64 id) { | |
| 135 success_ = success; | |
| 136 base::MessageLoop::current()->Quit(); | 134 base::MessageLoop::current()->Quit(); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void OnQueryResult(AndroidStatement* statement) { | 137 void OnQueryResult(AndroidStatement* statement) { |
| 140 success_ = statement != NULL; | 138 success_ = statement != NULL; |
| 141 statement_ = statement; | 139 statement_ = statement; |
| 142 base::MessageLoop::current()->Quit(); | 140 base::MessageLoop::current()->Quit(); |
| 143 } | 141 } |
| 144 | 142 |
| 145 private: | 143 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 favicon_data.push_back(1); | 161 favicon_data.push_back(1); |
| 164 base::RefCountedBytes *data_bytes = | 162 base::RefCountedBytes *data_bytes = |
| 165 base::RefCountedBytes::TakeVector(&favicon_data); | 163 base::RefCountedBytes::TakeVector(&favicon_data); |
| 166 row.set_favicon(data_bytes); | 164 row.set_favicon(data_bytes); |
| 167 row.set_last_visit_time(Time::Now()); | 165 row.set_last_visit_time(Time::Now()); |
| 168 row.set_visit_count(2); | 166 row.set_visit_count(2); |
| 169 row.set_title(base::UTF8ToUTF16("cnn")); | 167 row.set_title(base::UTF8ToUTF16("cnn")); |
| 170 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); | 168 scoped_refptr<CallbackHelper> callback(new CallbackHelper()); |
| 171 | 169 |
| 172 // Insert a row and verify it succeeded. | 170 // Insert a row and verify it succeeded. |
| 173 service_->InsertHistoryAndBookmark(row, &cancelable_consumer_, | 171 service_->InsertHistoryAndBookmark( |
| 174 Bind(&CallbackHelper::OnInserted, callback.get())); | 172 row, |
| 173 Bind(&CallbackHelper::OnInserted, callback.get()), |
| 174 &cancelable_tracker_); |
| 175 | 175 |
| 176 base::MessageLoop::current()->Run(); | 176 base::MessageLoop::current()->Run(); |
| 177 EXPECT_TRUE(callback->success()); | 177 EXPECT_TRUE(callback->success()); |
| 178 | 178 |
| 179 std::vector<HistoryAndBookmarkRow::ColumnID> projections; | 179 std::vector<HistoryAndBookmarkRow::ColumnID> projections; |
| 180 projections.push_back(HistoryAndBookmarkRow::URL); | 180 projections.push_back(HistoryAndBookmarkRow::URL); |
| 181 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); | 181 projections.push_back(HistoryAndBookmarkRow::LAST_VISIT_TIME); |
| 182 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); | 182 projections.push_back(HistoryAndBookmarkRow::VISIT_COUNT); |
| 183 projections.push_back(HistoryAndBookmarkRow::FAVICON); | 183 projections.push_back(HistoryAndBookmarkRow::FAVICON); |
| 184 | 184 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 cursor->GetBlob(env, NULL, 3); | 224 cursor->GetBlob(env, NULL, 3); |
| 225 std::vector<uint8> out; | 225 std::vector<uint8> out; |
| 226 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); | 226 base::android::JavaByteArrayToByteVector(env, data.obj(), &out); |
| 227 EXPECT_EQ(data_bytes->data().size(), out.size()); | 227 EXPECT_EQ(data_bytes->data().size(), out.size()); |
| 228 EXPECT_EQ(data_bytes->data()[0], out[0]); | 228 EXPECT_EQ(data_bytes->data()[0], out[0]); |
| 229 cursor->Destroy(env, NULL); | 229 cursor->Destroy(env, NULL); |
| 230 // Cursor::Destroy posts the task in UI thread, run Message loop to release | 230 // Cursor::Destroy posts the task in UI thread, run Message loop to release |
| 231 // the statement, delete SQLiteCursor itself etc. | 231 // the statement, delete SQLiteCursor itself etc. |
| 232 content::RunAllPendingInMessageLoop(); | 232 content::RunAllPendingInMessageLoop(); |
| 233 } | 233 } |
| OLD | NEW |