| 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/android/provider/chrome_browser_provider.h" | 5 #include "chrome/browser/android/provider/chrome_browser_provider.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/android/provider/blocking_ui_thread_async_request.h" | 19 #include "chrome/browser/android/provider/blocking_ui_thread_async_request.h" |
| 20 #include "chrome/browser/android/provider/bookmark_model_observer_task.h" | 20 #include "chrome/browser/android/provider/bookmark_model_observer_task.h" |
| 21 #include "chrome/browser/android/provider/run_on_ui_thread_blocking.h" | 21 #include "chrome/browser/android/provider/run_on_ui_thread_blocking.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 24 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 24 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | |
| 27 #include "chrome/browser/favicon/favicon_service.h" | 26 #include "chrome/browser/favicon/favicon_service.h" |
| 28 #include "chrome/browser/favicon/favicon_service_factory.h" | 27 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 29 #include "chrome/browser/history/android/sqlite_cursor.h" | 28 #include "chrome/browser/history/android/sqlite_cursor.h" |
| 30 #include "chrome/browser/history/history_service.h" | 29 #include "chrome/browser/history/history_service.h" |
| 31 #include "chrome/browser/history/history_service_factory.h" | 30 #include "chrome/browser/history/history_service_factory.h" |
| 32 #include "chrome/browser/history/top_sites.h" | 31 #include "chrome/browser/history/top_sites.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
| 35 #include "chrome/browser/search_engines/template_url_service_factory.h" | 34 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 36 #include "components/bookmarks/browser/bookmark_model.h" | 35 #include "components/bookmarks/browser/bookmark_model.h" |
| 37 #include "components/bookmarks/browser/bookmark_utils.h" | 36 #include "components/bookmarks/browser/bookmark_utils.h" |
| 38 #include "components/history/core/browser/android/android_history_types.h" | 37 #include "components/history/core/browser/android/android_history_types.h" |
| 39 #include "components/search_engines/template_url.h" | 38 #include "components/search_engines/template_url.h" |
| 40 #include "components/search_engines/template_url_service.h" | 39 #include "components/search_engines/template_url_service.h" |
| 41 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/notification_service.h" | |
| 43 #include "jni/ChromeBrowserProvider_jni.h" | 41 #include "jni/ChromeBrowserProvider_jni.h" |
| 44 #include "sql/statement.h" | 42 #include "sql/statement.h" |
| 45 #include "ui/base/layout.h" | 43 #include "ui/base/layout.h" |
| 46 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 47 #include "ui/gfx/favicon_size.h" | 45 #include "ui/gfx/favicon_size.h" |
| 48 | 46 |
| 49 using base::android::AttachCurrentThread; | 47 using base::android::AttachCurrentThread; |
| 50 using base::android::CheckException; | 48 using base::android::CheckException; |
| 51 using base::android::ClearException; | 49 using base::android::ClearException; |
| 52 using base::android::ConvertJavaStringToUTF16; | 50 using base::android::ConvertJavaStringToUTF16; |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 history_service_observer_(this), | 1163 history_service_observer_(this), |
| 1166 handling_extensive_changes_(false) { | 1164 handling_extensive_changes_(false) { |
| 1167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1168 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); | 1166 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 1169 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 1167 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
| 1170 top_sites_ = profile_->GetTopSites(); | 1168 top_sites_ = profile_->GetTopSites(); |
| 1171 favicon_service_ = FaviconServiceFactory::GetForProfile( | 1169 favicon_service_ = FaviconServiceFactory::GetForProfile( |
| 1172 profile_, ServiceAccessType::EXPLICIT_ACCESS), | 1170 profile_, ServiceAccessType::EXPLICIT_ACCESS), |
| 1173 service_.reset(new AndroidHistoryProviderService(profile_)); | 1171 service_.reset(new AndroidHistoryProviderService(profile_)); |
| 1174 | 1172 |
| 1175 // Registers the notifications we are interested. | 1173 // Register as observer for service we are interested. |
| 1176 bookmark_model_->AddObserver(this); | 1174 bookmark_model_->AddObserver(this); |
| 1177 history_service_observer_.Add(HistoryServiceFactory::GetForProfile( | 1175 history_service_observer_.Add(HistoryServiceFactory::GetForProfile( |
| 1178 profile_, ServiceAccessType::EXPLICIT_ACCESS)); | 1176 profile_, ServiceAccessType::EXPLICIT_ACCESS)); |
| 1179 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 1180 content::NotificationService::AllSources()); | |
| 1181 TemplateURLService* template_service = | 1177 TemplateURLService* template_service = |
| 1182 TemplateURLServiceFactory::GetForProfile(profile_); | 1178 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1183 if (!template_service->loaded()) | 1179 if (!template_service->loaded()) |
| 1184 template_service->Load(); | 1180 template_service->Load(); |
| 1185 } | 1181 } |
| 1186 | 1182 |
| 1187 ChromeBrowserProvider::~ChromeBrowserProvider() { | 1183 ChromeBrowserProvider::~ChromeBrowserProvider() { |
| 1188 bookmark_model_->RemoveObserver(this); | 1184 bookmark_model_->RemoveObserver(this); |
| 1189 } | 1185 } |
| 1190 | 1186 |
| 1191 void ChromeBrowserProvider::Destroy(JNIEnv*, jobject) { | 1187 void ChromeBrowserProvider::Destroy(JNIEnv*, jobject) { |
| 1188 history_service_observer_.RemoveAll(); |
| 1192 delete this; | 1189 delete this; |
| 1193 } | 1190 } |
| 1194 | 1191 |
| 1195 // ------------- Provider public APIs ------------- // | 1192 // ------------- Provider public APIs ------------- // |
| 1196 | 1193 |
| 1197 jlong ChromeBrowserProvider::AddBookmark(JNIEnv* env, | 1194 jlong ChromeBrowserProvider::AddBookmark(JNIEnv* env, |
| 1198 jobject, | 1195 jobject, |
| 1199 jstring jurl, | 1196 jstring jurl, |
| 1200 jstring jtitle, | 1197 jstring jtitle, |
| 1201 jboolean is_folder, | 1198 jboolean is_folder, |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 } | 1615 } |
| 1619 | 1616 |
| 1620 void ChromeBrowserProvider::OnURLVisited(HistoryService* history_service, | 1617 void ChromeBrowserProvider::OnURLVisited(HistoryService* history_service, |
| 1621 ui::PageTransition transition, | 1618 ui::PageTransition transition, |
| 1622 const history::URLRow& row, | 1619 const history::URLRow& row, |
| 1623 const history::RedirectList& redirects, | 1620 const history::RedirectList& redirects, |
| 1624 base::Time visit_time) { | 1621 base::Time visit_time) { |
| 1625 OnHistoryChanged(); | 1622 OnHistoryChanged(); |
| 1626 } | 1623 } |
| 1627 | 1624 |
| 1625 void ChromeBrowserProvider::OnURLsDeleted(HistoryService* history_service, |
| 1626 bool all_history, |
| 1627 bool expired, |
| 1628 const history::URLRows& deleted_rows, |
| 1629 const std::set<GURL>& favicon_urls) { |
| 1630 OnHistoryChanged(); |
| 1631 } |
| 1632 |
| 1628 void ChromeBrowserProvider::OnKeywordSearchTermUpdated( | 1633 void ChromeBrowserProvider::OnKeywordSearchTermUpdated( |
| 1629 HistoryService* history_service, | 1634 HistoryService* history_service, |
| 1630 const history::URLRow& row, | 1635 const history::URLRow& row, |
| 1631 history::KeywordID keyword_id, | 1636 history::KeywordID keyword_id, |
| 1632 const base::string16& term) { | 1637 const base::string16& term) { |
| 1633 JNIEnv* env = AttachCurrentThread(); | 1638 JNIEnv* env = AttachCurrentThread(); |
| 1634 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | 1639 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
| 1635 if (obj.is_null()) | 1640 if (obj.is_null()) |
| 1636 return; | 1641 return; |
| 1637 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); | 1642 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); |
| 1638 } | 1643 } |
| 1639 | 1644 |
| 1640 void ChromeBrowserProvider::OnKeywordSearchTermDeleted( | 1645 void ChromeBrowserProvider::OnKeywordSearchTermDeleted( |
| 1641 HistoryService* history_service, | 1646 HistoryService* history_service, |
| 1642 history::URLID url_id) {} | 1647 history::URLID url_id) { |
| 1643 | |
| 1644 void ChromeBrowserProvider::Observe( | |
| 1645 int type, | |
| 1646 const content::NotificationSource& source, | |
| 1647 const content::NotificationDetails& details) { | |
| 1648 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED); | |
| 1649 OnHistoryChanged(); | |
| 1650 } | 1648 } |
| OLD | NEW |