Chromium Code Reviews| 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 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 bool ChromeBrowserProvider::RegisterChromeBrowserProvider(JNIEnv* env) { | 1151 bool ChromeBrowserProvider::RegisterChromeBrowserProvider(JNIEnv* env) { |
| 1152 return RegisterNativesImpl(env); | 1152 return RegisterNativesImpl(env); |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) | 1155 ChromeBrowserProvider::ChromeBrowserProvider(JNIEnv* env, jobject obj) |
| 1156 : weak_java_provider_(env, obj), | 1156 : weak_java_provider_(env, obj), |
| 1157 handling_extensive_changes_(false) { | 1157 handling_extensive_changes_(false) { |
| 1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1159 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); | 1159 profile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 1160 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 1160 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
| 1161 history_service_ = | |
| 1162 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | |
| 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_->AddObserver(this); |
| 1169 content::NotificationService::AllSources()); | |
| 1170 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 1171 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 1171 content::NotificationService::AllSources()); | 1172 content::NotificationService::AllSources()); |
| 1172 notification_registrar_.Add(this, | 1173 notification_registrar_.Add(this, |
| 1173 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, | 1174 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED, |
| 1174 content::NotificationService::AllSources()); | 1175 content::NotificationService::AllSources()); |
| 1175 TemplateURLService* template_service = | 1176 TemplateURLService* template_service = |
| 1176 TemplateURLServiceFactory::GetForProfile(profile_); | 1177 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1177 if (!template_service->loaded()) | 1178 if (!template_service->loaded()) |
| 1178 template_service->Load(); | 1179 template_service->Load(); |
| 1179 } | 1180 } |
| 1180 | 1181 |
| 1181 ChromeBrowserProvider::~ChromeBrowserProvider() { | 1182 ChromeBrowserProvider::~ChromeBrowserProvider() { |
| 1182 bookmark_model_->RemoveObserver(this); | 1183 bookmark_model_->RemoveObserver(this); |
| 1184 history_service_->RemoveObserver(this); | |
| 1183 } | 1185 } |
| 1184 | 1186 |
| 1185 void ChromeBrowserProvider::Destroy(JNIEnv*, jobject) { | 1187 void ChromeBrowserProvider::Destroy(JNIEnv*, jobject) { |
| 1186 delete this; | 1188 delete this; |
| 1187 } | 1189 } |
| 1188 | 1190 |
| 1189 // ------------- Provider public APIs ------------- // | 1191 // ------------- Provider public APIs ------------- // |
| 1190 | 1192 |
| 1191 jlong ChromeBrowserProvider::AddBookmark(JNIEnv* env, | 1193 jlong ChromeBrowserProvider::AddBookmark(JNIEnv* env, |
| 1192 jobject, | 1194 jobject, |
| (...skipping 403 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::OnURLVisited(HistoryService* history_service, | |
| 1609 ui::PageTransition transition, | |
| 1610 const history::URLRow& row, | |
| 1611 const history::RedirectList& redirects, | |
| 1612 base::Time visit_time) { | |
| 1613 JNIEnv* env = AttachCurrentThread(); | |
| 1614 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | |
| 1615 if (obj.is_null()) | |
| 1616 return; | |
| 1617 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); | |
| 1618 } | |
| 1619 | |
| 1606 void ChromeBrowserProvider::Observe( | 1620 void ChromeBrowserProvider::Observe( |
| 1607 int type, | 1621 int type, |
| 1608 const content::NotificationSource& source, | 1622 const content::NotificationSource& source, |
| 1609 const content::NotificationDetails& details) { | 1623 const content::NotificationDetails& details) { |
| 1610 if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED || | 1624 if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
| 1611 type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | |
| 1612 JNIEnv* env = AttachCurrentThread(); | 1625 JNIEnv* env = AttachCurrentThread(); |
|
droger
2014/10/14 15:15:24
Is it possible to share some code with OnURLVisite
sdefresne
2014/10/14 16:02:05
Done.
| |
| 1613 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); | 1626 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); |
| 1614 if (obj.is_null()) | 1627 if (obj.is_null()) |
| 1615 return; | 1628 return; |
| 1616 Java_ChromeBrowserProvider_onHistoryChanged(env, obj.obj()); | 1629 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 |