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 |
(...skipping 11 matching lines...) Expand all Loading... |
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/history_service_factory.h" |
31 #include "chrome/browser/history/top_sites.h" | 31 #include "chrome/browser/history/top_sites.h" |
| 32 #include "chrome/browser/history/top_sites_service_factory.h" |
32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
34 #include "chrome/browser/search_engines/template_url_service_factory.h" | 35 #include "chrome/browser/search_engines/template_url_service_factory.h" |
35 #include "components/bookmarks/browser/bookmark_model.h" | 36 #include "components/bookmarks/browser/bookmark_model.h" |
36 #include "components/bookmarks/browser/bookmark_utils.h" | 37 #include "components/bookmarks/browser/bookmark_utils.h" |
37 #include "components/history/core/android/android_history_types.h" | 38 #include "components/history/core/android/android_history_types.h" |
38 #include "components/search_engines/template_url.h" | 39 #include "components/search_engines/template_url.h" |
39 #include "components/search_engines/template_url_service.h" | 40 #include "components/search_engines/template_url_service.h" |
40 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 return RegisterNativesImpl(env); | 1159 return RegisterNativesImpl(env); |
1159 } | 1160 } |
1160 | 1161 |
1161 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) | 1162 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) |
1162 : weak_java_provider_(env, obj), | 1163 : weak_java_provider_(env, obj), |
1163 history_service_observer_(this), | 1164 history_service_observer_(this), |
1164 handling_extensive_changes_(false) { | 1165 handling_extensive_changes_(false) { |
1165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1166 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); | 1167 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
1167 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 1168 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
1168 top_sites_ = profile_->GetTopSites(); | 1169 top_sites_ = TopSitesServiceFactory::GetForProfile(profile_); |
1169 favicon_service_ = FaviconServiceFactory::GetForProfile( | 1170 favicon_service_ = FaviconServiceFactory::GetForProfile( |
1170 profile_, Profile::EXPLICIT_ACCESS), | 1171 profile_, Profile::EXPLICIT_ACCESS), |
1171 service_.reset(new AndroidHistoryProviderService(profile_)); | 1172 service_.reset(new AndroidHistoryProviderService(profile_)); |
1172 | 1173 |
1173 // Registers the notifications we are interested. | 1174 // Registers the notifications we are interested. |
1174 bookmark_model_->AddObserver(this); | 1175 bookmark_model_->AddObserver(this); |
1175 history_service_observer_.Add( | 1176 history_service_observer_.Add( |
1176 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS)); | 1177 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS)); |
1177 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 1178 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
1178 content::NotificationService::AllSources()); | 1179 content::NotificationService::AllSources()); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 } | 1568 } |
1568 | 1569 |
1569 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail( | 1570 ScopedJavaLocalRef<jbyteArray> ChromeBrowserProvider::GetThumbnail( |
1570 JNIEnv* env, jobject obj, jstring jurl) { | 1571 JNIEnv* env, jobject obj, jstring jurl) { |
1571 if (!jurl) | 1572 if (!jurl) |
1572 return ScopedJavaLocalRef<jbyteArray>(); | 1573 return ScopedJavaLocalRef<jbyteArray>(); |
1573 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl)); | 1574 GURL url = GURL(ConvertJavaStringToUTF16(env, jurl)); |
1574 | 1575 |
1575 // GetPageThumbnail is synchronous and can be called from any thread. | 1576 // GetPageThumbnail is synchronous and can be called from any thread. |
1576 scoped_refptr<base::RefCountedMemory> thumbnail; | 1577 scoped_refptr<base::RefCountedMemory> thumbnail; |
1577 if (top_sites_) | 1578 if (top_sites_.get()) |
1578 top_sites_->GetPageThumbnail(url, false, &thumbnail); | 1579 top_sites_->GetPageThumbnail(url, false, &thumbnail); |
1579 | 1580 |
1580 if (!thumbnail.get() || !thumbnail->front()) { | 1581 if (!thumbnail.get() || !thumbnail->front()) { |
1581 return ScopedJavaLocalRef<jbyteArray>(); | 1582 return ScopedJavaLocalRef<jbyteArray>(); |
1582 } | 1583 } |
1583 | 1584 |
1584 return base::android::ToJavaByteArray(env, thumbnail->front(), | 1585 return base::android::ToJavaByteArray(env, thumbnail->front(), |
1585 thumbnail->size()); | 1586 thumbnail->size()); |
1586 } | 1587 } |
1587 | 1588 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 OnHistoryChanged(); | 1635 OnHistoryChanged(); |
1635 } else if (type == | 1636 } else if (type == |
1636 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { | 1637 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { |
1637 JNIEnv* env = AttachCurrentThread(); | 1638 JNIEnv* env = AttachCurrentThread(); |
1638 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | 1639 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
1639 if (obj.is_null()) | 1640 if (obj.is_null()) |
1640 return; | 1641 return; |
1641 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); | 1642 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); |
1642 } | 1643 } |
1643 } | 1644 } |
OLD | NEW |