| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/managed_bookmarks_shim.h" | 5 #include "chrome/browser/android/bookmarks/managed_bookmarks_shim.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return child; | 62 return child; |
| 63 } | 63 } |
| 64 return NULL; | 64 return NULL; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ManagedBookmarksShim::Reload() { | 67 void ManagedBookmarksShim::Reload() { |
| 68 std::string domain; | 68 std::string domain; |
| 69 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); | 69 std::string username = prefs_->GetString(prefs::kGoogleServicesUsername); |
| 70 if (!username.empty()) | 70 if (!username.empty()) |
| 71 domain = gaia::ExtractDomainName(username); | 71 domain = gaia::ExtractDomainName(username); |
| 72 string16 root_node_name; | 72 base::string16 root_node_name; |
| 73 if (domain.empty()) { | 73 if (domain.empty()) { |
| 74 root_node_name = | 74 root_node_name = |
| 75 l10n_util::GetStringUTF16(IDS_POLICY_MANAGED_BOOKMARKS_DEFAULT_NAME); | 75 l10n_util::GetStringUTF16(IDS_POLICY_MANAGED_BOOKMARKS_DEFAULT_NAME); |
| 76 } else { | 76 } else { |
| 77 root_node_name = l10n_util::GetStringFUTF16(IDS_POLICY_MANAGED_BOOKMARKS, | 77 root_node_name = l10n_util::GetStringFUTF16(IDS_POLICY_MANAGED_BOOKMARKS, |
| 78 base::UTF8ToUTF16(domain)); | 78 base::UTF8ToUTF16(domain)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 root_.reset(new BookmarkPermanentNode(0)); | 81 root_.reset(new BookmarkPermanentNode(0)); |
| 82 root_->SetTitle(root_node_name); | 82 root_->SetTitle(root_node_name); |
| 83 | 83 |
| 84 const base::ListValue* list = prefs_->GetList(prefs::kManagedBookmarks); | 84 const base::ListValue* list = prefs_->GetList(prefs::kManagedBookmarks); |
| 85 int64 id = 1; | 85 int64 id = 1; |
| 86 if (list) { | 86 if (list) { |
| 87 for (base::ListValue::const_iterator it = list->begin(); | 87 for (base::ListValue::const_iterator it = list->begin(); |
| 88 it != list->end(); ++it) { | 88 it != list->end(); ++it) { |
| 89 const base::DictionaryValue* dict = NULL; | 89 const base::DictionaryValue* dict = NULL; |
| 90 if (!*it || !(*it)->GetAsDictionary(&dict)) { | 90 if (!*it || !(*it)->GetAsDictionary(&dict)) { |
| 91 NOTREACHED(); | 91 NOTREACHED(); |
| 92 continue; | 92 continue; |
| 93 } | 93 } |
| 94 | 94 |
| 95 string16 name; | 95 base::string16 name; |
| 96 std::string url; | 96 std::string url; |
| 97 if (!dict->GetString(ManagedBookmarksPolicyHandler::kName, &name) || | 97 if (!dict->GetString(ManagedBookmarksPolicyHandler::kName, &name) || |
| 98 !dict->GetString(ManagedBookmarksPolicyHandler::kUrl, &url)) { | 98 !dict->GetString(ManagedBookmarksPolicyHandler::kUrl, &url)) { |
| 99 NOTREACHED(); | 99 NOTREACHED(); |
| 100 continue; | 100 continue; |
| 101 } | 101 } |
| 102 | 102 |
| 103 BookmarkNode* node = new BookmarkNode(id++, GURL(url)); | 103 BookmarkNode* node = new BookmarkNode(id++, GURL(url)); |
| 104 node->set_type(BookmarkNode::URL); | 104 node->set_type(BookmarkNode::URL); |
| 105 node->SetTitle(name); | 105 node->SetTitle(name); |
| 106 root_->Add(node, root_->child_count()); | 106 root_->Add(node, root_->child_count()); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 FOR_EACH_OBSERVER(Observer, observers_, OnManagedBookmarksChanged()); | 110 FOR_EACH_OBSERVER(Observer, observers_, OnManagedBookmarksChanged()); |
| 111 } | 111 } |
| OLD | NEW |