Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/history/android/sqlite_cursor.cc

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/history/android/android_history_types.h" 11 #include "chrome/browser/history/android/android_history_types.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "jni/SQLiteCursor_jni.h" 13 #include "jni/SQLiteCursor_jni.h"
14 #include "sql/statement.h" 14 #include "sql/statement.h"
15 15
16 using base::android::ConvertUTF8ToJavaString; 16 using base::android::ConvertUTF8ToJavaString;
17 using base::android::GetClass; 17 using base::android::GetClass;
18 using base::android::HasClass; 18 using base::android::HasClass;
19 using base::android::HasMethod; 19 using base::android::MethodID;
20 using base::android::GetMethodID;
21 using base::android::ScopedJavaLocalRef; 20 using base::android::ScopedJavaLocalRef;
22 using content::BrowserThread; 21 using content::BrowserThread;
23 22
24 namespace { 23 namespace {
25 24
26 SQLiteCursor::JavaColumnType ToJavaColumnType(sql::ColType type) { 25 SQLiteCursor::JavaColumnType ToJavaColumnType(sql::ColType type) {
27 switch (type) { 26 switch (type) {
28 case sql::COLUMN_TYPE_INTEGER: 27 case sql::COLUMN_TYPE_INTEGER:
29 return SQLiteCursor::NUMERIC; 28 return SQLiteCursor::NUMERIC;
30 case sql::COLUMN_TYPE_FLOAT: 29 case sql::COLUMN_TYPE_FLOAT:
(...skipping 24 matching lines...) Expand all
55 const std::vector<std::string>& column_names, 54 const std::vector<std::string>& column_names,
56 history::AndroidStatement* statement, 55 history::AndroidStatement* statement,
57 AndroidHistoryProviderService* service, 56 AndroidHistoryProviderService* service,
58 FaviconService* favicon_service) { 57 FaviconService* favicon_service) {
59 if (!HasClass(env, kSQLiteCursorClassPath)) { 58 if (!HasClass(env, kSQLiteCursorClassPath)) {
60 LOG(ERROR) << "Can not find " << kSQLiteCursorClassPath; 59 LOG(ERROR) << "Can not find " << kSQLiteCursorClassPath;
61 return ScopedJavaLocalRef<jobject>(); 60 return ScopedJavaLocalRef<jobject>();
62 } 61 }
63 62
64 ScopedJavaLocalRef<jclass> sclass = GetClass(env, kSQLiteCursorClassPath); 63 ScopedJavaLocalRef<jclass> sclass = GetClass(env, kSQLiteCursorClassPath);
65 if (!HasMethod(env, sclass, "<init>", "(I)V")) { 64 jmethodID method_id = MethodID::Get<MethodID::TYPE_INSTANCE>(
66 LOG(ERROR) << "Can not find " << kSQLiteCursorClassPath << " Constructor"; 65 env, sclass.obj(), "<init>", "(I)V");
67 return ScopedJavaLocalRef<jobject>();
68 }
69 66
70 jmethodID method_id = GetMethodID(env, sclass, "<init>", "(I)V");
71 SQLiteCursor* cursor = new SQLiteCursor(column_names, statement, service, 67 SQLiteCursor* cursor = new SQLiteCursor(column_names, statement, service,
72 favicon_service); 68 favicon_service);
73 ScopedJavaLocalRef<jobject> obj(env, 69 ScopedJavaLocalRef<jobject> obj(env,
74 env->NewObject(sclass.obj(), method_id, reinterpret_cast<jint>(cursor))); 70 env->NewObject(sclass.obj(), method_id, reinterpret_cast<jint>(cursor)));
75 if (obj.is_null()) { 71 if (obj.is_null()) {
76 delete cursor; 72 delete cursor;
77 return ScopedJavaLocalRef<jobject>(); 73 return ScopedJavaLocalRef<jobject>();
78 } 74 }
79 return obj; 75 return obj;
80 } 76 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return SQLiteCursor::BLOB; 270 return SQLiteCursor::BLOB;
275 271
276 return ToJavaColumnType(statement_->statement()->ColumnType(column)); 272 return ToJavaColumnType(statement_->statement()->ColumnType(column));
277 } 273 }
278 274
279 void SQLiteCursor::RunMoveStatementOnUIThread(int pos) { 275 void SQLiteCursor::RunMoveStatementOnUIThread(int pos) {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 service_->MoveStatement(statement_, position_, pos, &consumer_, 277 service_->MoveStatement(statement_, position_, pos, &consumer_,
282 base::Bind(&SQLiteCursor::OnMoved, base::Unretained(this))); 278 base::Bind(&SQLiteCursor::OnMoved, base::Unretained(this)));
283 } 279 }
OLDNEW
« no previous file with comments | « chrome/browser/android/provider/chrome_browser_provider.cc ('k') | content/browser/android/content_view_core_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698