OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/enhanced_bookmarks/enhanced_bookmarks_bridge.h" | 5 #include "chrome/browser/android/enhanced_bookmarks/enhanced_bookmarks_bridge.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce.h" | 10 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce.h" |
11 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce_factory.h" | 11 #include "chrome/browser/enhanced_bookmarks/chrome_bookmark_server_cluster_servi ce_factory.h" |
12 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" | 12 #include "chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h" |
13 #include "chrome/browser/profiles/profile_android.h" | 13 #include "chrome/browser/profiles/profile_android.h" |
14 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/bookmarks/browser/bookmark_utils.h" | 16 #include "components/bookmarks/browser/bookmark_utils.h" |
17 #include "components/bookmarks/common/android/bookmark_type.h" | 17 #include "components/bookmarks/common/android/bookmark_type.h" |
18 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" | 18 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
19 #include "components/enhanced_bookmarks/metadata_accessor.h" | |
Kibeom Kim (inactive)
2014/10/26 05:34:56
Can we delete metadata_accessor files with this CL
| |
20 #include "jni/EnhancedBookmarksBridge_jni.h" | 19 #include "jni/EnhancedBookmarksBridge_jni.h" |
21 | 20 |
22 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
23 using bookmarks::BookmarkType; | 22 using bookmarks::BookmarkType; |
24 | 23 |
25 namespace enhanced_bookmarks { | 24 namespace enhanced_bookmarks { |
26 namespace android { | 25 namespace android { |
27 | 26 |
28 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, | 27 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, |
29 jobject obj, | 28 jobject obj, |
30 Profile* profile) : weak_java_ref_(env, obj) { | 29 Profile* profile) : weak_java_ref_(env, obj) { |
31 profile_ = profile; | 30 profile_ = profile; |
32 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 31 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
33 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_)-> | 32 enhanced_bookmark_model_ = |
34 SetVersionSuffix(chrome::VersionInfo().OSType()); | 33 EnhancedBookmarkModelFactory::GetForBrowserContext(profile_); |
34 enhanced_bookmark_model_->SetVersionSuffix(chrome::VersionInfo().OSType()); | |
35 cluster_service_ = | 35 cluster_service_ = |
36 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); | 36 ChromeBookmarkServerClusterServiceFactory::GetForBrowserContext(profile_); |
37 cluster_service_->AddObserver(this); | 37 cluster_service_->AddObserver(this); |
38 } | 38 } |
39 | 39 |
40 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { | 40 EnhancedBookmarksBridge::~EnhancedBookmarksBridge() { |
41 cluster_service_->RemoveObserver(this); | 41 cluster_service_->RemoveObserver(this); |
Ian Wen
2014/10/25 04:39:58
Why don't we delete cluster service and enhanced b
Kibeom Kim (inactive)
2014/10/26 05:34:56
I think they are singleton (See BrowserContextKeye
| |
42 } | 42 } |
43 | 43 |
44 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { | 44 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { |
45 delete this; | 45 delete this; |
46 } | 46 } |
47 | 47 |
48 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( | 48 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( |
49 JNIEnv* env, jobject obj, jlong id, jint type) { | 49 JNIEnv* env, jobject obj, jlong id, jint type) { |
50 DCHECK(bookmark_model_->loaded()); | 50 DCHECK(bookmark_model_->loaded()); |
51 DCHECK_EQ(BookmarkType::BOOKMARK_TYPE_NORMAL, type); | 51 DCHECK_EQ(BookmarkType::BOOKMARK_TYPE_NORMAL, type); |
52 | 52 |
53 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 53 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
54 bookmark_model_, static_cast<int64>(id)); | 54 bookmark_model_, static_cast<int64>(id)); |
55 | 55 |
56 return node ? | 56 return node ? base::android::ConvertUTF8ToJavaString( |
57 base::android::ConvertUTF8ToJavaString( | 57 env, enhanced_bookmark_model_->GetDescription(node)) |
58 env, enhanced_bookmarks::DescriptionFromBookmark(node)) : | 58 : ScopedJavaLocalRef<jstring>(); |
59 ScopedJavaLocalRef<jstring>(); | |
60 } | 59 } |
61 | 60 |
62 void EnhancedBookmarksBridge::SetBookmarkDescription(JNIEnv* env, | 61 void EnhancedBookmarksBridge::SetBookmarkDescription(JNIEnv* env, |
63 jobject obj, | 62 jobject obj, |
64 jlong id, | 63 jlong id, |
65 jint type, | 64 jint type, |
66 jstring description) { | 65 jstring description) { |
67 DCHECK(bookmark_model_->loaded()); | 66 DCHECK(bookmark_model_->loaded()); |
Rune Fevang
2014/10/27 19:52:27
Could you change these checks to enhanced_bookmark
Ian Wen
2014/10/27 23:06:32
Done.
| |
68 DCHECK_EQ(type, BookmarkType::BOOKMARK_TYPE_NORMAL); | 67 DCHECK_EQ(type, BookmarkType::BOOKMARK_TYPE_NORMAL); |
69 | 68 |
70 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 69 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
71 bookmark_model_, static_cast<int64>(id)); | 70 bookmark_model_, static_cast<int64>(id)); |
72 | 71 |
73 enhanced_bookmarks::SetDescriptionForBookmark( | 72 enhanced_bookmark_model_->SetDescription( |
74 bookmark_model_, node, | 73 node, base::android::ConvertJavaStringToUTF8(env, description)); |
75 base::android::ConvertJavaStringToUTF8(env, description)); | |
76 } | 74 } |
77 | 75 |
78 void EnhancedBookmarksBridge::GetBookmarksForFilter(JNIEnv* env, | 76 void EnhancedBookmarksBridge::GetBookmarksForFilter(JNIEnv* env, |
79 jobject obj, | 77 jobject obj, |
80 jstring j_filter, | 78 jstring j_filter, |
81 jobject j_result_obj) { | 79 jobject j_result_obj) { |
82 DCHECK(bookmark_model_->loaded()); | 80 DCHECK(bookmark_model_->loaded()); |
83 const std::string title = | 81 const std::string title = |
84 base::android::ConvertJavaStringToUTF8(env, j_filter); | 82 base::android::ConvertJavaStringToUTF8(env, j_filter); |
85 const std::vector<const BookmarkNode*> bookmarks = | 83 const std::vector<const BookmarkNode*> bookmarks = |
(...skipping 28 matching lines...) Expand all Loading... | |
114 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( | 112 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( |
115 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 113 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
116 } | 114 } |
117 | 115 |
118 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { | 116 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { |
119 return RegisterNativesImpl(env); | 117 return RegisterNativesImpl(env); |
120 } | 118 } |
121 | 119 |
122 } // namespace android | 120 } // namespace android |
123 } // namespace enhanced_bookmarks | 121 } // namespace enhanced_bookmarks |
OLD | NEW |