Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bookmarks/partner_bookmarks_reader.h" | 5 #include "chrome/browser/android/bookmarks/partner_bookmarks_reader.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | |
| 10 #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" | 11 #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | 13 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/favicon/core/favicon_service.h" | 17 #include "components/favicon/core/favicon_service.h" |
| 17 #include "components/favicon_base/favicon_types.h" | 18 #include "components/favicon_base/favicon_types.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "jni/PartnerBookmarksReader_jni.h" | 20 #include "jni/PartnerBookmarksReader_jni.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 jlong parent_id, | 147 jlong parent_id, |
| 147 const JavaParamRef<jbyteArray>& favicon, | 148 const JavaParamRef<jbyteArray>& favicon, |
| 148 const JavaParamRef<jbyteArray>& touchicon) { | 149 const JavaParamRef<jbyteArray>& touchicon) { |
| 149 base::string16 url; | 150 base::string16 url; |
| 150 base::string16 title; | 151 base::string16 title; |
| 151 if (jurl) | 152 if (jurl) |
| 152 url = ConvertJavaStringToUTF16(env, jurl); | 153 url = ConvertJavaStringToUTF16(env, jurl); |
| 153 if (jtitle) | 154 if (jtitle) |
| 154 title = ConvertJavaStringToUTF16(env, jtitle); | 155 title = ConvertJavaStringToUTF16(env, jtitle); |
| 155 | 156 |
| 156 BookmarkNode* node = NULL; | 157 BookmarkNode* node = NULL; |
|
Bernhard Bauer
2016/09/30 08:58:43
Can we make this a unique_ptr<> from the start?
Avi (use Gerrit)
2016/09/30 16:10:12
Done.
| |
| 157 if (wip_partner_bookmarks_root_.get()) { | 158 if (wip_partner_bookmarks_root_.get()) { |
| 158 node = new BookmarkNode(wip_next_available_id_++, GURL(url)); | 159 node = new BookmarkNode(wip_next_available_id_++, GURL(url)); |
| 159 node->set_type(is_folder ? BookmarkNode::FOLDER : BookmarkNode::URL); | 160 node->set_type(is_folder ? BookmarkNode::FOLDER : BookmarkNode::URL); |
| 160 node->SetTitle(title); | 161 node->SetTitle(title); |
| 161 | 162 |
| 162 // Handle favicon and touchicon | 163 // Handle favicon and touchicon |
| 163 if (profile_ != NULL && (favicon != NULL || touchicon != NULL)) { | 164 if (profile_ != NULL && (favicon != NULL || touchicon != NULL)) { |
| 164 jbyteArray icon = (touchicon != NULL) ? touchicon : favicon; | 165 jbyteArray icon = (touchicon != NULL) ? touchicon : favicon; |
| 165 const favicon_base::IconType icon_type = | 166 const favicon_base::IconType icon_type = |
| 166 touchicon ? favicon_base::TOUCH_ICON : favicon_base::FAVICON; | 167 touchicon ? favicon_base::TOUCH_ICON : favicon_base::FAVICON; |
| 167 const int icon_len = env->GetArrayLength(icon); | 168 const int icon_len = env->GetArrayLength(icon); |
| 168 jbyte* icon_bytes = env->GetByteArrayElements(icon, NULL); | 169 jbyte* icon_bytes = env->GetByteArrayElements(icon, NULL); |
| 169 if (icon_bytes) | 170 if (icon_bytes) |
| 170 PrepareAndSetFavicon(env, icon_bytes, icon_len, | 171 PrepareAndSetFavicon(env, icon_bytes, icon_len, |
| 171 node, profile_, icon_type); | 172 node, profile_, icon_type); |
| 172 env->ReleaseByteArrayElements(icon, icon_bytes, JNI_ABORT); | 173 env->ReleaseByteArrayElements(icon, icon_bytes, JNI_ABORT); |
| 173 } | 174 } |
| 174 | 175 |
| 175 const BookmarkNode* parent = | 176 const BookmarkNode* parent = |
| 176 GetNodeByID(wip_partner_bookmarks_root_.get(), parent_id); | 177 GetNodeByID(wip_partner_bookmarks_root_.get(), parent_id); |
| 177 if (!parent) { | 178 if (!parent) { |
| 178 LOG(WARNING) << "partner_bookmarks_shim: invalid/unknown parent_id=" | 179 LOG(WARNING) << "partner_bookmarks_shim: invalid/unknown parent_id=" |
| 179 << parent_id << ": adding to the root"; | 180 << parent_id << ": adding to the root"; |
| 180 parent = wip_partner_bookmarks_root_.get(); | 181 parent = wip_partner_bookmarks_root_.get(); |
| 181 } | 182 } |
| 182 const_cast<BookmarkNode*>(parent)->Add(node, parent->child_count()); | 183 const_cast<BookmarkNode*>(parent)->Add(base::WrapUnique(node), |
| 184 parent->child_count()); | |
| 183 } else { | 185 } else { |
| 184 node = new BookmarkPermanentNode(wip_next_available_id_++); | 186 node = new BookmarkPermanentNode(wip_next_available_id_++); |
| 185 node->SetTitle(title); | 187 node->SetTitle(title); |
| 186 wip_partner_bookmarks_root_.reset(node); | 188 wip_partner_bookmarks_root_.reset(node); |
| 187 } | 189 } |
| 188 return node->id(); | 190 return node->id(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 // static | 193 // static |
| 192 static void DisablePartnerBookmarksEditing(JNIEnv* env, | 194 static void DisablePartnerBookmarksEditing(JNIEnv* env, |
| 193 const JavaParamRef<jclass>& clazz) { | 195 const JavaParamRef<jclass>& clazz) { |
| 194 PartnerBookmarksShim::DisablePartnerBookmarksEditing(); | 196 PartnerBookmarksShim::DisablePartnerBookmarksEditing(); |
| 195 } | 197 } |
| 196 | 198 |
| 197 // static | 199 // static |
| 198 bool PartnerBookmarksReader::RegisterPartnerBookmarksReader(JNIEnv* env) { | 200 bool PartnerBookmarksReader::RegisterPartnerBookmarksReader(JNIEnv* env) { |
| 199 return RegisterNativesImpl(env); | 201 return RegisterNativesImpl(env); |
| 200 } | 202 } |
| 201 | 203 |
| 202 // ---------------------------------------------------------------- | 204 // ---------------------------------------------------------------- |
| 203 | 205 |
| 204 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 206 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 205 Profile* profile = ProfileManager::GetActiveUserProfile(); | 207 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 206 PartnerBookmarksShim* partner_bookmarks_shim = | 208 PartnerBookmarksShim* partner_bookmarks_shim = |
| 207 PartnerBookmarksShim::BuildForBrowserContext(profile); | 209 PartnerBookmarksShim::BuildForBrowserContext(profile); |
| 208 PartnerBookmarksReader* reader = new PartnerBookmarksReader( | 210 PartnerBookmarksReader* reader = new PartnerBookmarksReader( |
| 209 partner_bookmarks_shim, profile); | 211 partner_bookmarks_shim, profile); |
| 210 return reinterpret_cast<intptr_t>(reader); | 212 return reinterpret_cast<intptr_t>(reader); |
| 211 } | 213 } |
| OLD | NEW |