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" | 26 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/favicon/favicon_service.h" | 27 #include "chrome/browser/favicon/favicon_service.h" |
28 #include "chrome/browser/favicon/favicon_service_factory.h" | 28 #include "chrome/browser/favicon/favicon_service_factory.h" |
29 #include "chrome/browser/history/android/sqlite_cursor.h" | 29 #include "chrome/browser/history/android/sqlite_cursor.h" |
| 30 #include "chrome/browser/history/history_service_factory.h" |
30 #include "chrome/browser/history/top_sites.h" | 31 #include "chrome/browser/history/top_sites.h" |
31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/browser/search_engines/template_url_service_factory.h" | 34 #include "chrome/browser/search_engines/template_url_service_factory.h" |
34 #include "components/bookmarks/browser/bookmark_model.h" | 35 #include "components/bookmarks/browser/bookmark_model.h" |
35 #include "components/bookmarks/browser/bookmark_utils.h" | 36 #include "components/bookmarks/browser/bookmark_utils.h" |
36 #include "components/history/core/android/android_history_types.h" | 37 #include "components/history/core/android/android_history_types.h" |
37 #include "components/search_engines/template_url.h" | 38 #include "components/search_engines/template_url.h" |
38 #include "components/search_engines/template_url_service.h" | 39 #include "components/search_engines/template_url_service.h" |
39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 ChromeBrowserProvider* provider = new ChromeBrowserProvider(env, obj); | 1148 ChromeBrowserProvider* provider = new ChromeBrowserProvider(env, obj); |
1148 return reinterpret_cast<intptr_t>(provider); | 1149 return reinterpret_cast<intptr_t>(provider); |
1149 } | 1150 } |
1150 | 1151 |
1151 bool ChromeBrowserProvider::RegisterChromeBrowserProvider(JNIEnv* env) { | 1152 bool ChromeBrowserProvider::RegisterChromeBrowserProvider(JNIEnv* env) { |
1152 return RegisterNativesImpl(env); | 1153 return RegisterNativesImpl(env); |
1153 } | 1154 } |
1154 | 1155 |
1155 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) | 1156 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) |
1156 : weak_java_provider_(env, obj), | 1157 : weak_java_provider_(env, obj), |
| 1158 history_service_observer_(this), |
1157 handling_extensive_changes_(false) { | 1159 handling_extensive_changes_(false) { |
1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1159 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); | 1161 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
1160 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 1162 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
1161 top_sites_ = profile_->GetTopSites(); | 1163 top_sites_ = profile_->GetTopSites(); |
1162 service_.reset(new AndroidHistoryProviderService(profile_)); | 1164 service_.reset(new AndroidHistoryProviderService(profile_)); |
1163 favicon_service_.reset(FaviconServiceFactory::GetForProfile(profile_, | 1165 favicon_service_.reset(FaviconServiceFactory::GetForProfile(profile_, |
1164 Profile::EXPLICIT_ACCESS)); | 1166 Profile::EXPLICIT_ACCESS)); |
1165 | 1167 |
1166 // Registers the notifications we are interested. | 1168 // Registers the notifications we are interested. |
1167 bookmark_model_->AddObserver(this); | 1169 bookmark_model_->AddObserver(this); |
1168 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, | 1170 history_service_observer_.Add( |
1169 content::NotificationService::AllSources()); | 1171 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS)); |
1170 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 1172 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
1171 content::NotificationService::AllSources()); | 1173 content::NotificationService::AllSources()); |
1172 notification_registrar_.Add(this, | 1174 notification_registrar_.Add(this, |
1173 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, | 1175 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, |
1174 content::NotificationService::AllSources()); | 1176 content::NotificationService::AllSources()); |
1175 TemplateURLService* template_service = | 1177 TemplateURLService* template_service = |
1176 TemplateURLServiceFactory::GetForProfile(profile_); | 1178 TemplateURLServiceFactory::GetForProfile(profile_); |
1177 if (!template_service->loaded()) | 1179 if (!template_service->loaded()) |
1178 template_service->Load(); | 1180 template_service->Load(); |
1179 } | 1181 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 return; | 1598 return; |
1597 | 1599 |
1598 JNIEnv* env = AttachCurrentThread(); | 1600 JNIEnv* env = AttachCurrentThread(); |
1599 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | 1601 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
1600 if (obj.is_null()) | 1602 if (obj.is_null()) |
1601 return; | 1603 return; |
1602 | 1604 |
1603 Java_ChromeBrowserProvider_onBookmarkChanged(env, obj.obj()); | 1605 Java_ChromeBrowserProvider_onBookmarkChanged(env, obj.obj()); |
1604 } | 1606 } |
1605 | 1607 |
| 1608 void ChromeBrowserProvider::OnHistoryChanged() { |
| 1609 JNIEnv* env = AttachCurrentThread(); |
| 1610 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
| 1611 if (obj.is_null()) |
| 1612 return; |
| 1613 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); |
| 1614 } |
| 1615 |
| 1616 void ChromeBrowserProvider::OnURLVisited(HistoryService* history_service, |
| 1617 ui::PageTransition transition, |
| 1618 const history::URLRow& row, |
| 1619 const history::RedirectList& redirects, |
| 1620 base::Time visit_time) { |
| 1621 OnHistoryChanged(); |
| 1622 } |
| 1623 |
1606 void ChromeBrowserProvider::Observe( | 1624 void ChromeBrowserProvider::Observe( |
1607 int type, | 1625 int type, |
1608 const content::NotificationSource& source, | 1626 const content::NotificationSource& source, |
1609 const content::NotificationDetails& details) { | 1627 const content::NotificationDetails& details) { |
1610 if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED || | 1628 if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
1611 type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | 1629 OnHistoryChanged(); |
1612 JNIEnv* env = AttachCurrentThread(); | |
1613 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | |
1614 if (obj.is_null()) | |
1615 return; | |
1616 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); | |
1617 } else if (type == | 1630 } else if (type == |
1618 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { | 1631 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { |
1619 JNIEnv* env = AttachCurrentThread(); | 1632 JNIEnv* env = AttachCurrentThread(); |
1620 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | 1633 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
1621 if (obj.is_null()) | 1634 if (obj.is_null()) |
1622 return; | 1635 return; |
1623 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); | 1636 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); |
1624 } | 1637 } |
1625 } | 1638 } |
OLD | NEW |